function MenuUiContentTranslationTest::testChangeContentToPseudoLanguage

Same name in other branches
  1. 11.x core/modules/menu_ui/tests/src/Functional/MenuUiContentTranslationTest.php \Drupal\Tests\menu_ui\Functional\MenuUiContentTranslationTest::testChangeContentToPseudoLanguage()

Tests changing content with menu link from language to pseudo language.

@dataProvider provideChangeContentToPseudoLanguageData

Parameters

string $langcode: Language code of pseudo-language to change content language to. Either \Drupal\Core\LanguageInterface::LANGCODE_NOT_SPECIFIED or \Drupal\Core\LanguageInterface::LANGCODE_NOT_APPLICABLE.

File

core/modules/menu_ui/tests/src/Functional/MenuUiContentTranslationTest.php, line 121

Class

MenuUiContentTranslationTest
Tests Menu UI and Content Translation integration for content entities.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testChangeContentToPseudoLanguage($langcode) : void {
    $node_title = 'Test node';
    $menu_link_title_en = 'Test menu link EN';
    $menu_link_title_pseudo = 'Test menu link PSEUDO';
    // Create a page node in English.
    $this->drupalGet('node/add/page');
    $this->assertSession()
        ->statusCodeEquals(200);
    $edit = [
        'title[0][value]' => $node_title,
        'menu[enabled]' => 1,
        'menu[title]' => $menu_link_title_en,
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Assert that node exists and node language is English.
    $node = $this->getContentEntityByTitle('node', $node_title);
    $this->assertTrue(is_object($node));
    $this->assertTrue($node->language()
        ->getId() == 'en');
    // Assert that menu link exists and menu link language is English.
    $menu_link = $this->getContentEntityByTitle('menu_link_content', $menu_link_title_en);
    $this->assertTrue(is_object($menu_link));
    $this->assertTrue($menu_link->language()
        ->getId() == 'en');
    $this->assertTrue($menu_link->hasTranslation('en'));
    // Assert that menu link is visible with initial title.
    $this->assertSession()
        ->linkExists($menu_link_title_en);
    // Change language of page node and title of its menu link.
    $this->clickLink('Edit');
    $edit = [
        'langcode[0][value]' => $langcode,
        'menu[title]' => $menu_link_title_pseudo,
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Assert that node exists and node language is target language.
    $node = $this->getContentEntityByTitle('node', $node_title);
    $this->assertTrue(is_object($node));
    $this->assertTrue($node->language()
        ->getId() == $langcode);
    // Assert that menu link exists and menu link language is target language.
    $menu_link = $this->getContentEntityByTitle('menu_link_content', $menu_link_title_pseudo);
    $this->assertTrue(is_object($menu_link));
    $this->assertTrue($menu_link->language()
        ->getId() == $langcode);
    $this->assertFalse($menu_link->hasTranslation('en'));
    // Assert that menu link is visible with updated title.
    $this->assertSession()
        ->linkExists($menu_link_title_pseudo);
}

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