diff --git a/core/modules/user/src/Plugin/Block/UserLoginBlock.php b/core/modules/user/src/Plugin/Block/UserLoginBlock.php index 6709454..a9341f9 100644 --- a/core/modules/user/src/Plugin/Block/UserLoginBlock.php +++ b/core/modules/user/src/Plugin/Block/UserLoginBlock.php @@ -100,6 +100,9 @@ public function build() { // https://www.drupal.org/node/2562341. The placholder uses a fixed string // that is // Crypt::hashBase64('\Drupal\user\Plugin\Block\UserLoginBlock::build'); + // This is based on the implementation in + // \Drupal\Core\Form\FormBuilder::prepareForm(), but the user login block + // requires different behavior for the destination query argument. $placeholder = 'form_action_p_4r8ITd22yaUvXM6SzwrSe9rnQWe48hz9k1Sxto3pBvE'; $form['#attached']['placeholders'][$placeholder] = [ @@ -145,6 +148,8 @@ public function build() { * * @return array * A renderable array representing the form action. + * + * @see \Drupal\Core\Form\FormBuilder::renderPlaceholderFormAction() */ public static function renderPlaceholderFormAction() { return [ diff --git a/core/modules/user/src/Tests/UserBlocksTest.php b/core/modules/user/src/Tests/UserBlocksTest.php index 26dcf89..e22fbd4 100644 --- a/core/modules/user/src/Tests/UserBlocksTest.php +++ b/core/modules/user/src/Tests/UserBlocksTest.php @@ -2,6 +2,7 @@ namespace Drupal\user\Tests; +use Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber; use Drupal\simpletest\WebTestBase; /** @@ -77,20 +78,26 @@ public function testUserLoginBlock() { // Now, log out and repeat with a non-403 page. $this->drupalLogout(); - $this->drupalPostForm('filter/tips', $edit, t('Log in')); + $this->drupalGet('filter/tips'); + $this->assertEqual('MISS', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER)); + $this->drupalPostForm(NULL, $edit, t('Log in')); $this->assertNoText(t('User login'), 'Logged in.'); $this->assertPattern('!!', 'Still on the same page after login for allowed page'); // Log out again and repeat with a non-403 page including query arguments. $this->drupalLogout(); - $this->drupalPostForm('filter/tips', $edit, t('Log in'), ['query' => ['foo' => 'bar']]); + $this->drupalGet('filter/tips', ['query' => ['foo' => 'bar']]); + $this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER)); + $this->drupalPostForm(NULL, $edit, t('Log in')); $this->assertNoText(t('User login'), 'Logged in.'); $this->assertPattern('!!', 'Still on the same page after login for allowed page'); $this->assertTrue(strpos($this->getUrl(),'/filter/tips?foo=bar') !== FALSE, 'Correct query arguments are displayed after login'); // Repeat with different query arguments. $this->drupalLogout(); - $this->drupalPostForm('filter/tips', $edit, t('Log in'), ['query' => ['foo' => 'baz']]); + $this->drupalGet('filter/tips', ['query' => ['foo' => 'baz']]); + $this->assertEqual('HIT', $this->drupalGetHeader(DynamicPageCacheSubscriber::HEADER)); + $this->drupalPostForm(NULL, $edit, t('Log in')); $this->assertNoText(t('User login'), 'Logged in.'); $this->assertPattern('!!', 'Still on the same page after login for allowed page'); $this->assertTrue(strpos($this->getUrl(),'/filter/tips?foo=baz') !== FALSE, 'Correct query arguments are displayed after login');