drupalPlaceBlock('local_tasks_block'); } /** * Test \Drupal\simpletest\WebTestBase::getAbsoluteUrl(). */ public function testGetAbsoluteUrl() { $url = 'user/login'; $this->drupalGet($url); $absolute = \Drupal::url('user.login', [], ['absolute' => TRUE]); $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.'); $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.'); $this->drupalPostForm(NULL, [], t('Log in')); $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.'); $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.'); $this->clickLink('Create new account'); $absolute = \Drupal::url('user.register', [], ['absolute' => TRUE]); $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.'); $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.'); } /** * Tests XPath escaping. */ public function testXPathEscaping() { $testpage = <<< EOF
A "weird" link, just to bother the dumb "XPath 1.0" A second "even more weird" link, in memory of George O'Malley A \$third$ link, so weird it's worth $1 million A fourth link, containing alternative \\1 regex backreferences \\2 EOF; $this->setRawContent($testpage); // Matches the first link. $urls = $this->xpath('//a[text()=:text]', [':text' => 'A "weird" link, just to bother the dumb "XPath 1.0"']); $this->assertEqual($urls[0]['href'], 'link1', 'Match with quotes.'); $urls = $this->xpath('//a[text()=:text]', [':text' => 'A second "even more weird" link, in memory of George O\'Malley']); $this->assertEqual($urls[0]['href'], 'link2', 'Match with mixed single and double quotes.'); $urls = $this->xpath('//a[text()=:text]', [':text' => 'A $third$ link, so weird it\'s worth $1 million']); $this->assertEqual($urls[0]['href'], 'link3', 'Match with a regular expression back reference symbol (dollar sign).'); $urls = $this->xpath('//a[text()=:text]', [':text' => 'A fourth link, containing alternative \\1 regex backreferences \\2']); $this->assertEqual($urls[0]['href'], 'link4', 'Match with another regular expression back reference symbol (double backslash).'); } /** * Tests that cookies set during a request are available for testing. */ public function testCookies() { // Check that the $this->cookies property is populated when a user logs in. $user = $this->drupalCreateUser(); $edit = ['name' => $user->getUsername(), 'pass' => $user->pass_raw]; $this->drupalPostForm('