public function ConfigSourceUnitTest::testNodeType in Translation Management Tool 8
Tests the node type config entity.
File
- sources/
tmgmt_config/ tests/ src/ Kernel/ ConfigSourceUnitTest.php, line 46
Class
- ConfigSourceUnitTest
- Unit tests for exporting translatable data from config entities and saving it back.
Namespace
Drupal\Tests\tmgmt_config\KernelCode
public function testNodeType() {
// Create an english test entity.
$node_type = NodeType::create(array(
'type' => 'test',
'name' => 'Node type name',
'description' => 'Node type description',
'title_label' => 'Title label',
'langcode' => 'en',
));
$node_type
->save();
$job = tmgmt_job_create('en', 'de');
$job->translator = 'test_translator';
$job
->save();
$job_item = tmgmt_job_item_create('config', 'node_type', 'node.type.' . $node_type
->id(), array(
'tjid' => $job
->id(),
));
$job_item
->save();
$source_plugin = $this->container
->get('plugin.manager.tmgmt.source')
->createInstance('config');
$data = $source_plugin
->getData($job_item);
// Test the name property.
$this
->assertEqual($data['name']['#label'], 'Name');
$this
->assertEqual($data['name']['#text'], $node_type
->label());
$this
->assertEqual($data['name']['#translate'], TRUE);
$this
->assertEqual($data['description']['#label'], 'Description');
$this
->assertEqual($data['description']['#text'], $node_type
->getDescription());
$this
->assertEqual($data['description']['#translate'], TRUE);
// Test item types.
$this
->assertEqual($source_plugin
->getItemTypes()['node_type'], t('Content type'));
// Now request a translation and save it back.
$job
->requestTranslation();
$items = $job
->getItems();
$item = reset($items);
$item
->acceptTranslation();
$data = $item
->getData();
// Check that the translations were saved correctly.
$language_manager = \Drupal::languageManager();
$language_manager
->setConfigOverrideLanguage($language_manager
->getLanguage('de'));
$node_type = NodeType::load($node_type
->id());
$this
->assertEqual($node_type
->label(), $data['name']['#translation']['#text']);
$this
->assertEqual($node_type
->getDescription(), $data['description']['#translation']['#text']);
}