You are here

protected function PathLanguageTest::setUp in Zircon Profile 8

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

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides PathTestBase::setUp

File

core/modules/path/src/Tests/PathLanguageTest.php, line 31
Contains \Drupal\path\Tests\PathLanguageTest.

Class

PathLanguageTest
Confirm that paths work with translated nodes.

Namespace

Drupal\path\Tests

Code

protected function setUp() {
  parent::setUp();
  $permissions = array(
    '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 login user.
  $this->webUser = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($this->webUser);

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

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

  // Enable translation for page node.
  $edit = array(
    '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'));
  \Drupal::entityManager()
    ->clearCachedDefinitions();
  $definitions = \Drupal::entityManager()
    ->getFieldDefinitions('node', 'page');
  $this
    ->assertTrue($definitions['path']
    ->isTranslatable(), 'Node path is translatable.');
  $this
    ->assertTrue($definitions['body']
    ->isTranslatable(), 'Node body is translatable.');
}