NodeViewTest.php in Drupal 8
File
core/modules/node/tests/src/Functional/NodeViewTest.php
View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\Component\Utility\Html;
class NodeViewTest extends NodeTestBase {
protected $defaultTheme = 'classy';
public function testHtmlHeadLinks() {
$node = $this
->drupalCreateNode();
$this
->drupalGet($node
->toUrl());
$result = $this
->xpath('//link[@rel = "canonical"]');
$this
->assertEqual($result[0]
->getAttribute('href'), $node
->toUrl()
->setAbsolute()
->toString());
$result = $this
->xpath('//link[@rel = "version-history"]');
$this
->assertEmpty($result, 'Version history not present for anonymous users without access.');
$result = $this
->xpath('//link[@rel = "edit-form"]');
$this
->assertEmpty($result, 'Edit form not present for anonymous users without access.');
$this
->drupalLogin($this
->createUser([
'access content',
]));
$this
->drupalGet($node
->toUrl());
$result = $this
->xpath('//link[@rel = "canonical"]');
$this
->assertEqual($result[0]
->getAttribute('href'), $node
->toUrl()
->setAbsolute()
->toString());
$result = $this
->xpath('//link[@rel = "version-history"]');
$this
->assertEqual($result[0]
->getAttribute('href'), $node
->toUrl('version-history')
->setAbsolute()
->toString());
$result = $this
->xpath('//link[@rel = "edit-form"]');
$this
->assertEqual($result[0]
->getAttribute('href'), $node
->toUrl('edit-form')
->setAbsolute()
->toString());
$this
->drupalLogin($this->rootUser);
$edit = [
'anonymous[edit own ' . $node
->bundle() . ' content]' => TRUE,
];
$this
->drupalPostForm('admin/people/permissions', $edit, 'Save permissions');
$this
->drupalLogout();
$this
->drupalGet($node
->toUrl());
$result = $this
->xpath('//link[@rel = "canonical"]');
$this
->assertEqual($result[0]
->getAttribute('href'), $node
->toUrl()
->setAbsolute()
->toString());
$result = $this
->xpath('//link[@rel = "version-history"]');
$this
->assertEmpty($result, 'Version history not present for anonymous users without access.');
$result = $this
->xpath('//link[@rel = "edit-form"]');
$this
->assertEqual($result[0]
->getAttribute('href'), $node
->toUrl('edit-form')
->setAbsolute()
->toString());
}
public function testLinkHeader() {
$node = $this
->drupalCreateNode();
$expected = [
'<' . Html::escape($node
->toUrl('canonical')
->setAbsolute()
->toString()) . '>; rel="canonical"',
'<' . Html::escape($node
->toUrl('canonical')
->setAbsolute()
->toString(), [
'alias' => TRUE,
]) . '>; rel="shortlink"',
'<' . Html::escape($node
->toUrl('revision')
->setAbsolute()
->toString()) . '>; rel="revision"',
];
$this
->drupalGet($node
->toUrl());
$links = $this
->getSession()
->getResponseHeaders()['Link'];
$this
->assertEqual($links, $expected);
}
public function testMultiByteUtf8() {
$title = '🐝';
$this
->assertTrue(mb_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.');
$node = $this
->drupalCreateNode([
'title' => $title,
]);
$this
->drupalGet($node
->toUrl());
$result = $this
->xpath('//span[contains(@class, "field--name-title")]');
$this
->assertEqual($result[0]
->getText(), $title, 'The passed title was returned.');
}
}