comparison core/modules/simpletest/src/Tests/BrowserTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\simpletest\Tests; 3 namespace Drupal\simpletest\Tests;
4 4
5 use Drupal\Core\Url;
5 use Drupal\simpletest\WebTestBase; 6 use Drupal\simpletest\WebTestBase;
6 7
7 /** 8 /**
8 * Tests the internal browser of the testing framework. 9 * Tests the internal browser of the testing framework.
9 * 10 *
10 * @group simpletest 11 * @group simpletest
12 * @group WebTestBase
11 */ 13 */
12 class BrowserTest extends WebTestBase { 14 class BrowserTest extends WebTestBase {
13 15
14 /** 16 /**
15 * A flag indicating whether a cookie has been set in a test. 17 * A flag indicating whether a cookie has been set in a test.
39 */ 41 */
40 public function testGetAbsoluteUrl() { 42 public function testGetAbsoluteUrl() {
41 $url = 'user/login'; 43 $url = 'user/login';
42 44
43 $this->drupalGet($url); 45 $this->drupalGet($url);
44 $absolute = \Drupal::url('user.login', [], ['absolute' => TRUE]); 46 $absolute = Url::fromRoute('user.login', [], ['absolute' => TRUE])->toString();
45 $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.'); 47 $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.');
46 $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.'); 48 $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.');
47 49
48 $this->drupalPostForm(NULL, [], t('Log in')); 50 $this->drupalPostForm(NULL, [], t('Log in'));
49 $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.'); 51 $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.');
50 $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.'); 52 $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.');
51 53
52 $this->clickLink('Create new account'); 54 $this->clickLink('Create new account');
53 $absolute = \Drupal::url('user.register', [], ['absolute' => TRUE]); 55 $absolute = Url::fromRoute('user.register', [], ['absolute' => TRUE])->toString();
54 $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.'); 56 $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.');
55 $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.'); 57 $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.');
56 } 58 }
57 59
58 /** 60 /**
89 * Tests that cookies set during a request are available for testing. 91 * Tests that cookies set during a request are available for testing.
90 */ 92 */
91 public function testCookies() { 93 public function testCookies() {
92 // Check that the $this->cookies property is populated when a user logs in. 94 // Check that the $this->cookies property is populated when a user logs in.
93 $user = $this->drupalCreateUser(); 95 $user = $this->drupalCreateUser();
94 $edit = ['name' => $user->getUsername(), 'pass' => $user->pass_raw]; 96 $edit = ['name' => $user->getAccountName(), 'pass' => $user->pass_raw];
95 $this->drupalPostForm('<front>', $edit, t('Log in')); 97 $this->drupalPostForm('<front>', $edit, t('Log in'));
96 $this->assertEqual(count($this->cookies), 1, 'A cookie is set when the user logs in.'); 98 $this->assertEqual(count($this->cookies), 1, 'A cookie is set when the user logs in.');
97 99
98 // Check that the name and value of the cookie match the request data. 100 // Check that the name and value of the cookie match the request data.
99 $cookie_header = $this->drupalGetHeader('set-cookie', TRUE); 101 $cookie_header = $this->drupalGetHeader('set-cookie', TRUE);