Chris@0: drupalCreateNode(); Chris@0: Chris@18: $this->drupalGet($node->toUrl()); Chris@0: Chris@0: $result = $this->xpath('//link[@rel = "canonical"]'); Chris@18: $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString()); Chris@0: Chris@0: // Link relations are checked for access for anonymous users. Chris@0: $result = $this->xpath('//link[@rel = "version-history"]'); Chris@0: $this->assertFalse($result, 'Version history not present for anonymous users without access.'); Chris@0: Chris@0: $result = $this->xpath('//link[@rel = "edit-form"]'); Chris@0: $this->assertFalse($result, 'Edit form not present for anonymous users without access.'); Chris@0: Chris@0: $this->drupalLogin($this->createUser(['access content'])); Chris@18: $this->drupalGet($node->toUrl()); Chris@0: Chris@0: $result = $this->xpath('//link[@rel = "canonical"]'); Chris@18: $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString()); Chris@0: Chris@0: // Link relations are present regardless of access for authenticated users. Chris@0: $result = $this->xpath('//link[@rel = "version-history"]'); Chris@18: $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('version-history')->setAbsolute()->toString()); Chris@0: Chris@0: $result = $this->xpath('//link[@rel = "edit-form"]'); Chris@18: $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('edit-form')->setAbsolute()->toString()); Chris@0: Chris@0: // Give anonymous users access to edit the node. Do this through the UI to Chris@0: // ensure caches are handled properly. Chris@0: $this->drupalLogin($this->rootUser); Chris@0: $edit = [ Chris@17: 'anonymous[edit own ' . $node->bundle() . ' content]' => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/people/permissions', $edit, 'Save permissions'); Chris@0: $this->drupalLogout(); Chris@0: Chris@0: // Anonymous user's should now see the edit-form link but not the Chris@0: // version-history link. Chris@18: $this->drupalGet($node->toUrl()); Chris@0: $result = $this->xpath('//link[@rel = "canonical"]'); Chris@18: $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString()); Chris@0: Chris@0: $result = $this->xpath('//link[@rel = "version-history"]'); Chris@0: $this->assertFalse($result, 'Version history not present for anonymous users without access.'); Chris@0: Chris@0: $result = $this->xpath('//link[@rel = "edit-form"]'); Chris@18: $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('edit-form')->setAbsolute()->toString()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the Link header. Chris@0: */ Chris@0: public function testLinkHeader() { Chris@0: $node = $this->drupalCreateNode(); Chris@0: Chris@0: $expected = [ Chris@18: '<' . Html::escape($node->toUrl('canonical')->setAbsolute()->toString()) . '>; rel="canonical"', Chris@18: '<' . Html::escape($node->toUrl('canonical')->setAbsolute()->toString(), ['alias' => TRUE]) . '>; rel="shortlink"', Chris@18: '<' . Html::escape($node->toUrl('revision')->setAbsolute()->toString()) . '>; rel="revision"', Chris@0: ]; Chris@0: Chris@18: $this->drupalGet($node->toUrl()); Chris@0: Chris@0: $links = $this->drupalGetHeaders()['Link']; Chris@0: $this->assertEqual($links, $expected); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that we store and retrieve multi-byte UTF-8 characters correctly. Chris@0: */ Chris@0: public function testMultiByteUtf8() { Chris@0: $title = '🐝'; Chris@0: $this->assertTrue(mb_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.'); Chris@0: $node = $this->drupalCreateNode(['title' => $title]); Chris@18: $this->drupalGet($node->toUrl()); Chris@0: $result = $this->xpath('//span[contains(@class, "field--name-title")]'); Chris@0: $this->assertEqual($result[0]->getText(), $title, 'The passed title was returned.'); Chris@0: } Chris@0: Chris@0: }