diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index d33daa1..a77632f 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -19,7 +19,6 @@ use Drupal\Core\Render\Element; use Drupal\Core\Render\ElementInfoManagerInterface; use Drupal\Core\Theme\ThemeManagerInterface; -use Drupal\Core\Url; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; @@ -685,25 +684,15 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) { * The URL to be used as the $form['#action']. */ protected function buildFormAction() { - $request = $this->requestStack->getMasterRequest(); - - // Do not attempt to use \Drupal\Core\Url during installation, - // return the request URI directly. - if (drupal_installation_attempted()) { - return $request->getRequestUri(); - } - // @todo Use instead of the master request in // https://www.drupal.org/node/2505339. - $url = Url::fromUri('internal:' . $request->getRequestUri()); + $request_uri = $this->requestStack->getMasterRequest()->getRequestUri(); // @todo Remove this unset() once these are removed from the request in // https://www.drupal.org/node/2504709. - $query = $url->getOption('query'); - unset($query[FormBuilderInterface::AJAX_FORM_REQUEST], $query[MainContentViewSubscriber::WRAPPER_FORMAT]); - $url->setOption('query', $query); - - return $url->toString(); + $parsed = UrlHelper::parse($request_uri); + unset($parsed['query'][FormBuilderInterface::AJAX_FORM_REQUEST], $parsed['query'][MainContentViewSubscriber::WRAPPER_FORMAT]); + return $parsed['path'] . ($parsed['query'] ? ('?' . UrlHelper::buildQuery($parsed['query'])) : ''); } /** diff --git a/core/modules/dblog/src/Tests/DbLogFormInjectionTest.php b/core/modules/dblog/src/Tests/DbLogFormInjectionTest.php index af69263..e622fe2 100644 --- a/core/modules/dblog/src/Tests/DbLogFormInjectionTest.php +++ b/core/modules/dblog/src/Tests/DbLogFormInjectionTest.php @@ -83,10 +83,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { protected function setUp() { parent::setUp(); $this->installSchema('dblog', ['watchdog']); - $this->installSchema('system', ['key_value_expire', 'router', 'sequences']); + $this->installSchema('system', ['key_value_expire', 'sequences']); $this->installEntitySchema('user'); - \Drupal::service('router.builder')->rebuild(); - $this->logger = \Drupal::logger('test_logger'); $test_user = User::create(array( 'name' => 'foobar', diff --git a/core/modules/language/src/Tests/LanguageListTest.php b/core/modules/language/src/Tests/LanguageListTest.php index 252b6d3..e72a6b0 100644 --- a/core/modules/language/src/Tests/LanguageListTest.php +++ b/core/modules/language/src/Tests/LanguageListTest.php @@ -7,7 +7,6 @@ namespace Drupal\language\Tests; -use Drupal\Core\Url; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\simpletest\WebTestBase; use Drupal\Core\Language\Language; @@ -137,11 +136,7 @@ function testLanguageList() { // We need raw here because %language and %langcode will add HTML. $t_args = array('%language' => 'French', '%langcode' => 'fr'); $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The French language has been removed.'); - // The previous request had still two languages (before the container - // rebuild), so the form pointed to /en. Now that we removed 'fr', - // \Drupal::url() will no longer take language url processing in mind, - // therefore add a manual prefix. - $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'prefix' => $english->getId() . '/'])); + $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE])); // Verify that language is no longer found. $this->drupalGet('admin/config/regional/language/delete/fr'); $this->assertResponse(404, 'Language no longer found.'); diff --git a/core/modules/system/src/Tests/Form/FormDefaultHandlersTest.php b/core/modules/system/src/Tests/Form/FormDefaultHandlersTest.php index de3b596..94187af 100644 --- a/core/modules/system/src/Tests/Form/FormDefaultHandlersTest.php +++ b/core/modules/system/src/Tests/Form/FormDefaultHandlersTest.php @@ -31,8 +31,7 @@ class FormDefaultHandlersTest extends KernelTestBase implements FormInterface { */ protected function setUp() { parent::setUp(); - $this->installSchema('system', ['key_value_expire', 'router']); - \Drupal::service('router.builder')->rebuild(); + $this->installSchema('system', ['key_value_expire']); } /** diff --git a/core/modules/system/src/Tests/Form/RedirectTest.php b/core/modules/system/src/Tests/Form/RedirectTest.php index aface9e..6ea944c 100644 --- a/core/modules/system/src/Tests/Form/RedirectTest.php +++ b/core/modules/system/src/Tests/Form/RedirectTest.php @@ -97,7 +97,7 @@ public function testRedirectFromErrorPages() { $this->assertResponse(404); $this->drupalPostForm(NULL, array(), t('Submit')); $this->assertResponse(200); - $this->assertUrl($expected); + $this->assertUrl($expected, [], 'Redirected to correct url/query.'); // Visit the block admin page (403 page) and submit the form. Verify it // ends up at the right URL. @@ -105,6 +105,6 @@ public function testRedirectFromErrorPages() { $this->assertResponse(403); $this->drupalPostForm(NULL, array(), t('Submit')); $this->assertResponse(200); - $this->assertUrl($expected); + $this->assertUrl($expected, [], 'Redirected to correct url/query.'); } } diff --git a/core/modules/system/src/Tests/Queue/QueueSerializationTest.php b/core/modules/system/src/Tests/Queue/QueueSerializationTest.php index 584d8ba..9108ac2 100644 --- a/core/modules/system/src/Tests/Queue/QueueSerializationTest.php +++ b/core/modules/system/src/Tests/Queue/QueueSerializationTest.php @@ -81,10 +81,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { */ protected function setUp() { parent::setUp(); - $this->installSchema('system', ['key_value_expire', 'router', 'sequences', 'queue']); + $this->installSchema('system', ['key_value_expire', 'sequences', 'queue']); $this->installEntitySchema('user'); - \Drupal::service('router.builder')->rebuild(); - $this->queue = \Drupal::service('queue.database')->get('aggregator_refresh'); $test_user = User::create(array( 'name' => 'foobar', diff --git a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php index 0e22d19..679eec0 100644 --- a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php +++ b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php @@ -26,16 +26,6 @@ class UserAccountFormFieldsTest extends KernelTestBase { public static $modules = array('system', 'user', 'field'); /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->installSchema('system', ['router']); - \Drupal::service('router.builder')->rebuild(); - } - - /** * Tests the root user account form section in the "Configure site" form. */ function testInstallConfigureForm() { @@ -88,6 +78,10 @@ function testUserEditForm() { // Install default configuration; required for AccountFormController. $this->installConfig(array('user')); + // Install the router table and then rebuild. + $this->installSchema('system', ['router']); + \Drupal::service('router.builder')->rebuild(); + $form = $this->buildAccountForm('default'); // Verify name and pass field order. diff --git a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php index 5b8d1ab..b6fe9dd 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php +++ b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php @@ -189,10 +189,7 @@ protected function setUp() { ->getMock(); $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); - $this->formBuilder = $this->getMockBuilder('Drupal\Core\Form\FormBuilder') - ->setConstructorArgs([$this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->elementInfo, $this->themeManager, $this->csrfToken, $this->kernel]) - ->setMethods(['buildFormAction']) - ->getMock(); + $this->formBuilder = new FormBuilder($this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->elementInfo, $this->themeManager, $this->csrfToken, $this->kernel); } /**