public function SimpleTestBrowserTest::testInternalBrowser in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php \Drupal\simpletest\Tests\SimpleTestBrowserTest::testInternalBrowser()
Test the internal browsers functionality.
File
- core/
modules/ simpletest/ src/ Tests/ SimpleTestBrowserTest.php, line 36 - Contains \Drupal\simpletest\Tests\SimpleTestBrowserTest.
Class
- SimpleTestBrowserTest
- Tests the Simpletest UI internal browser.
Namespace
Drupal\simpletest\TestsCode
public function testInternalBrowser() {
// Retrieve the test page and check its title and headers.
$this
->drupalGet('test-page');
$this
->assertTrue($this
->drupalGetHeader('Date'), 'An HTTP header was received.');
$this
->assertTitle(t('Test page | @site-name', array(
'@site-name' => $this
->config('system.site')
->get('name'),
)));
$this
->assertNoTitle('Foo');
$old_user_id = $this->container
->get('current_user')
->id();
$user = $this
->drupalCreateUser();
$this
->drupalLogin($user);
// Check that current user service updated.
$this
->assertNotEqual($old_user_id, $this->container
->get('current_user')
->id(), 'Current user service updated.');
$headers = $this
->drupalGetHeaders(TRUE);
$this
->assertEqual(count($headers), 2, 'There was one intermediate request.');
$this
->assertTrue(strpos($headers[0][':status'], '303') !== FALSE, 'Intermediate response code was 303.');
$this
->assertFalse(empty($headers[0]['location']), 'Intermediate request contained a Location header.');
$this
->assertEqual($this
->getUrl(), $headers[0]['location'], 'HTTP redirect was followed');
$this
->assertFalse($this
->drupalGetHeader('Location'), 'Headers from intermediate request were reset.');
$this
->assertResponse(200, 'Response code from intermediate request was reset.');
$this
->drupalLogout();
// Check that current user service updated to anonymous user.
$this
->assertEqual(0, $this->container
->get('current_user')
->id(), 'Current user service updated.');
// Test the maximum redirection option.
$this->maximumRedirects = 1;
$edit = array(
'name' => $user
->getUsername(),
'pass' => $user->pass_raw,
);
$this
->drupalPostForm('user/login', $edit, t('Log in'), array(
'query' => array(
'destination' => 'user/logout',
),
));
$headers = $this
->drupalGetHeaders(TRUE);
$this
->assertEqual(count($headers), 2, 'Simpletest stopped following redirects after the first one.');
// Remove the Simpletest private key file so we can test the protection
// against requests that forge a valid testing user agent to gain access
// to the installer.
// @see drupal_valid_test_ua()
// Not using File API; a potential error must trigger a PHP warning.
unlink($this->siteDirectory . '/.htkey');
$this
->drupalGet(Url::fromUri('base:core/install.php', array(
'external' => TRUE,
'absolute' => TRUE,
))
->toString());
$this
->assertResponse(403, 'Cannot access install.php.');
}