Commit 8dc402f9 authored by catch's avatar catch

Issue #2616164 by agoradesign, swentel, facine, dawehner: /update.php/run URL...

Issue #2616164 by agoradesign, swentel, facine, dawehner: /update.php/run URL is generated with language prefix and returns 404 error
parent b97d20d9
......@@ -305,14 +305,18 @@ public function generateFromRoute($name, $parameters = array(), $options = array
return $collect_bubbleable_metadata ? $generated_url->setGeneratedUrl($url) : $url;
}
$options += array('prefix' => '');
$options += $route->getOption('default_url_options') ?: [];
$options += array('prefix' => '', 'path_processing' => TRUE);
$name = $this->getRouteDebugMessage($name);
$this->processRoute($name, $route, $parameters, $generated_url);
$path = $this->getInternalPathFromRoute($name, $route, $parameters, $query_params);
// Outbound path processors might need the route object for the path, e.g.
// to get the path pattern.
$options['route'] = $route;
$path = $this->processPath($path, $options, $generated_url);
if ($options['path_processing']) {
$path = $this->processPath($path, $options, $generated_url);
}
if (!empty($options['prefix'])) {
$path = ltrim($path, '/');
......
......@@ -8,6 +8,7 @@
namespace Drupal\system\Tests\Update;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
/**
......@@ -22,7 +23,7 @@ class UpdateScriptTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('update_script_test', 'dblog');
public static $modules = array('update_script_test', 'dblog', 'language');
/**
* {@inheritdoc}
......@@ -218,6 +219,57 @@ function testMaintenanceModeUpdateFunctionality() {
$this->assertEqual($final_maintenance_mode, $initial_maintenance_mode, 'Maintenance mode should not have changed after database updates.');
}
/**
* Tests perfoming updates with update.php in a multilingual environment.
*/
function testSuccessfulMultilingualUpdateFunctionality() {
// Add some custom languages.
foreach (array('aa', 'bb') as $language_code) {
ConfigurableLanguage::create(array(
'id' => $language_code,
'label' => $this->randomMachineName(),
))->save();
}
$config = \Drupal::service('config.factory')->getEditable('language.negotiation');
// Ensure path prefix is used to determine the language.
$config->set('url.source', 'path_prefix');
// Ensure that there's a path prefix set for english as well.
$config->set('url.prefixes.en', 'en');
$config->save();
// Reset the static cache to ensure we have the most current setting.
$schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
$this->assertEqual($schema_version, 8001, 'update_script_test schema version is 8001 after updating.');
// Set the installed schema version to one less than the current update.
drupal_set_installed_schema_version('update_script_test', $schema_version - 1);
$schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
$this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.');
// Create admin user.
$admin_user = $this->drupalCreateUser(array('administer software updates', 'access administration pages', 'access site reports', 'access site in maintenance mode', 'administer site configuration'));
$this->drupalLogin($admin_user);
// Visit status report page and ensure, that link to update.php has no path prefix set.
$this->drupalGet('en/admin/reports/status', array('external' => TRUE));
$this->assertResponse(200);
$this->assertLinkByHref('/update.php');
$this->assertNoLinkByHref('en/update.php');
// Click through update.php with 'access administration pages' and
// 'access site reports' permissions.
$this->drupalGet($this->updateUrl, array('external' => TRUE));
$this->clickLink(t('Continue'));
$this->clickLink(t('Apply pending updates'));
$this->assertText('Updates were attempted.');
$this->assertLink('logged');
$this->assertLink('Administration pages');
$this->assertNoLinkByHrefInMainRegion('update.php', 1);
$this->clickLink('Administration pages');
$this->assertResponse(200);
}
/**
* Helper function to run updates via the browser.
*/
......
......@@ -464,6 +464,9 @@ system.db_update:
op: 'info'
requirements:
_access: 'TRUE'
options:
default_url_options:
path_processing: FALSE
system.admin_content:
path: '/admin/content'
......
......@@ -9,12 +9,15 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\PathProcessor\PathProcessorAlias;
use Drupal\Core\PathProcessor\PathProcessorManager;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Routing\RequestContext;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Routing\UrlGenerator;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Route;
......@@ -28,6 +31,13 @@
*/
class UrlGeneratorTest extends UnitTestCase {
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected $provider;
/**
* The url generator to test.
*
......@@ -56,6 +66,13 @@ class UrlGeneratorTest extends UnitTestCase {
*/
protected $requestStack;
/**
* The request context.
*
* @var \Drupal\Core\Routing\RequestContext
*/
protected $context;
/**
* {@inheritdoc}
*/
......@@ -115,7 +132,8 @@ protected function setUp() {
$route_name_return_map[] = array($values['route_name'], $values['return']);
$routes_names_return_map[] = array(array($values['route_name']), $values['return']);
}
$provider->expects($this->any())
$this->provider = $provider;
$this->provider->expects($this->any())
->method('getRouteByName')
->will($this->returnValueMap($route_name_return_map));
$provider->expects($this->any())
......@@ -137,8 +155,8 @@ protected function setUp() {
$request = Request::create('/some/path');
$this->requestStack->push($request);
$context = new RequestContext();
$context->fromRequestStack($this->requestStack);
$this->context = new RequestContext();
$this->context->fromRequestStack($this->requestStack);
$processor = new PathProcessorAlias($this->aliasManager);
$processor_manager = new PathProcessorManager();
......@@ -148,8 +166,8 @@ protected function setUp() {
->disableOriginalConstructor()
->getMock();
$generator = new UrlGenerator($provider, $processor_manager, $this->routeProcessorManager, $this->requestStack, ['http', 'https']);
$generator->setContext($context);
$generator = new UrlGenerator($this->provider, $processor_manager, $this->routeProcessorManager, $this->requestStack, ['http', 'https']);
$generator->setContext($this->context);
$this->generator = $generator;
}
......@@ -198,6 +216,54 @@ public function testAliasGeneration() {
$this->assertEquals('test/one', $path);
}
/**
* @covers ::generateFromRoute
*/
public function testUrlGenerationWithDisabledPathProcessing() {
$path_processor = $this->prophesize(OutboundPathProcessorInterface::class);
$path_processor->processOutbound(Argument::cetera())->shouldNotBeCalled();
$generator = new UrlGenerator($this->provider, $path_processor->reveal(), $this->routeProcessorManager, $this->requestStack, ['http', 'https']);
$generator->setContext($this->context);
$url = $this->generator->generateFromRoute('test_1', [], ['path_processing' => FALSE]);
$this->assertEquals('/test/one', $url);
}
/**
* @covers ::generateFromRoute
*/
public function testUrlGenerationWithDisabledPathProcessingByRoute() {
$path_processor = $this->prophesize(OutboundPathProcessorInterface::class);
$path_processor->processOutbound(Argument::cetera())->shouldNotBeCalled();
$provider = $this->prophesize(RouteProviderInterface::class);
$provider->getRouteByName('test_1')->willReturn(new Route('/test/one', [], [], ['default_url_options' => ['path_processing' => FALSE]]));
$generator = new UrlGenerator($provider->reveal(), $path_processor->reveal(), $this->routeProcessorManager, $this->requestStack, ['http', 'https']);
$generator->setContext($this->context);
$url = $generator->generateFromRoute('test_1', []);
$this->assertEquals('/test/one', $url);
}
/**
* @covers ::generateFromRoute
*/
public function testUrlGenerationWithDisabledPathProcessingByRouteAndOptedInPathProcessing() {
$path_processor = $this->prophesize(OutboundPathProcessorInterface::class);
$path_processor->processOutbound('/test/one', Argument::cetera())->willReturn('/hello/world')->shouldBeCalled();
$provider = $this->prophesize(RouteProviderInterface::class);
$provider->getRouteByName('test_1')->willReturn(new Route('/test/one', [], [], ['default_url_options' => ['path_processing' => FALSE]]));
$generator = new UrlGenerator($provider->reveal(), $path_processor->reveal(), $this->routeProcessorManager, $this->requestStack, ['http', 'https']);
$generator->setContext($this->context);
$url = $generator->generateFromRoute('test_1', [], ['path_processing' => TRUE]);
$this->assertEquals('/hello/world', $url);
}
/**
* Tests URL generation in a subdirectory.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment