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