diff --git a/tests/src/Functional/PathautoTestHelperTrait.php b/tests/src/Functional/PathautoTestHelperTrait.php index 3f91caa..d0d529a 100644 --- a/tests/src/Functional/PathautoTestHelperTrait.php +++ b/tests/src/Functional/PathautoTestHelperTrait.php @@ -10,12 +10,15 @@ use Drupal\pathauto\PathautoPatternInterface; use Drupal\taxonomy\VocabularyInterface; use Drupal\taxonomy\Entity\Vocabulary; use Drupal\taxonomy\Entity\Term; +use Drupal\Tests\Traits\Core\PathAliasTestTrait; /** * Helper test class with some added functions for testing. */ trait PathautoTestHelperTrait { + use PathAliasTestTrait; + /** * Creates a pathauto pattern. * @@ -76,18 +79,12 @@ trait PathautoTestHelperTrait { $this->assertSame($tokens[$token], $expected, t("Token value for [@type:@token] was '@actual', expected value '@expected'.", ['@type' => $type, '@token' => $token, '@actual' => $tokens[$token], '@expected' => $expected])); } - public function saveAlias($source, $alias, $langcode = Language::LANGCODE_NOT_SPECIFIED) { - $alias_to_delete = \Drupal::service('entity_type.manager')->getStorage('path_alias')->loadByProperties(['path' => $source, 'langcode' => $langcode]); - \Drupal::service('entity_type.manager')->getStorage('path_alias')->delete($alias_to_delete); - return \Drupal::service('entity_type.manager')->getStorage('path_alias')->create(['path' => $source, 'alias' => $alias, 'langcode' => $langcode])->save(); - } - public function saveEntityAlias(EntityInterface $entity, $alias, $langcode = NULL) { // By default, use the entity language. if (!$langcode) { $langcode = $entity->language()->getId(); } - return $this->saveAlias('/' . $entity->toUrl()->getInternalPath(), $alias, $langcode); + return $this->createPathAlias('/' . $entity->toUrl()->getInternalPath(), $alias, $langcode); } public function assertEntityAlias(EntityInterface $entity, $expected_alias, $langcode = NULL) { @@ -129,13 +126,13 @@ trait PathautoTestHelperTrait { } public function assertAliasExists($conditions) { - $path = \Drupal::service('entity_type.manager')->getStorage('path_alias')->loadByProperties($conditions); + $path = $this->loadPathAliasByConditions($conditions); $this->assertNotEmpty($path, t('Alias with conditions @conditions found.', ['@conditions' => var_export($conditions, TRUE)])); return $path; } public function assertNoAliasExists($conditions) { - $alias = \Drupal::service('entity_type.manager')->getStorage('path_alias')->loadByProperties($conditions); + $alias = $this->loadPathAliasByConditions($conditions); $this->assertFalse($alias, t('Alias with conditions @conditions not found.', ['@conditions' => var_export($conditions, TRUE)])); } diff --git a/tests/src/FunctionalJavascript/PathautoLocaleTest.php b/tests/src/FunctionalJavascript/PathautoLocaleTest.php index 21d9275..dab3e73 100644 --- a/tests/src/FunctionalJavascript/PathautoLocaleTest.php +++ b/tests/src/FunctionalJavascript/PathautoLocaleTest.php @@ -60,7 +60,7 @@ class PathautoLocaleTest extends WebDriverTestBase { ]], ]; $node = $this->drupalCreateNode($node); - $english_alias = \Drupal::service('entity_type.manager')->getStorage('path_alias')->loadByProperties(['alias' => '/english-node', 'langcode' => 'en']); + $english_alias = $this->loadPathAliasByConditions(['alias' => '/english-node', 'langcode' => 'en']); $this->assertNotEmpty($english_alias, 'Alias created with proper language.'); // Also save a French alias that should not be left alone, even though @@ -69,7 +69,7 @@ class PathautoLocaleTest extends WebDriverTestBase { // Add an alias with the soon-to-be generated alias, causing the upcoming // alias update to generate a unique alias with the '-0' suffix. - $this->saveAlias('/node/invalid', '/content/english-node', Language::LANGCODE_NOT_SPECIFIED); + $this->createPathAlias('/node/invalid', '/content/english-node', Language::LANGCODE_NOT_SPECIFIED); // Update the node, triggering a change in the English alias. $node->path->pathauto = PathautoState::CREATE; @@ -78,7 +78,7 @@ class PathautoLocaleTest extends WebDriverTestBase { // Check that the new English alias replaced the old one. $this->assertEntityAlias($node, '/content/english-node-0', 'en'); $this->assertEntityAlias($node, '/french-node', 'fr'); - $this->assertAliasExists(['pid' => $english_alias['pid'], 'alias' => '/content/english-node-0']); + $this->assertAliasExists(['pid' => $english_alias->id(), 'alias' => '/content/english-node-0']); // Create a new node with the same title as before but without // specifying a language. diff --git a/tests/src/Kernel/PathautoKernelTest.php b/tests/src/Kernel/PathautoKernelTest.php index 430256b..8c25fce 100644 --- a/tests/src/Kernel/PathautoKernelTest.php +++ b/tests/src/Kernel/PathautoKernelTest.php @@ -250,12 +250,12 @@ class PathautoKernelTest extends KernelTestBase { * Test pathauto_path_delete_multiple(). */ public function testPathDeleteMultiple() { - $this->saveAlias('/node/1', '/node-1-alias'); - $this->saveAlias('/node/1/view', '/node-1-alias/view'); - $this->saveAlias('/node/1', '/node-1-alias-en', 'en'); - $this->saveAlias('/node/1', '/node-1-alias-fr', 'fr'); - $this->saveAlias('/node/2', '/node-2-alias'); - $this->saveAlias('/node/10', '/node-10-alias'); + $this->createPathAlias('/node/1', '/node-1-alias'); + $this->createPathAlias('/node/1/view', '/node-1-alias/view'); + $this->createPathAlias('/node/1', '/node-1-alias-en', 'en'); + $this->createPathAlias('/node/1', '/node-1-alias-fr', 'fr'); + $this->createPathAlias('/node/2', '/node-2-alias'); + $this->createPathAlias('/node/10', '/node-10-alias'); \Drupal::service('pathauto.alias_storage_helper')->deleteBySourcePrefix('/node/1'); $this->assertNoAliasExists(['path' => "/node/1"]); @@ -302,7 +302,7 @@ class PathautoKernelTest extends KernelTestBase { $this->assertNoAliasExists(['alias' => '/content/third-title']); // The older second alias is not deleted yet. $older_path = $this->assertAliasExists(['path' => '/' . $node->toUrl()->getInternalPath(), 'alias' => '/content/second-title']); - \Drupal::service('entity_type.manager')->getStorage('path_alias')->delete($older_path); + \Drupal::service('entity_type.manager')->getStorage('path_alias')->delete([$older_path]); $config->set('update_action', PathautoGeneratorInterface::UPDATE_ACTION_NO_NEW); $config->save();