You are here

protected function LanguageNeutralAliasesStorageTest::setUp in Language neutral aliases 8

Setup test.

Overrides KernelTestBase::setUp

File

tests/src/Kernel/LanguageNeutralAliasesStorageTest.php, line 33

Class

LanguageNeutralAliasesStorageTest
Test language neutral aliases.

Namespace

Drupal\Tests\language_neutral_aliases\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this->field = 'path';
  $this->idField = 'id';

  // Before 8.8 the field was named source.
  if (version_compare(Drupal::VERSION, '8.8', '<')) {
    $this->field = 'source';
    $this->idField = 'pid';
  }
  else {
    $this
      ->installEntitySchema('path_alias');
  }
  $database = $this->container
    ->get('database');

  // Create some test data.
  $storage = $this->container
    ->get('path.alias_storage');
  $storage
    ->save('/node/1', '/path/first');
  $storage
    ->save('/node/2', '/path/second');
  $storage
    ->save('/node/3', '/path/third');

  // Change the language of some aliases.
  $database
    ->update(LanguageNeutralAliasesStorage::TABLE)
    ->fields([
    'langcode' => 'de',
  ])
    ->condition($this->field, '/node/1')
    ->execute();
  $database
    ->update(LanguageNeutralAliasesStorage::TABLE)
    ->fields([
    'langcode' => 'da',
  ])
    ->condition($this->field, '/node/2')
    ->execute();
  if ($this->field === 'path') {
    $database
      ->update('path_alias_revision')
      ->fields([
      'langcode' => 'de',
    ])
      ->condition($this->field, '/node/1')
      ->execute();
    $database
      ->update('path_alias_revision')
      ->fields([
      'langcode' => 'da',
    ])
      ->condition($this->field, '/node/2')
      ->execute();
  }
}