function NodeTypeTranslationTest::testNodeTypeTitleLabelTranslation

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php \Drupal\Tests\node\Functional\NodeTypeTranslationTest::testNodeTypeTitleLabelTranslation()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php \Drupal\Tests\node\Functional\NodeTypeTranslationTest::testNodeTypeTitleLabelTranslation()
  3. 10 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 142

Class

NodeTypeTranslationTest
Ensures that node types translation work correctly.

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeTypeTitleLabelTranslation() : void {
    $type = $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->drupalGet("admin/structure/types/manage/{$type}");
    $this->submitForm([
        'title_label' => 'Edited title',
    ], 'Save');
    // 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->assertSession()
        ->pageTextContains('Edited title');
    // Translate the title label.
    $this->submitForm([
        "translation[config_names][core.base_field_override.node.{$type}.title][label]" => 'Translated title',
    ], '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->assertSession()
        ->pageTextContains('Edited title');
    $this->drupalGet("{$langcode}/node/add/{$type}");
    $this->assertSession()
        ->pageTextContains('Translated title');
    // Add an email field.
    $this->drupalGet("admin/structure/types/manage/{$type}/fields/add-field");
    $this->submitForm([
        'new_storage_type' => 'email',
    ], 'Continue');
    $this->submitForm([
        'label' => 'Email',
        'field_name' => 'email',
    ], 'Continue');
    $this->submitForm([], 'Update settings');
    $this->submitForm([], 'Save settings');
    $type = $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->drupalGet('admin/config/regional/language');
    $this->submitForm([
        'site_default_language' => 'es',
    ], 'Save configuration');
    // Try re-using the email field.
    $this->drupalGet("es/admin/structure/types/manage/{$type}/fields/reuse");
    $this->submitForm([], 'Re-use');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->drupalGet("es/admin/structure/types/manage/{$type}/fields/node.{$type}.field_email/translate");
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains("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.