function LocaleContentTest::testMachineNameLTR

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

Verifies that machine name fields are always LTR.

File

core/modules/locale/tests/src/Functional/LocaleContentTest.php, line 32

Class

LocaleContentTest
Tests you can enable multilingual support on content types and configure a language for a node.

Namespace

Drupal\Tests\locale\Functional

Code

public function testMachineNameLTR() {
    // User to add and remove language.
    $admin_user = $this->drupalCreateUser([
        'administer languages',
        'administer content types',
        'access administration pages',
        'administer site configuration',
    ]);
    // Log in as admin.
    $this->drupalLogin($admin_user);
    // Verify that the machine name field is LTR for a new content type.
    $this->drupalGet('admin/structure/types/add');
    $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when no additional language is configured.');
    // Install the Arabic language (which is RTL) and configure as the default.
    $edit = [];
    $edit['predefined_langcode'] = 'ar';
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
    $edit = [
        'site_default_language' => 'ar',
    ];
    $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
    // Verify that the machine name field is still LTR for a new content type.
    $this->drupalGet('admin/structure/types/add');
    $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when the default language is RTL.');
}

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