diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 94b5109..f257f9f 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -380,15 +380,15 @@ protected function registerPathProcessors(ContainerBuilder $container) { $container->register('path_processor_manager', 'Drupal\Core\PathProcessor\PathProcessorManager'); // Register the processor that urldecodes the path. $container->register('path_processor_decode', 'Drupal\Core\PathProcessor\PathProcessorDecode') - ->addTag('inbound_path_processor', array('priority' => 300)); + ->addTag('path_processor_inbound', array('priority' => 1000)); // Register the processor that resolves the front page. $container->register('path_processor_front', 'Drupal\Core\PathProcessor\PathProcessorFront') ->addArgument(new Reference('config.factory')) - ->addTag('inbound_path_processor', array('priority' => 200)); + ->addTag('path_processor_inbound', array('priority' => 200)); // Register the alias path processor. $container->register('path_processor_alias', 'Drupal\Core\PathProcessor\PathProcessorAlias') ->addArgument(new Reference('path.alias_manager')) - ->addTag('inbound_path_processor', array('priority' => 100)); + ->addTag('path_processor_inbound', array('priority' => 100)); // Add the compiler pass that will process the tagged services. $container->addCompilerPass(new RegisterPathProcessorsPass()); diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterPathProcessorsPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterPathProcessorsPass.php index fd3cb5b..6e298da 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterPathProcessorsPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterPathProcessorsPass.php @@ -17,7 +17,7 @@ class RegisterPathProcessorsPass implements CompilerPassInterface { /** - * Adds services tagged 'inbound_path_processor' to the path processor manager. + * Adds services tagged 'path_processor_inbound' to the path processor manager. * * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * The container to process. @@ -27,7 +27,7 @@ public function process(ContainerBuilder $container) { return; } $manager = $container->getDefinition('path_processor_manager'); - foreach ($container->findTaggedServiceIds('inbound_path_processor') as $id => $attributes) { + foreach ($container->findTaggedServiceIds('path_processor_inbound') as $id => $attributes) { $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0; $manager->addMethodCall('addInbound', array(new Reference($id), $priority)); } diff --git a/core/lib/Drupal/Core/PathProcessor/PathProcessorManager.php b/core/lib/Drupal/Core/PathProcessor/PathProcessorManager.php index b79f0c7..1d0adff 100644 --- a/core/lib/Drupal/Core/PathProcessor/PathProcessorManager.php +++ b/core/lib/Drupal/Core/PathProcessor/PathProcessorManager.php @@ -45,10 +45,6 @@ class PathProcessorManager implements InboundPathProcessorInterface { * The priority of the processor being added. */ public function addInbound(InboundPathProcessorInterface $processor, $priority = 0) { - if (empty($this->inboundProcessors[$priority])) { - $this->inboundProcessors[$priority] = array(); - } - $this->inboundProcessors[$priority][] = $processor; $this->sortedInbound = array(); } diff --git a/core/modules/language/lib/Drupal/language/HttpKernel/PathProcessorLanguage.php b/core/modules/language/lib/Drupal/language/HttpKernel/PathProcessorLanguage.php index 3954451..ad16ac6 100644 --- a/core/modules/language/lib/Drupal/language/HttpKernel/PathProcessorLanguage.php +++ b/core/modules/language/lib/Drupal/language/HttpKernel/PathProcessorLanguage.php @@ -2,7 +2,7 @@ /** * @file - * Contains Drupal\language\PathProcessorLanguage. + * Contains Drupal\language\HttpKernel\PathProcessorLanguage. */ namespace Drupal\language\HttpKernel; diff --git a/core/modules/language/lib/Drupal/language/LanguageBundle.php b/core/modules/language/lib/Drupal/language/LanguageBundle.php index 458bff5..1e788aa 100644 --- a/core/modules/language/lib/Drupal/language/LanguageBundle.php +++ b/core/modules/language/lib/Drupal/language/LanguageBundle.php @@ -23,7 +23,7 @@ public function build(ContainerBuilder $container) { // Register the language-based path processor. $container->register('path_processor_language', 'Drupal\language\HttpKernel\PathProcessorLanguage') ->addArgument(new Reference('module_handler')) - ->addTag('inbound_path_processor', array('priority' => 250)); + ->addTag('path_processor_inbound', array('priority' => 300)); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php b/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php index 275e1c4..5dc3158 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\system\Tests\Path\CrudTest. + * Contains Drupal\system\Tests\Path\AliasTest. */ namespace Drupal\system\Tests\Path; @@ -15,7 +15,7 @@ /** * Tests path alias CRUD and lookup functionality. */ -class AliasTest extends DrupalUnitTestBase { +class AliasTest extends PathUnitTestBase { public static function getInfo() { return array( @@ -25,18 +25,6 @@ public static function getInfo() { ); } - public function setUp() { - parent::setUp(); - $this->fixtures = new UrlAliasFixtures(); - } - - public function tearDown() { - $this->fixtures->dropTables(Database::getConnection()); - - parent::tearDown(); - } - - function testCRUD() { //Prepare database table. $connection = Database::getConnection(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/PathUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Path/PathUnitTestBase.php new file mode 100644 index 0000000..c24506d --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Path/PathUnitTestBase.php @@ -0,0 +1,28 @@ +fixtures = new UrlAliasFixtures(); + } + + public function tearDown() { + $this->fixtures->dropTables(Database::getConnection()); + + parent::tearDown(); + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/UrlAliasFixtures.php b/core/modules/system/lib/Drupal/system/Tests/Path/UrlAliasFixtures.php index 6fb02da..a51e3bf 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Path/UrlAliasFixtures.php +++ b/core/modules/system/lib/Drupal/system/Tests/Path/UrlAliasFixtures.php @@ -16,7 +16,7 @@ class UrlAliasFixtures { * The connection to use to create the tables. */ public function createTables(Connection $connection) { - $tables = $this->urlAliasTableDefinition(); + $tables = $this->tableDefinition(); $schema = $connection->schema(); foreach ($tables as $name => $table) { @@ -32,7 +32,7 @@ public function createTables(Connection $connection) { * The connection to use to drop the tables. */ public function dropTables(Connection $connection) { - $tables = $this->urlAliasTableDefinition(); + $tables = $this->tableDefinition(); $schema = $connection->schema(); foreach ($tables as $name => $table) { @@ -77,7 +77,7 @@ public function sampleUrlAliases() { * @return array * Table definitions. */ - public function urlAliasTableDefinition() { + public function tableDefinition() { $tables = array(); module_load_install('system'); diff --git a/core/modules/system/lib/Drupal/system/Tests/PathProcessor/PathProcessorFixtures.php b/core/modules/system/lib/Drupal/system/Tests/PathProcessor/PathProcessorFixtures.php new file mode 100644 index 0000000..dbc987d --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/PathProcessor/PathProcessorFixtures.php @@ -0,0 +1,27 @@ + t('Path Processor Unit Tests'), + 'description' => t('Tests processing of the inbound path.'), + 'group' => t('Path API'), + ); + } + + public function setUp() { + parent::setUp(); + $this->fixtures = new PathProcessorFixtures(); + } + + /** + * Tests resolving the inbound path to the system path. + */ + function testProcessInbound() { + + // Ensure all tables needed for these tests are created. + $connection = Database::getConnection(); + $this->fixtures->createTables($connection); + + // Create dependecies needed by various path processors. + $alias_manager = new AliasManager($connection, $this->container->get('state'), $this->container->get('language_manager')); + $module_handler = $this->container->get('module_handler'); + + // Create the processors. + $alias_processor = new PathProcessorAlias($alias_manager); + $decode_processor = new PathProcessorDecode(); + $front_processor = new PathProcessorFront($this->container->get('config.factory')); + $language_processor = new PathProcessorLanguage($module_handler); + + // Add a url alias for testing the alias-based processor. + $path_crud = new Path($connection, $alias_manager); + $path_crud->save('user/1', 'foo'); + + // Add a language for testing the language-based processor. + $module_handler->setModuleList(array('language' => 'core/modules/language/language.module')); + $module_handler->load('language'); + $language = new \stdClass(); + $language->langcode = 'fr'; + $language->name = 'French'; + language_save($language); + + // First, test the processor manager with the processors in the incorrect + // order. The alias processor will run before the language processor, meaning + // aliases will not be found. + $priorities = array( + 1000 => $alias_processor, + 500 => $decode_processor, + 300 => $front_processor, + 200 => $language_processor, + ); + + // Create the processor manager and add the processors. + $processor_manager = new PathProcessorManager(); + foreach ($priorities as $priority => $processor) { + $processor_manager->addInbound($processor, $priority); + } + + // Test resolving the French homepage using the incorrect processor order. + $test_path = 'fr'; + $request = Request::create($test_path); + $processed = $processor_manager->processInbound($test_path, $request); + $this->assertEqual($processed, '', 'Processing in the incorrect order fails to resolve the system path from the empty path'); + + // Test resolving an existing alias using the incorrect processor order. + $test_path = 'fr/foo'; + $request = Request::create($test_path); + $processed = $processor_manager->processInbound($test_path, $request); + $this->assertEqual($processed, 'foo', 'Processing in the incorrect order fails to resolve the system path from an alias'); + + // Now create a new processor manager and add the processors, this time in + // the correct order. + $processor_manager = new PathProcessorManager(); + $priorities = array( + 1000 => $decode_processor, + 500 => $language_processor, + 300 => $front_processor, + 200 => $alias_processor, + ); + foreach ($priorities as $priority => $processor) { + $processor_manager->addInbound($processor, $priority); + } + + // Test resolving the French homepage using the correct processor order. + $test_path = 'fr'; + $request = Request::create($test_path); + $processed = $processor_manager->processInbound($test_path, $request); + $this->assertEqual($processed, 'user', 'Processing in the correct order resolves the system path from the empty path.'); + + // Test resolving an existing alias using the correct processor order. + $test_path = 'fr/foo'; + $request = Request::create($test_path); + $processed = $processor_manager->processInbound($test_path, $request); + $this->assertEqual($processed, 'user/1', 'Processing in the correct order resolves the system path from an alias.'); + } + +}