Issue #2905818 by Wim Leers, Lendude: Make sure \Drupal\Tests\BrowserTestBase::checkForMetaRefresh is case insensitive
parent
5f77cf76af
commit
aae0baf839
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\test_page_test\Controller;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
/**
|
||||
|
@ -108,4 +111,16 @@ class Test {
|
|||
return ['#markup' => '<a href="http://example.com">foo|bar|baz</a>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a page that does a redirect.
|
||||
*
|
||||
* Drupal uses Symfony's RedirectResponse for generating redirects. That class
|
||||
* uses a lower-case 'http-equiv="refresh"'.
|
||||
*
|
||||
* @see \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function metaRefresh() {
|
||||
return new RedirectResponse(Url::fromRoute('test_page_test.test_page', [], ['absolute' => TRUE])->toString(), 302);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,3 +82,11 @@ test_page_test.field_xpath:
|
|||
_form: '\Drupal\test_page_test\Form\TestForm'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
||||
test_page_test.meta_refresh:
|
||||
path: '/test-meta-refresh'
|
||||
defaults:
|
||||
_title: 'Page with a redirect'
|
||||
_controller: '\Drupal\test_page_test\Controller\Test::metaRefresh'
|
||||
requirements:
|
||||
_access: 'TRUE'
|
||||
|
|
|
@ -605,4 +605,22 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
|||
$this->assertEquals('Australia/Sydney', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ::checkForMetaRefresh() method.
|
||||
*/
|
||||
public function testCheckForMetaRefresh() {
|
||||
// Disable following redirects in the client.
|
||||
$this->getSession()->getDriver()->getClient()->followRedirects(FALSE);
|
||||
// Set the maximumMetaRefreshCount to zero to make sure the redirect doesn't
|
||||
// happen when doing a drupalGet.
|
||||
$this->maximumMetaRefreshCount = 0;
|
||||
$this->drupalGet('test-meta-refresh');
|
||||
$this->assertNotEmpty($this->cssSelect('meta[http-equiv="refresh"]'));
|
||||
// Allow one redirect to happen.
|
||||
$this->maximumMetaRefreshCount = 1;
|
||||
$this->checkForMetaRefresh();
|
||||
// Check that we are now on the test page.
|
||||
$this->assertSession()->pageTextContains('Test page text.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1267,13 +1267,13 @@ abstract class BrowserTestBase extends TestCase {
|
|||
* Checks for meta refresh tag and if found call drupalGet() recursively.
|
||||
*
|
||||
* This function looks for the http-equiv attribute to be set to "Refresh" and
|
||||
* is case-sensitive.
|
||||
* is case-insensitive.
|
||||
*
|
||||
* @return string|false
|
||||
* Either the new page content or FALSE.
|
||||
*/
|
||||
protected function checkForMetaRefresh() {
|
||||
$refresh = $this->cssSelect('meta[http-equiv="Refresh"]');
|
||||
$refresh = $this->cssSelect('meta[http-equiv="Refresh"], meta[http-equiv="refresh"]');
|
||||
if (!empty($refresh) && (!isset($this->maximumMetaRefreshCount) || $this->metaRefreshCount < $this->maximumMetaRefreshCount)) {
|
||||
// Parse the content attribute of the meta tag for the format:
|
||||
// "[delay]: URL=[page_to_redirect_to]".
|
||||
|
|
Loading…
Reference in New Issue