diff --git a/core/modules/path/src/Tests/PathLanguageUiTest.php b/core/modules/path/src/Tests/PathLanguageUiTest.php index ab33c0e..b6836fe 100644 --- a/core/modules/path/src/Tests/PathLanguageUiTest.php +++ b/core/modules/path/src/Tests/PathLanguageUiTest.php @@ -45,7 +45,7 @@ protected function setUp() { function testLanguageNeutralUrl() { $name = $this->randomMachineName(8); $edit = array(); - $edit['source'] = 'admin/config/search/path'; + $edit['path'] = 'admin/config/search/path'; $edit['alias'] = $name; $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); @@ -59,7 +59,7 @@ function testLanguageNeutralUrl() { function testDefaultLanguageUrl() { $name = $this->randomMachineName(8); $edit = array(); - $edit['source'] = 'admin/config/search/path'; + $edit['path'] = 'admin/config/search/path'; $edit['alias'] = $name; $edit['langcode'] = 'en'; $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); @@ -74,7 +74,7 @@ function testDefaultLanguageUrl() { function testNonDefaultUrl() { $name = $this->randomMachineName(8); $edit = array(); - $edit['source'] = 'admin/config/search/path'; + $edit['path'] = 'admin/config/search/path'; $edit['alias'] = $name; $edit['langcode'] = 'fr'; $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); diff --git a/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php b/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php index 32b3d26..3314ad2 100644 --- a/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php +++ b/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php @@ -127,8 +127,6 @@ public function testSimpleEntityType() { * Tests a field whose associated in-place editor generates custom metadata. */ public function testEditorWithCustomMetadata() { - $this->installSchema('system', 'url_alias'); - $this->editorManager = $this->container->get('plugin.manager.quickedit.editor'); $this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter')); $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager); diff --git a/core/modules/serialization/src/Tests/NormalizerTestBase.php b/core/modules/serialization/src/Tests/NormalizerTestBase.php index 531c53d..73e0342 100644 --- a/core/modules/serialization/src/Tests/NormalizerTestBase.php +++ b/core/modules/serialization/src/Tests/NormalizerTestBase.php @@ -23,7 +23,6 @@ protected function setUp() { $this->installEntitySchema('entity_test_mulrev'); $this->installEntitySchema('user'); - $this->installSchema('system', array('url_alias')); $this->installConfig(array('field')); // Auto-create a field for testing. diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php index 24c5550..bc09396 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -30,11 +30,14 @@ public function testShortcutLinkAdd() { $set = $this->set; // Create an alias for the node so we can test aliases. - $path = array( - 'source' => 'node/' . $this->node->id(), - 'alias' => $this->randomMachineName(8), - ); - $this->container->get('path.alias_storage')->save($path['source'], $path['alias']); + $alias = $this->container->get('entity.manager')->getStorage('alias') + ->create( + array( + 'path' => $this->node->getSystemPath(), + 'alias' => $this->randomMachineName(8), + ) + ); + $alias->save(); // Create some paths to test. $test_cases = array( @@ -43,7 +46,7 @@ public function testShortcutLinkAdd() { array('path' => 'admin', 'route_name' => 'system.admin'), array('path' => 'admin/config/system/site-information', 'route_name' => 'system.site_information_settings'), array('path' => 'node/' . $this->node->id() . '/edit', 'route_name' => 'entity.node.edit_form'), - array('path' => $path['alias'], 'route_name' => 'entity.node.canonical'), + array('path' => $alias->get('alias')->value, 'route_name' => 'entity.node.canonical'), array('path' => 'router_test/test2', 'route_name' => 'router_test.2'), array('path' => 'router_test/test3/value', 'route_name' => 'router_test.3'), ); diff --git a/core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php b/core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php index 76e87f4..0c82ffd 100644 --- a/core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php +++ b/core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php @@ -19,11 +19,6 @@ */ class EntityAccessControlHandlerTest extends EntityLanguageTestBase { - protected function setUp() { - parent::setUp(); - $this->installSchema('system', 'url_alias'); - } - /** * Asserts entity access correctly grants or denies access. */ diff --git a/core/modules/system/src/Tests/Path/AliasTest.php b/core/modules/system/src/Tests/Path/AliasTest.php index d91c59f..0674b0a 100644 --- a/core/modules/system/src/Tests/Path/AliasTest.php +++ b/core/modules/system/src/Tests/Path/AliasTest.php @@ -8,10 +8,11 @@ namespace Drupal\system\Tests\Path; use Drupal\Core\Cache\MemoryCounterBackend; -use Drupal\Core\Path\AliasStorage; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Database\Database; use Drupal\Core\Path\AliasManager; use Drupal\Core\Path\AliasWhitelist; +use Drupal\language\Entity\ConfigurableLanguage; /** * Tests path alias CRUD and lookup functionality. @@ -20,134 +21,212 @@ */ class AliasTest extends PathUnitTestBase { + public static $modules = array('language'); + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->installConfig(array('language')); + + $i = 0; + foreach (array('af', 'fr') as $langcode) { + $language = ConfigurableLanguage::createFromLangcode($langcode); + $language->set('weight', $i--); + $language->save(); + } + } + function testCRUD() { //Prepare database table. $connection = Database::getConnection(); - $this->fixtures->createTables($connection); - - //Create Path object. - $aliasStorage = new AliasStorage($connection, $this->container->get('module_handler')); + $this->fixtures->createTables($connection, $this->container->get('entity.manager')); $aliases = $this->fixtures->sampleUrlAliases(); //Create a few aliases foreach ($aliases as $idx => $alias) { - $aliasStorage->save($alias['source'], $alias['alias'], $alias['langcode']); - - $result = $connection->query('SELECT * FROM {url_alias} WHERE source = :source AND alias= :alias AND langcode = :langcode', array(':source' => $alias['source'], ':alias' => $alias['alias'], ':langcode' => $alias['langcode'])); + $this->container->get('entity.manager') + ->getStorage('alias') + ->create( + array( + 'path' => $alias['path'], + 'alias' => $alias['alias'], + 'langcode' => $alias['langcode'] + ) + ) + ->save(); + + $result = $connection->query('SELECT * FROM {alias_field_data} WHERE path = :path AND alias= :alias AND langcode = :langcode', array(':path' => $alias['path'], ':alias' => $alias['alias'], ':langcode' => $alias['langcode'])); $rows = $result->fetchAll(); $this->assertEqual(count($rows), 1, format_string('Created an entry for %alias.', array('%alias' => $alias['alias']))); //Cache the pid for further tests. - $aliases[$idx]['pid'] = $rows[0]->pid; + $aliases[$idx]['aid'] = $rows[0]->aid; } //Load a few aliases foreach ($aliases as $alias) { - $pid = $alias['pid']; - $loadedAlias = $aliasStorage->load(array('pid' => $pid)); - $this->assertEqual($loadedAlias, $alias, format_string('Loaded the expected path with pid %pid.', array('%pid' => $pid))); + $aid = $alias['aid']; + $loadedAlias = $this->container->get('entity.manager') + ->getStorage('alias') + ->load($alias['aid']); + + $this->assertEqual($loadedAlias->get('alias')->value, $alias['alias'], format_string('Loaded the expected alias with aid %aid.', array('%aid' => $aid))); + $this->assertEqual($loadedAlias->get('path')->value, $alias['path'], format_string('Loaded the expected path with aid %aid.', array('%aid' => $aid))); + $this->assertEqual($loadedAlias->get('langcode')->value, $alias['langcode'], format_string('Loaded the expected langcode with aid %aid.', array('%aid' => $aid))); } //Update a few aliases foreach ($aliases as $alias) { - $fields = $aliasStorage->save($alias['source'], $alias['alias'] . '_updated', $alias['langcode'], $alias['pid']); - - $this->assertEqual($alias['alias'], $fields['original']['alias']); + $loadedAlias = $this->container->get('entity.manager') + ->getStorage('alias') + ->load($alias['aid']); + $loadedAlias->alias = $alias['alias'] . '_updated'; + $loadedAlias->save(); - $result = $connection->query('SELECT pid FROM {url_alias} WHERE source = :source AND alias= :alias AND langcode = :langcode', array(':source' => $alias['source'], ':alias' => $alias['alias'] . '_updated', ':langcode' => $alias['langcode'])); - $pid = $result->fetchField(); + $result = $connection->query('SELECT aid FROM {alias_field_data} WHERE path = :path AND alias= :alias AND langcode = :langcode', array(':path' => $alias['path'], ':alias' => $alias['alias'] . '_updated', ':langcode' => $alias['langcode'])); + $aid = $result->fetchField(); - $this->assertEqual($pid, $alias['pid'], format_string('Updated entry for pid %pid.', array('%pid' => $pid))); + $this->assertEqual($aid, $alias['aid'], format_string('Updated entry for aid %aid.', array('%aid' => $aid))); } //Delete a few aliases foreach ($aliases as $alias) { - $pid = $alias['pid']; - $aliasStorage->delete(array('pid' => $pid)); + $loadedAlias = $this->container->get('entity.manager') + ->getStorage('alias') + ->load($alias['aid']); + $loadedAlias->delete(); - $result = $connection->query('SELECT * FROM {url_alias} WHERE pid = :pid', array(':pid' => $pid)); + $result = $connection->query('SELECT * FROM {alias_field_data} WHERE aid = :aid', array(':aid' => $alias['aid'])); $rows = $result->fetchAll(); - $this->assertEqual(count($rows), 0, format_string('Deleted entry with pid %pid.', array('%pid' => $pid))); + $this->assertEqual(count($rows), 0, format_string('Deleted entry with aid %aid.', array('%aid' => $aid))); } } function testLookupPath() { + /** @var \Drupal\Core\Path\AliasStorageInterface $alias_storage */ + $alias_storage = $this->container->get('entity.manager')->getStorage('alias'); + //Prepare database table. $connection = Database::getConnection(); - $this->fixtures->createTables($connection); + $this->fixtures->createTables($connection, $this->container->get('entity.manager')); //Create AliasManager and Path object. $aliasManager = $this->container->get('path.alias_manager'); - $aliasStorage = new AliasStorage($connection, $this->container->get('module_handler')); // Test the situation where the source is the same for multiple aliases. // Start with a language-neutral alias, which we will override. - $path = array( - 'source' => "user/1", + $alias = array( + 'path' => "user/1", 'alias' => 'foo', ); - $aliasStorage->save($path['source'], $path['alias']); - $this->assertEqual($aliasManager->getAliasByPath($path['source']), $path['alias'], 'Basic alias lookup works.'); - $this->assertEqual($aliasManager->getPathByAlias($path['alias']), $path['source'], 'Basic source lookup works.'); + $alias_storage->create( + array( + 'path' => $alias['path'], + 'alias' => $alias['alias'], + ) + ) + ->save(); + $this->assertEqual($aliasManager->getAliasByPath($alias['path']), $alias['alias'], 'Basic alias lookup works.'); + $this->assertEqual($aliasManager->getPathByAlias($alias['alias']), $alias['path'], 'Basic source lookup works.'); // Create a language specific alias for the default language (English). - $path = array( - 'source' => "user/1", + $alias = array( + 'path' => "user/1", 'alias' => "users/Dries", 'langcode' => 'en', ); - $aliasStorage->save($path['source'], $path['alias'], $path['langcode']); + $alias_storage->create( + array( + 'path' => $alias['path'], + 'alias' => $alias['alias'], + 'langcode' => $alias['langcode'], + ) + ) + ->save(); // Hook that clears cache is not executed with unit tests. \Drupal::service('path.alias_manager')->cacheClear(); - $this->assertEqual($aliasManager->getAliasByPath($path['source']), $path['alias'], 'English alias overrides language-neutral alias.'); - $this->assertEqual($aliasManager->getPathByAlias($path['alias']), $path['source'], 'English source overrides language-neutral source.'); + $this->assertEqual($aliasManager->getAliasByPath($alias['path']), $alias['alias'], 'English alias overrides language-neutral alias.'); + $this->assertEqual($aliasManager->getPathByAlias($alias['alias']), $alias['path'], 'English source overrides language-neutral source.'); // Create a language-neutral alias for the same path, again. - $path = array( - 'source' => "user/1", + $alias = array( + 'path' => "user/1", 'alias' => 'bar', ); - $aliasStorage->save($path['source'], $path['alias']); - $this->assertEqual($aliasManager->getAliasByPath($path['source']), "users/Dries", 'English alias still returned after entering a language-neutral alias.'); + $alias_storage->create( + array( + 'path' => $alias['path'], + 'alias' => $alias['alias'], + 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, + ) + ) + ->save(); + $this->assertEqual($aliasManager->getAliasByPath($alias['path']), "users/Dries", 'English alias still returned after entering a language-neutral alias.'); // Create a language-specific (xx-lolspeak) alias for the same path. - $path = array( - 'source' => "user/1", + $alias = array( + 'path' => "user/1", 'alias' => 'LOL', - 'langcode' => 'xx-lolspeak', + 'langcode' => 'af', ); - $aliasStorage->save($path['source'], $path['alias'], $path['langcode']); - $this->assertEqual($aliasManager->getAliasByPath($path['source']), "users/Dries", 'English alias still returned after entering a LOLspeak alias.'); + $alias_storage->create( + array( + 'path' => $alias['path'], + 'alias' => $alias['alias'], + 'langcode' => $alias['langcode'], + ) + ) + ->save(); + $this->assertEqual($aliasManager->getAliasByPath($alias['path']), "users/Dries", 'English alias still returned after entering a LOLspeak alias.'); // The LOLspeak alias should be returned if we really want LOLspeak. - $this->assertEqual($aliasManager->getAliasByPath($path['source'], 'xx-lolspeak'), 'LOL', 'LOLspeak alias returned if we specify xx-lolspeak to the alias manager.'); + $this->assertEqual($aliasManager->getAliasByPath($alias['path'], 'af'), 'LOL', 'LOLspeak alias returned if we specify af to the alias manager.'); // Create a new alias for this path in English, which should override the // previous alias for "user/1". - $path = array( - 'source' => "user/1", + $alias = array( + 'path' => "user/1", 'alias' => 'users/my-new-path', 'langcode' => 'en', ); - $aliasStorage->save($path['source'], $path['alias'], $path['langcode']); + $alias_storage->create( + array( + 'path' => $alias['path'], + 'alias' => $alias['alias'], + 'langcode' => $alias['langcode'], + ) + ) + ->save(); // Hook that clears cache is not executed with unit tests. $aliasManager->cacheClear(); - $this->assertEqual($aliasManager->getAliasByPath($path['source']), $path['alias'], 'Recently created English alias returned.'); - $this->assertEqual($aliasManager->getPathByAlias($path['alias']), $path['source'], 'Recently created English source returned.'); + $this->assertEqual($aliasManager->getAliasByPath($alias['path']), $alias['alias'], 'Recently created English alias returned.'); + $this->assertEqual($aliasManager->getPathByAlias($alias['alias']), $alias['path'], 'Recently created English source returned.'); // Remove the English aliases, which should cause a fallback to the most // recently created language-neutral alias, 'bar'. - $aliasStorage->delete(array('langcode' => 'en')); + $aids = $this->container->get('entity.query')->get('alias') + ->condition('langcode', 'en') + ->execute(); + $alias_storage->delete($alias_storage->loadMultiple($aids)); // Hook that clears cache is not executed with unit tests. $aliasManager->cacheClear(); - $this->assertEqual($aliasManager->getAliasByPath($path['source']), 'bar', 'Path lookup falls back to recently created language-neutral alias.'); + $this->assertEqual($aliasManager->getAliasByPath('user/1'), 'bar', 'Path lookup falls back to recently created language-neutral alias.'); // Test the situation where the alias and language are the same, but // the source differs. The newer alias record should be returned. - $aliasStorage->save('user/2', 'bar'); + $alias_storage->create( + array( + 'path' => 'user/2', + 'alias' => 'bar', + 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, + )) + ->save(); // Hook that clears cache is not executed with unit tests. $aliasManager->cacheClear(); $this->assertEqual($aliasManager->getPathByAlias('bar'), 'user/2', 'Newer alias record is returned when comparing two LanguageInterface::LANGCODE_NOT_SPECIFIED paths with the same alias.'); @@ -159,14 +238,13 @@ function testLookupPath() { function testWhitelist() { // Prepare database table. $connection = Database::getConnection(); - $this->fixtures->createTables($connection); + $this->fixtures->createTables($connection, $this->container->get('entity.manager')); $memoryCounterBackend = new MemoryCounterBackend('default'); - // Create AliasManager and Path object. - $aliasStorage = new AliasStorage($connection, $this->container->get('module_handler')); - $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $aliasStorage); - $aliasManager = new AliasManager($aliasStorage, $whitelist, $this->container->get('language_manager'), $memoryCounterBackend); + // Create AliasManager object. + $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $this->container->get('entity.manager')); + $aliasManager = new AliasManager($this->container->get('entity.manager'), $whitelist, $this->container->get('language_manager'), $memoryCounterBackend); // No alias for user and admin yet, so should be NULL. $this->assertNull($whitelist->get('user')); @@ -177,21 +255,42 @@ function testWhitelist() { $this->assertNull($whitelist->get($this->randomMachineName())); // Add an alias for user/1, user should get whitelisted now. - $aliasStorage->save('user/1', $this->randomMachineName()); + $this->container->get('entity.manager') + ->getStorage('alias') + ->create( + array( + 'path' => 'user/1', + 'alias' => $this->randomMachineName(), + 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, + ) + ) + ->save(); $aliasManager->cacheClear(); $this->assertTrue($whitelist->get('user')); $this->assertNull($whitelist->get('admin')); $this->assertNull($whitelist->get($this->randomMachineName())); // Add an alias for admin, both should get whitelisted now. - $aliasStorage->save('admin/something', $this->randomMachineName()); + $this->container->get('entity.manager') + ->getStorage('alias') + ->create( + array( + 'path' => 'admin/something', + 'alias' => $this->randomMachineName(), + 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, + ) + ) + ->save(); $aliasManager->cacheClear(); $this->assertTrue($whitelist->get('user')); $this->assertTrue($whitelist->get('admin')); $this->assertNull($whitelist->get($this->randomMachineName())); // Remove the user alias again, whitelist entry should be removed. - $aliasStorage->delete(array('source' => 'user/1')); + $aids = $this->container->get('entity.query')->get('alias') + ->condition('path', 'user/1') + ->execute(); + $this->container->get('entity.manager')->getStorage('alias')->delete($this->container->get('entity.manager')->getStorage('alias')->loadMultiple($aids)); $aliasManager->cacheClear(); $this->assertNull($whitelist->get('user')); $this->assertTrue($whitelist->get('admin')); @@ -204,7 +303,7 @@ function testWhitelist() { // Re-initialize the whitelist using the same cache backend, should load // from cache. - $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $aliasStorage); + $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $this->container->get('entity.manager')); $this->assertNull($whitelist->get('user')); $this->assertTrue($whitelist->get('admin')); $this->assertNull($whitelist->get($this->randomMachineName())); diff --git a/core/modules/system/src/Tests/Path/PathUnitTestBase.php b/core/modules/system/src/Tests/Path/PathUnitTestBase.php index 3d25b1b..2ead69b 100644 --- a/core/modules/system/src/Tests/Path/PathUnitTestBase.php +++ b/core/modules/system/src/Tests/Path/PathUnitTestBase.php @@ -29,7 +29,7 @@ protected function setUp() { } protected function tearDown() { - $this->fixtures->dropTables(Database::getConnection()); + $this->fixtures->dropTables(Database::getConnection(), $this->container->get('entity.manager')); parent::tearDown(); } diff --git a/core/modules/system/src/Tests/Path/UrlAliasFixtures.php b/core/modules/system/src/Tests/Path/UrlAliasFixtures.php index 777ffb1..60b2290 100644 --- a/core/modules/system/src/Tests/Path/UrlAliasFixtures.php +++ b/core/modules/system/src/Tests/Path/UrlAliasFixtures.php @@ -3,6 +3,7 @@ namespace Drupal\system\Tests\Path; use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\EntityManagerInterface; /** * Utility methods to generate sample data, database configuration, etc. @@ -15,7 +16,7 @@ class UrlAliasFixtures { * @param \Drupal\Core\Database\Connection $connection * The connection to use to create the tables. */ - public function createTables(Connection $connection) { + public function createTables(Connection $connection, EntityManagerInterface $entity_manager) { $tables = $this->tableDefinition(); $schema = $connection->schema(); @@ -23,6 +24,9 @@ public function createTables(Connection $connection) { $schema->dropTable($name); $schema->createTable($name, $table); } + + $entity_manager->onEntityTypeDelete($entity_manager->getDefinition('alias')); + $entity_manager->onEntityTypeCreate($entity_manager->getDefinition('alias')); } /** @@ -31,13 +35,15 @@ public function createTables(Connection $connection) { * @param \Drupal\Core\Database\Connection $connection * The connection to use to drop the tables. */ - public function dropTables(Connection $connection) { + public function dropTables(Connection $connection, EntityManagerInterface $entity_manager) { $tables = $this->tableDefinition(); $schema = $connection->schema(); foreach ($tables as $name => $table) { $schema->dropTable($name); } + + $entity_manager->onEntityTypeDelete($entity_manager->getDefinition('alias')); } /** @@ -48,22 +54,22 @@ public function dropTables(Connection $connection) { public function sampleUrlAliases() { return array( array( - 'source' => 'node/1', + 'path' => 'node/1', 'alias' => 'alias_for_node_1_en', 'langcode' => 'en' ), array( - 'source' => 'node/2', + 'path' => 'node/2', 'alias' => 'alias_for_node_2_en', 'langcode' => 'en' ), array( - 'source' => 'node/1', + 'path' => 'node/1', 'alias' => 'alias_for_node_1_fr', 'langcode' => 'fr' ), array( - 'source' => 'node/1', + 'path' => 'node/1', 'alias' => 'alias_for_node_1_und', 'langcode' => 'und' ) @@ -83,7 +89,6 @@ public function tableDefinition() { module_load_install('system'); $schema = system_schema(); - $tables['url_alias'] = $schema['url_alias']; $tables['key_value'] = $schema['key_value']; return $tables;