function NodeTypeTranslationTest::testNodeTypeTitleLabelTranslation

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php \Drupal\Tests\node\Functional\NodeTypeTranslationTest::testNodeTypeTitleLabelTranslation()
  2. 10 core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php \Drupal\Tests\node\Functional\NodeTypeTranslationTest::testNodeTypeTitleLabelTranslation()
  3. 11.x core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php \Drupal\Tests\node\Functional\NodeTypeTranslationTest::testNodeTypeTitleLabelTranslation()

Tests the node type title label translation.

File

core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php, line 135

Class

NodeTypeTranslationTest
Ensures that node types translation work correctly.

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeTypeTitleLabelTranslation() {
    $type = mb_strtolower($this->randomMachineName(16));
    $name = $this->randomString();
    $this->drupalLogin($this->adminUser);
    $this->drupalCreateContentType([
        'type' => $type,
        'name' => $name,
    ]);
    $langcode = $this->additionalLangcodes[0];
    // Edit the title label for it to be displayed on the translation form.
    $this->drupalPostForm("admin/structure/types/manage/{$type}", [
        'title_label' => 'Edited title',
    ], t('Save content type'));
    // Assert that the title label is displayed on the translation form with the right value.
    $this->drupalGet("admin/structure/types/manage/{$type}/translate/{$langcode}/add");
    $this->assertText('Edited title');
    // Translate the title label.
    $this->drupalPostForm(NULL, [
        "translation[config_names][core.base_field_override.node.{$type}.title][label]" => 'Translated title',
    ], t('Save translation'));
    // Assert that the right title label is displayed on the node add form. The
    // translations are created in this test; therefore, the assertions do not
    // use t(). If t() were used then the correct langcodes would need to be
    // provided.
    $this->drupalGet("node/add/{$type}");
    $this->assertText('Edited title');
    $this->drupalGet("{$langcode}/node/add/{$type}");
    $this->assertText('Translated title');
    // Add an e-mail field.
    $this->drupalPostForm("admin/structure/types/manage/{$type}/fields/add-field", [
        'new_storage_type' => 'email',
        'label' => 'Email',
        'field_name' => 'email',
    ], 'Save and continue');
    $this->drupalPostForm(NULL, [], 'Save field settings');
    $this->drupalPostForm(NULL, [], 'Save settings');
    $type = mb_strtolower($this->randomMachineName(16));
    $name = $this->randomString();
    $this->drupalCreateContentType([
        'type' => $type,
        'name' => $name,
    ]);
    // Set tabs.
    $this->drupalPlaceBlock('local_tasks_block', [
        'primary' => TRUE,
    ]);
    // Change default language.
    $this->drupalPostForm('admin/config/regional/language', [
        'site_default_language' => 'es',
    ], 'Save configuration');
    // Try re-using the email field.
    $this->drupalGet("es/admin/structure/types/manage/{$type}/fields/add-field");
    $this->drupalPostForm(NULL, [
        'existing_storage_name' => 'field_email',
        'existing_storage_label' => 'Email',
    ], 'Save and continue');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->drupalGet("es/admin/structure/types/manage/{$type}/fields/node.{$type}.field_email/translate");
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertText("The configuration objects have different language codes so they cannot be translated");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.