Commit be30a526 authored by alexpott's avatar alexpott

Issue #2447139 by Gábor Hojtsy: Config entities should be created in the...

Issue #2447139 by Gábor Hojtsy: Config entities should be created in the negotiated language unless otherwise specified
parent 7f4abc7c
......@@ -195,8 +195,8 @@ protected function doLoadMultiple(array $ids = NULL) {
* {@inheritdoc}
*/
protected function doCreate(array $values) {
// Set default language to site default if not provided.
$values += array($this->langcodeKey => $this->languageManager->getDefaultLanguage()->getId());
// Set default language to current language if not provided.
$values += array($this->langcodeKey => $this->languageManager->getCurrentLanguage()->getId());
$entity = new $this->entityClass($values, $this->entityTypeId);
return $entity;
......
......@@ -139,8 +139,8 @@ protected function setUp() {
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$this->languageManager->expects($this->any())
->method('getDefaultLanguage')
->will($this->returnValue(new Language(array('langcode' => 'en'))));
->method('getCurrentLanguage')
->willReturn(new Language(array('id' => 'hu')));
$this->configFactory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
......@@ -175,6 +175,7 @@ protected function setUp() {
$container->set('config.typed', $this->typedConfigManager);
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
$container->set('config.manager', $this->configManager);
$container->set('language_manager', $this->languageManager);
\Drupal::setContainer($container);
}
......@@ -229,6 +230,34 @@ public function testCreate() {
return $entity;
}
/**
* @covers ::create
* @covers ::doCreate
*/
public function testCreateWithCurrentLanguage() {
$this->languageManager->expects($this->any())
->method('getLanguage')
->with('hu')
->willReturn(new Language(array('id' => 'hu')));
$entity = $this->entityStorage->create(array('id' => 'foo'));
$this->assertSame('hu', $entity->language()->getId());
}
/**
* @covers ::create
* @covers ::doCreate
*/
public function testCreateWithExplicitLanguage() {
$this->languageManager->expects($this->any())
->method('getLanguage')
->with('en')
->willReturn(new Language(array('id' => 'en')));
$entity = $this->entityStorage->create(array('id' => 'foo', 'langcode' => 'en'));
$this->assertSame('en', $entity->language()->getId());
}
/**
* @covers ::save
* @covers ::doSave
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment