diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index d102559..b39663c 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -188,6 +188,16 @@ public static function request() { } /** + * Retrives the request stack. + * + * @return \Symfony\Component\HttpFoundation\RequestStack + * The request stack + */ + public static function requestStack() { + return static::$container->get('request_stack'); + } + + /** * Retrieves the currently active route match object. * * @return \Drupal\Core\Routing\RouteMatchInterface diff --git a/core/lib/Drupal/Core/PathProcessor/PathProcessorCurrent.php b/core/lib/Drupal/Core/PathProcessor/PathProcessorCurrent.php index a665c1c..5a44f16 100644 --- a/core/lib/Drupal/Core/PathProcessor/PathProcessorCurrent.php +++ b/core/lib/Drupal/Core/PathProcessor/PathProcessorCurrent.php @@ -19,10 +19,12 @@ class PathProcessorCurrent implements OutboundPathProcessorInterface { */ public function processOutbound($path, &$options = array(), Request $request = NULL) { if ($path == '%3Ccurrent%3E' && $request) { - $path_info = $request->getPathInfo(); + $request_uri = $request->getRequestUri(); $current_base_path = $request->getBasePath() . '/'; - return mb_strcut($path_info, strlen($current_base_path)); + debug($request_uri); + debug($current_base_path); + return substr($request_uri, strlen($current_base_path)); } return $path; } diff --git a/core/modules/node/src/Controller/NodeController.php b/core/modules/node/src/Controller/NodeController.php index 2990324..bf3a7c7 100644 --- a/core/modules/node/src/Controller/NodeController.php +++ b/core/modules/node/src/Controller/NodeController.php @@ -62,6 +62,8 @@ public static function create(ContainerInterface $container) { public function addPage() { $content = array(); + debug(\Drupal::url('')); + // Only use node types the user has access to. foreach ($this->entityManager()->getStorage('node_type')->loadMultiple() as $type) { if ($this->entityManager()->getAccessControlHandler('node')->createAccess($type->type)) { diff --git a/core/modules/system/src/Tests/PathProcessor/PathProcessorCurrentIntegrationTest.php b/core/modules/system/src/Tests/PathProcessor/PathProcessorCurrentIntegrationTest.php index f7f55ba..74388ed 100644 --- a/core/modules/system/src/Tests/PathProcessor/PathProcessorCurrentIntegrationTest.php +++ b/core/modules/system/src/Tests/PathProcessor/PathProcessorCurrentIntegrationTest.php @@ -8,22 +8,80 @@ namespace Drupal\system\Tests\PathProcessor; use Drupal\simpletest\KernelTestBase; +use Symfony\Component\HttpFoundation\Request; /** * @see \Drupal\Core\PathProcessor\PathProcessorCurrent * @group path_processor */ -class PathProcessorIntegrationTest extends KernelTestBase { +class PathProcessorCurrentIntegrationTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['system']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->installSchema('system', ['router']); + \Drupal::service('router.builder')->rebuild(); + } /** * Tests the output process. */ public function testProcessOutbound() { - // Test installation with subdir. - // Test installation without subdir. + $request_stack = \Drupal::requestStack(); + /** @var \Symfony\Component\Routing\RequestContext $request_context */ + $request_context = \Drupal::service('router.request_context'); + + // Test request with subdir on homepage. + $server = [ + 'SCRIPT_NAME' => '/subdir/index.php', + 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SERVER_NAME' => 'http://www.example.com', + ]; + $request = Request::create('/subdir', 'GET', [], [], [], $server); + $request_stack->push($request); + $request_context->fromRequest($request); + $this->assertEqual('/subdir/', \Drupal::url('')); - $this->assertEqual('', \Drupal::url('')); + // Test request with subdir on other page. + $server = [ + 'SCRIPT_NAME' => '/subdir/index.php', + 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SERVER_NAME' => 'http://www.example.com', + ]; + $request = Request::create('/subdir/node/add', 'GET', [], [], [], $server); + $request_stack->push($request); + $request_context->fromRequest($request); + $this->assertEqual('/subdir/node/add', \Drupal::url('')); + + // Test request without subdir on the homepage. + $server = [ + 'SCRIPT_NAME' => '/index.php', + 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SERVER_NAME' => 'http://www.example.com', + ]; + $request = Request::create('/', 'GET', [], [], [], $server); + $request_stack->push($request); + $request_context->fromRequest($request); + $this->assertEqual('/', \Drupal::url('')); + + // Test request without subdir on other page. + $server = [ + 'SCRIPT_NAME' => '/index.php', + 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SERVER_NAME' => 'http://www.example.com', + ]; + $request = Request::create('/node/add', 'GET', [], [], [], $server); + $request_stack->push($request); + $request_context->fromRequest($request); + $this->assertEqual('/node/add', \Drupal::url('')); } } - diff --git a/core/tests/Drupal/Tests/Core/DrupalTest.php b/core/tests/Drupal/Tests/Core/DrupalTest.php index 5af3c73..4ca6f09 100644 --- a/core/tests/Drupal/Tests/Core/DrupalTest.php +++ b/core/tests/Drupal/Tests/Core/DrupalTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Core; use Drupal\Tests\UnitTestCase; +use Symfony\Component\HttpFoundation\RequestStack; /** * Tests the Drupal class. @@ -132,6 +133,18 @@ public function testQueue() { } /** + * Tests the testRequestStack() method. + * + * @covers ::requestStack + */ + public function testRequestStack() { + $request_stack = new RequestStack(); + $this->setMockContainerService('request_stack', $request_stack); + + $this->assertSame($request_stack, \Drupal::requestStack()); + } + + /** * Tests the keyValue() method. */ public function testKeyValue() {