ContentTranslationModuleInstallTest.php in Drupal 8
File
core/modules/content_translation/tests/src/Kernel/ContentTranslationModuleInstallTest.php
View source
<?php
namespace Drupal\Tests\content_translation\Kernel;
use Drupal\entity_test\Entity\EntityTestWithBundle;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
class ContentTranslationModuleInstallTest extends KernelTestBase {
protected static $modules = [
'content_translation',
'content_translation_test',
'entity_test',
'language',
'user',
];
protected $contentTranslationManager;
protected $sourceLangcode = 'en';
protected $translationLangcode = 'af';
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('entity_test_with_bundle');
ConfigurableLanguage::createFromLangcode($this->translationLangcode)
->save();
$this->contentTranslationManager = $this->container
->get('content_translation.manager');
}
public function testFieldUpdates() {
$this
->installConfig([
'content_translation_test',
]);
$entity = EntityTestWithBundle::create([
'type' => 'test',
'langcode' => $this->sourceLangcode,
]);
$entity
->save();
$translation = $entity
->addTranslation($this->translationLangcode);
$translation_metadata = $this->contentTranslationManager
->getTranslationMetadata($translation);
$translation_metadata
->setSource($this->sourceLangcode)
->setOutdated(TRUE);
$translation
->save();
$entity = EntityTestWithBundle::load($entity
->id());
$translation = $entity
->getTranslation($this->translationLangcode);
$translation_metadata = $this->contentTranslationManager
->getTranslationMetadata($translation);
$this
->assertSame($this->sourceLangcode, $translation_metadata
->getSource());
$this
->assertSame(TRUE, $translation_metadata
->isOutdated());
}
}