View source
<?php
namespace Drupal\node\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
class NodeTypeTranslationTest extends WebTestBase {
public static $modules = array(
'config_translation',
'node',
);
protected $defaultLangcode = 'fr';
protected $additionalLangcodes = [
'es',
];
protected $adminUser;
protected function setUp() {
parent::setUp();
$admin_permissions = array(
'administer content types',
'administer site configuration',
'administer themes',
'translate configuration',
);
$this->adminUser = $this
->drupalCreateUser($admin_permissions);
foreach ($this->additionalLangcodes as $langcode) {
ConfigurableLanguage::createFromLangcode($langcode)
->save();
}
}
protected function installParameters() {
$parameters = parent::installParameters();
$parameters['parameters']['langcode'] = $this->defaultLangcode;
return $parameters;
}
public function testNodeTypeTranslation() {
$type = Unicode::strtolower($this
->randomMachineName(16));
$name = $this
->randomString();
$this
->drupalLogin($this->adminUser);
$this
->drupalCreateContentType(array(
'type' => $type,
'name' => $name,
));
$langcode = $this->additionalLangcodes[0];
$translated_name = $langcode . '-' . $name;
$edit = array(
"translation[config_names][node.type.{$type}][name]" => $translated_name,
);
$this
->drupalPostForm("admin/structure/types/manage/{$type}/translate/{$langcode}/add", $edit, t('Save translation'));
$this
->drupalPostForm('admin/appearance', array(
'use_admin_theme' => '0',
), t('Save configuration'));
$this
->drupalGet("{$langcode}/node/add/{$type}");
$this
->assertRaw(t('Create @name', array(
'@name' => $translated_name,
)));
$this
->drupalPostForm('admin/appearance', array(
'use_admin_theme' => '1',
), t('Save configuration'));
$this
->drupalGet("{$langcode}/node/add/{$type}");
$this
->assertRaw(t('Create @name', array(
'@name' => $translated_name,
)));
}
public function testNodeTypeTitleLabelTranslation() {
$type = Unicode::strtolower($this
->randomMachineName(16));
$name = $this
->randomString();
$this
->drupalLogin($this->adminUser);
$this
->drupalCreateContentType(array(
'type' => $type,
'name' => $name,
));
$langcode = $this->additionalLangcodes[0];
$this
->drupalPostForm("admin/structure/types/manage/{$type}", array(
'title_label' => 'Edited title',
), t('Save content type'));
$this
->drupalGet("admin/structure/types/manage/{$type}/translate/{$langcode}/add");
$this
->assertRaw(t('Label'));
$this
->assertRaw(t('Edited title'));
$this
->drupalPostForm(NULL, array(
"translation[config_names][core.base_field_override.node.{$type}.title][label]" => 'Translated title',
), t('Save translation'));
$this
->drupalGet("node/add/{$type}");
$this
->assertRaw(t('Edited title'));
$this
->drupalGet("{$langcode}/node/add/{$type}");
$this
->assertRaw(t('Translated title'));
}
}