Commit 4416f7bb authored by catch's avatar catch

Issue #2870453 by Lendude, michielnugter, dawehner: Convert web tests to...

Issue #2870453 by Lendude, michielnugter, dawehner: Convert web tests to browser tests for node module
parent 96343716
......@@ -3,7 +3,7 @@
namespace Drupal\Tests\content_translation\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Tests\NodeTestBase;
use Drupal\Tests\node\Functional\NodeTestBase;
use Drupal\user\Entity\Role;
/**
......
......@@ -2,8 +2,13 @@
namespace Drupal\node\Tests;
@trigger_error('\Drupal\Tests\node\Functional\AssertButtonsTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\node\Functional\AssertButtonsTrait', E_USER_DEPRECATED);
/**
* Asserts that buttons are present on a page.
*
* @deprecated Scheduled for removal before Drupal 9.0.0.
* Use \Drupal\Tests\node\Functional\AssertButtonsTrait instead.
*/
trait AssertButtonsTrait {
......
......@@ -2,11 +2,16 @@
namespace Drupal\node\Tests\Views;
@trigger_error('\Drupal\node\Tests\Views\NodeTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\node\Functional\Views\NodeTestBase', E_USER_DEPRECATED);
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Base class for all node tests.
*
* @deprecated Scheduled for removal before Drupal 9.0.0.
* Use \Drupal\Tests\node\Functional\Views\NodeTestBase instead.
*/
abstract class NodeTestBase extends ViewTestBase {
......
<?php
namespace Drupal\Tests\node\Functional;
/**
* Asserts that buttons are present on a page.
*/
trait AssertButtonsTrait {
/**
* Assert method to verify the buttons in the dropdown element.
*
* @param array $buttons
* A collection of buttons to assert for on the page.
* @param bool $dropbutton
* Whether to check if the buttons are in a dropbutton widget or not.
*/
public function assertButtons(array $buttons, $dropbutton = TRUE) {
// Try to find a Save button.
$save_button = $this->xpath('//input[@type="submit"][@value="Save"]');
// Verify that the number of buttons passed as parameters is
// available in the dropbutton widget.
if ($dropbutton) {
$i = 0;
$count = count($buttons);
// Assert there is no save button.
$this->assertTrue(empty($save_button));
// Dropbutton elements.
/** @var \Behat\Mink\Element\NodeElement[] $elements */
$elements = $this->xpath('//div[@class="dropbutton-wrapper"]//input[@type="submit"]');
$this->assertEqual($count, count($elements));
foreach ($elements as $element) {
$value = $element->getValue() ?: '';
$this->assertEqual($buttons[$i], $value);
$i++;
}
}
else {
// Assert there is a save button.
$this->assertTrue(!empty($save_button));
$this->assertNoRaw('dropbutton-wrapper');
}
}
}
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Url;
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
/**
* Tests the node access automatic cacheability bubbling logic.
......@@ -13,6 +14,8 @@
*/
class NodeAccessAutoBubblingTest extends NodeTestBase {
use AssertPageCacheContextsAndTagsTrait;
/**
* Modules to enable.
*
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\node\Entity\NodeType;
......@@ -198,7 +198,7 @@ protected function assertTaxonomyPage($is_admin) {
$this->nidsVisible = [];
foreach ($this->xpath("//a[text()='Read more']") as $link) {
// See also testTranslationRendering() in NodeTranslationUITest.
$this->assertTrue(preg_match('|node/(\d+)$|', (string) $link['href'], $matches), 'Read more points to a node');
$this->assertTrue(preg_match('|node/(\d+)$|', $link->getAttribute('href'), $matches), 'Read more points to a node');
$this->nidsVisible[$matches[1]] = TRUE;
}
foreach ($this->nodesByUser as $uid => $data) {
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\comment\CommentInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\Entity\Comment;
use Drupal\Tests\BrowserTestBase;
/**
* Tests access controlled node views have the right amount of comment pages.
*
* @group node
*/
class NodeAccessPagerTest extends WebTestBase {
class NodeAccessPagerTest extends BrowserTestBase {
use CommentTestTrait;
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\node\Entity\NodeType;
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\user\RoleInterface;
......@@ -134,7 +134,7 @@ public function testContentAdminPages() {
$this->assertLinkByHref('node/' . $node->id() . '/edit');
$this->assertLinkByHref('node/' . $node->id() . '/delete');
// Verify that we can see the content type label.
$this->assertEqual(trim((string) $node_type_labels[$delta]), $node->type->entity->label());
$this->assertEqual(trim($node_type_labels[$delta]->getText()), $node->type->entity->label());
$delta++;
}
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\block\Entity\Block;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\node\NodeInterface;
use Drupal\user\Entity\User;
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Cache\Cache;
use Drupal\Tests\EntityViewTrait;
/**
* Tests changing view modes for nodes.
......@@ -11,6 +12,8 @@
*/
class NodeEntityViewModeAlterTest extends NodeTestBase {
use EntityViewTrait;
/**
* Enable dummy module that implements hook_ENTITY_TYPE_view() for nodes.
*/
......@@ -43,7 +46,7 @@ public function testNodeViewModeChange() {
$this->assertNoText('Data that should appear only in the body for the node.', 'Body text not present');
// Test that the correct build mode has been set.
$build = $this->drupalBuildEntityView($node);
$build = $this->buildEntityView($node);
$this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.');
}
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\BrowserTestBase;
/**
* Tests multilingual support for fields.
*
* @group node
*/
class NodeFieldMultilingualTest extends WebTestBase {
class NodeFieldMultilingualTest extends BrowserTestBase {
/**
* Modules to enable.
......@@ -123,7 +123,7 @@ public function testMultilingualDisplaySettings() {
':node-class' => ' node ',
':content-class' => 'node__content',
]);
$this->assertEqual(current($body), $node->body->value, 'Node body found.');
$this->assertEqual($body[0]->getText(), $node->body->value, 'Node body found.');
}
}
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
/**
* Tests all the different buttons on the node form.
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
/**
* Tests that node access queries are properly altered by the node module.
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
/**
* Tests user permissions for node revisions.
......@@ -9,6 +11,8 @@
*/
class NodeRevisionPermissionsTest extends NodeTestBase {
use GeneratePermutationsTrait;
/**
* The node revisions.
*
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
/**
* Tests if the syndicate block is available.
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Component\Utility\Html;
......@@ -56,15 +56,15 @@ public function testNodeTitle() {
// Test <title> tag.
$this->drupalGet('node/' . $node->id());
$xpath = '//title';
$this->assertEqual(current($this->xpath($xpath)), $node->label() . ' | Drupal', 'Page title is equal to node title.', 'Node');
$this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label() . ' | Drupal', 'Page title is equal to node title.', 'Node');
// Test breadcrumb in comment preview.
$this->drupalGet('comment/reply/node/' . $node->id() . '/comment');
$xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a';
$this->assertEqual(current($this->xpath($xpath)), $node->label(), 'Node breadcrumb is equal to node title.', 'Node');
$this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label(), 'Node breadcrumb is equal to node title.', 'Node');
// Test node title in comment preview.
$this->assertEqual(current($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', [':node-class' => ' node--type-' . $node->bundle() . ' '])), $node->label(), 'Node preview title is equal to node title.', 'Node');
$this->assertEqual($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', [':node-class' => ' node--type-' . $node->bundle() . ' '])[0]->getText(), $node->label(), 'Node preview title is equal to node title.', 'Node');
// Test node title is clickable on teaser list (/node).
$this->drupalGet('node');
......@@ -92,11 +92,11 @@ public function testNodeTitle() {
// the page.
$edge_case_title_escaped = Html::escape($edge_case_title);
$this->drupalGet('node/' . $node->id());
$this->assertTitle($edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node');
$this->assertRaw('<title>' . $edge_case_title_escaped . ' | Drupal</title>', 'Page title is equal to article\'s "title".', 'Node');
// Test that the title appears as <title> when reloading the node page.
$this->drupalGet('node/' . $node->id());
$this->assertTitle($edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node');
$this->assertRaw('<title>' . $edge_case_title_escaped . ' | Drupal</title>', 'Page title is equal to article\'s "title".', 'Node');
}
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Component\Utility\Html;
......@@ -11,6 +11,7 @@
* @group node
*/
class NodeTitleXSSTest extends NodeTestBase {
/**
* Tests XSS functionality with a node entity.
*/
......@@ -32,7 +33,7 @@ public function testNodeTitleXSS() {
$this->drupalGet('node/' . $node->id());
// Titles should be escaped.
$this->assertTitle(Html::escape($title) . ' | Drupal', 'Title is displayed when viewing a node.');
$this->assertRaw('<title>' . Html::escape($title) . ' | Drupal</title>', 'Title is displayed when viewing a node.');
$this->assertNoRaw($xss, 'Harmful tags are escaped when viewing a node.');
$this->drupalGet('node/' . $node->id() . '/edit');
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Entity\EntityInterface;
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
......@@ -82,7 +82,7 @@ public function testPublishedStatusNoFields() {
// Add a node.
$default_langcode = $this->langcodes[0];
$values[$default_langcode] = ['title' => [['value' => $this->randomMachineName()]]];
$entity_id = $this->createEntity($values[$default_langcode], $default_langcode);
$this->entityId = $this->createEntity($values[$default_langcode], $default_langcode);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
......@@ -327,7 +327,7 @@ public function testTranslationRendering() {
}
$pattern = '|^' . $expected_href . '$|';
foreach ($this->xpath("//a[text()='Read more']") as $link) {
if (preg_match($pattern, (string) $link['href'], $matches) == TRUE) {
if (preg_match($pattern, $link->getAttribute('href'), $matches) == TRUE) {
$num_match_found++;
}
}
......@@ -349,7 +349,7 @@ public function testTranslationRendering() {
}
$pattern = '|^' . $expected_href . '$|';
foreach ($this->xpath("//a[text()='Add new comment']") as $link) {
if (preg_match($pattern, (string) $link['href'], $matches) == TRUE) {
if (preg_match($pattern, $link->getAttribute('href'), $matches) == TRUE) {
$num_match_found++;
}
}
......
<?php
namespace Drupal\node\Tests;
namespace Drupal\Tests\node\Functional;
use Drupal\Component\Utility\Html;
......@@ -21,7 +21,7 @@ public function testHtmlHeadLinks() {
$this->drupalGet($node->urlInfo());
$result = $this->xpath('//link[@rel = "canonical"]');
$this->assertEqual($result[0]['href'], $node->url());
$this->assertEqual($result[0]->getAttribute('href'), $node->url());
// Link relations are checked for access for anonymous users.
$result = $this->xpath('//link[@rel = "version-history"]');
......@@ -34,14 +34,14 @@ public function testHtmlHeadLinks() {
$this->drupalGet($node->urlInfo());
$result = $this->xpath('//link[@rel = "canonical"]');
$this->assertEqual($result[0]['href'], $node->url());
$this->assertEqual($result[0]->getAttribute('href'), $node->url());
// Link relations are present regardless of access for authenticated users.
$result = $this->xpath('//link[@rel = "version-history"]');
$this->assertEqual($result[0]['href'], $node->url('version-history'));
$this->assertEqual($result[0]->getAttribute('href'), $node->url('version-history'));
$result = $this->xpath('//link[@rel = "edit-form"]');
$this->assertEqual($result[0]['href'], $node->url('edit-form'));
$this->assertEqual($result[0]->getAttribute('href'), $node->url('edit-form'));
// Give anonymous users access to edit the node. Do this through the UI to
// ensure caches are handled properly.
......@@ -56,13 +56,13 @@ public function testHtmlHeadLinks() {
// version-history link.
$this->drupalGet($node->urlInfo());
$result = $this->xpath('//link[@rel = "canonical"]');
$this->assertEqual($result[0]['href'], $node->url());
$this->assertEqual($result[0]->getAttribute('href'), $node->url());
$result = $this->xpath('//link[@rel = "version-history"]');
$this->assertFalse($result, 'Version history not present for anonymous users without access.');
$result = $this->xpath('//link[@rel = "edit-form"]');
$this->assertEqual($result[0]['href'], $node->url('edit-form'));
$this->assertEqual($result[0]->getAttribute('href'), $node->url('edit-form'));
}
/**
......@@ -79,7 +79,7 @@ public function testLinkHeader() {
$this->drupalGet($node->urlInfo());
$links = explode(',', $this->drupalGetHeader('Link'));
$links = $this->drupalGetHeaders()['Link'];
$this->assertEqual($links, $expected);
}
......@@ -92,7 +92,7 @@ public function testMultiByteUtf8() {
$node = $this->drupalCreateNode(['title' => $title]);
$this->drupalGet($node->urlInfo());
$result = $this->xpath('//span[contains(@class, "field--name-title")]');
$this->assertEqual((string) $result[0], $title, 'The passed title was returned.');
$this->assertEqual($result[0]->getText(), $title, 'The passed title was returned.');
}
}
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\node\Entity\Node;
......@@ -41,8 +41,8 @@ class BulkFormAccessTest extends NodeTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create Article node type.
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\language\Entity\ConfigurableLanguage;
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\node\Entity\NodeType;
......@@ -31,8 +31,11 @@ class FilterNodeAccessTest extends NodeTestBase {
*/
public static $testViews = ['test_filter_node_access'];
protected function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\views\Views;
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\AssertViewsCacheTagsTrait;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
......@@ -39,8 +39,11 @@ class FrontPageTest extends ViewTestBase {
*/
public static $modules = ['node', 'contextual'];
protected function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->nodeStorage = $this->container->get('entity.manager')
->getStorage('node');
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\language\Entity\ConfigurableLanguage;
......@@ -30,8 +30,11 @@ class NodeFieldFilterTest extends NodeTestBase {
*/
public $nodeTitles = [];
public function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create Page content type.
if ($this->profile != 'standard') {
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
/**
* Tests the node integration into views.
......@@ -59,7 +59,7 @@ protected function assertNids(array $expected_nids = []) {
$result = $this->xpath('//span[@class="field-content"]');
$nids = [];
foreach ($result as $element) {
$nids[] = (int) $element;
$nids[] = (int) $element->getText();
}
$this->assertEqual($nids, $expected_nids);
}
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -38,7 +38,7 @@ class NodeLanguageTest extends NodeTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp($import_test_views = TRUE) {
parent::setUp(FALSE);
// Create Page content type.
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\views\Tests\Wizard\WizardTestBase;
use Drupal\Tests\views\Functional\Wizard\WizardTestBase;
use Drupal\views\Views;
/**
......
<?php
namespace Drupal\Tests\node\Functional\Views;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Base class for all node Views tests.
*/
abstract class NodeTestBase extends ViewTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node_test_views'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), ['node_test_views']);
}
}
}
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
use Drupal\views\Views;
......@@ -32,8 +32,11 @@ class PathPluginTest extends NodeTestBase {
*/
protected $nodes;
protected function setUp() {
parent::setUp();
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->drupalCreateContentType(['type' => 'article']);
......
<?php
namespace Drupal\node\Tests\Views;
namespace Drupal\Tests\node\Functional\Views;
/**
* Tests the different revision link handlers.
......