You are here

public function LanguageNeutralAliasesStorageTest::testSave in Language neutral aliases 8

Test that new aliases gets saved with language neutral.

File

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

Class

LanguageNeutralAliasesStorageTest
Test language neutral aliases.

Namespace

Drupal\Tests\language_neutral_aliases\Kernel

Code

public function testSave() {
  $storage = $this->container
    ->get('path.alias_storage');
  $storage
    ->save('/node/4', '/path/fourth', 'de');
  $expected = [
    'pid' => '4',
    'source' => '/node/4',
    'alias' => '/path/fourth',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ];
  $actual = $storage
    ->load([
    $this->field => '/node/4',
  ]);
  $this
    ->assertEqual($expected, $actual);

  // Ensure that non-neutral language aliases is not overwritten.
  $storage
    ->save('/node/1', '/path/fifth', 'de', $this
    ->getPid('/node/1'));
  $expected = [
    'pid' => '5',
    'source' => '/node/1',
    'alias' => '/path/fifth',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ];
  $actual = $storage
    ->load([
    'alias' => '/path/fifth',
  ]);
  $this
    ->assertEqual($expected, $actual);

  // Ensure that language neutral aliases can be updated.
  $storage
    ->save('/node/4', '/path/sixth', LanguageInterface::LANGCODE_NOT_SPECIFIED, $this
    ->getPid('/node/4'));
  $expected = [
    'pid' => '4',
    'source' => '/node/4',
    'alias' => '/path/sixth',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ];
  $actual = $storage
    ->load([
    $this->field => '/node/4',
  ]);
}