You are here

protected function PathLanguageTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/path/tests/src/Functional/PathLanguageTest.php \Drupal\Tests\path\Functional\PathLanguageTest::setUp()

Overrides PathTestBase::setUp

File

core/modules/path/tests/src/Functional/PathLanguageTest.php, line 36

Class

PathLanguageTest
Confirm that paths work with translated nodes.

Namespace

Drupal\Tests\path\Functional

Code

protected function setUp() {
  parent::setUp();
  $permissions = [
    'access administration pages',
    'administer content translation',
    'administer content types',
    'administer languages',
    'administer url aliases',
    'create content translations',
    'create page content',
    'create url aliases',
    'edit any page content',
    'translate any entity',
  ];

  // Create and log in user.
  $this->webUser = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($this->webUser);

  // Enable French language.
  $edit = [];
  $edit['predefined_langcode'] = 'fr';
  $this
    ->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));

  // Enable URL language detection and selection.
  $edit = [
    'language_interface[enabled][language-url]' => 1,
  ];
  $this
    ->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));

  // Enable translation for page node.
  $edit = [
    'entity_types[node]' => 1,
    'settings[node][page][translatable]' => 1,
    'settings[node][page][fields][path]' => 1,
    'settings[node][page][fields][body]' => 1,
    'settings[node][page][settings][language][language_alterable]' => 1,
  ];
  $this
    ->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
  $definitions = \Drupal::service('entity_field.manager')
    ->getFieldDefinitions('node', 'page');
  $this
    ->assertTrue($definitions['path']
    ->isTranslatable(), 'Node path is translatable.');
  $this
    ->assertTrue($definitions['body']
    ->isTranslatable(), 'Node body is translatable.');
}