diff --git a/core/modules/node/src/Tests/AssertButtonsTrait.php b/core/modules/node/src/Tests/AssertButtonsTrait.php index 58d484d9e4..512ea2a1d8 100644 --- a/core/modules/node/src/Tests/AssertButtonsTrait.php +++ b/core/modules/node/src/Tests/AssertButtonsTrait.php @@ -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 in Drupal 9.0.0. + * Use \Drupal\Tests\node\Functional\AssertButtonsTrait instead. */ trait AssertButtonsTrait { diff --git a/core/modules/node/src/Tests/AssertButtonsTrait.php b/core/modules/node/tests/src/Functional/AssertButtonsTrait.php similarity index 84% copy from core/modules/node/src/Tests/AssertButtonsTrait.php copy to core/modules/node/tests/src/Functional/AssertButtonsTrait.php index 58d484d9e4..bc2ef9078b 100644 --- a/core/modules/node/src/Tests/AssertButtonsTrait.php +++ b/core/modules/node/tests/src/Functional/AssertButtonsTrait.php @@ -1,6 +1,6 @@ xpath('//input[@type="submit"][@value="Save"]'); @@ -30,10 +30,11 @@ public function assertButtons($buttons, $dropbutton = TRUE) { $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 = isset($element['value']) ? (string) $element['value'] : ''; + $value = $element->getValue() ?: ''; $this->assertEqual($buttons[$i], $value); $i++; } diff --git a/core/modules/node/src/Tests/NodeAccessAutoBubblingTest.php b/core/modules/node/tests/src/Functional/NodeAccessAutoBubblingTest.php similarity index 92% rename from core/modules/node/src/Tests/NodeAccessAutoBubblingTest.php rename to core/modules/node/tests/src/Functional/NodeAccessAutoBubblingTest.php index 789818b408..6af8d8de66 100644 --- a/core/modules/node/src/Tests/NodeAccessAutoBubblingTest.php +++ b/core/modules/node/tests/src/Functional/NodeAccessAutoBubblingTest.php @@ -1,8 +1,9 @@ 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) { diff --git a/core/modules/node/src/Tests/NodeAccessPagerTest.php b/core/modules/node/tests/src/Functional/NodeAccessPagerTest.php similarity index 95% rename from core/modules/node/src/Tests/NodeAccessPagerTest.php rename to core/modules/node/tests/src/Functional/NodeAccessPagerTest.php index b4fe8302e9..ad6cc54944 100644 --- a/core/modules/node/src/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/tests/src/Functional/NodeAccessPagerTest.php @@ -1,18 +1,18 @@ 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++; } diff --git a/core/modules/node/src/Tests/NodeBlockFunctionalTest.php b/core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php similarity index 99% rename from core/modules/node/src/Tests/NodeBlockFunctionalTest.php rename to core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php index 5a2e40a30d..ad3613d74f 100644 --- a/core/modules/node/src/Tests/NodeBlockFunctionalTest.php +++ b/core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php @@ -1,6 +1,6 @@ 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.'); } diff --git a/core/modules/node/src/Tests/NodeFieldMultilingualTest.php b/core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php similarity index 95% rename from core/modules/node/src/Tests/NodeFieldMultilingualTest.php rename to core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php index edd01b2d00..771426d025 100644 --- a/core/modules/node/src/Tests/NodeFieldMultilingualTest.php +++ b/core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php @@ -1,19 +1,19 @@ ' 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.'); } } diff --git a/core/modules/node/src/Tests/NodeFormButtonsTest.php b/core/modules/node/tests/src/Functional/NodeFormButtonsTest.php similarity index 99% rename from core/modules/node/src/Tests/NodeFormButtonsTest.php rename to core/modules/node/tests/src/Functional/NodeFormButtonsTest.php index ed2bb8f7a4..546a6334ad 100644 --- a/core/modules/node/src/Tests/NodeFormButtonsTest.php +++ b/core/modules/node/tests/src/Functional/NodeFormButtonsTest.php @@ -1,6 +1,6 @@ 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($edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node'); // Test that the title appears as 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($edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node'); } diff --git a/core/modules/node/src/Tests/NodeTitleXSSTest.php b/core/modules/node/tests/src/Functional/NodeTitleXSSTest.php similarity index 89% rename from core/modules/node/src/Tests/NodeTitleXSSTest.php rename to core/modules/node/tests/src/Functional/NodeTitleXSSTest.php index c5bbe95d62..cbc9162f35 100644 --- a/core/modules/node/src/Tests/NodeTitleXSSTest.php +++ b/core/modules/node/tests/src/Functional/NodeTitleXSSTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\node\Tests; +namespace Drupal\Tests\node\Functional; use Drupal\Component\Utility\Html; @@ -32,7 +32,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(Html::escape($title) . ' | Drupal', 'Title is displayed when viewing a node.'); $this->assertNoRaw($xss, 'Harmful tags are escaped when viewing a node.'); $this->drupalGet('node/' . $node->id() . '/edit'); diff --git a/core/modules/node/src/Tests/NodeTranslationUITest.php b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php similarity index 98% rename from core/modules/node/src/Tests/NodeTranslationUITest.php rename to core/modules/node/tests/src/Functional/NodeTranslationUITest.php index a01c4d5c39..a8a74544ec 100644 --- a/core/modules/node/src/Tests/NodeTranslationUITest.php +++ b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php @@ -1,9 +1,9 @@ <?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++; } } diff --git a/core/modules/node/src/Tests/NodeViewTest.php b/core/modules/node/tests/src/Functional/NodeViewTest.php similarity index 81% rename from core/modules/node/src/Tests/NodeViewTest.php rename to core/modules/node/tests/src/Functional/NodeViewTest.php index a01cb25a57..b0eaa47f66 100644 --- a/core/modules/node/src/Tests/NodeViewTest.php +++ b/core/modules/node/tests/src/Functional/NodeViewTest.php @@ -1,6 +1,6 @@ <?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.'); } } diff --git a/core/modules/node/src/Tests/SummaryLengthTest.php b/core/modules/node/tests/src/Kernel/SummaryLengthTest.php similarity index 61% rename from core/modules/node/src/Tests/SummaryLengthTest.php rename to core/modules/node/tests/src/Kernel/SummaryLengthTest.php index e953882e41..65189608df 100644 --- a/core/modules/node/src/Tests/SummaryLengthTest.php +++ b/core/modules/node/tests/src/Kernel/SummaryLengthTest.php @@ -1,15 +1,82 @@ <?php -namespace Drupal\node\Tests; +namespace Drupal\Tests\node\Kernel; +use Drupal\Component\Utility\Unicode; +use Drupal\Core\Datetime\Entity\DateFormat; +use Drupal\KernelTests\KernelTestBase; use Drupal\node\Entity\Node; +use Drupal\simpletest\ContentTypeCreationTrait; +use Drupal\simpletest\NodeCreationTrait; +use Drupal\simpletest\UserCreationTrait; +use Drupal\Tests\EntityViewTrait; /** * Tests summary length. * * @group node */ -class SummaryLengthTest extends NodeTestBase { +class SummaryLengthTest extends KernelTestBase { + + use NodeCreationTrait { + getNodeByTitle as drupalGetNodeByTitle; + createNode as drupalCreateNode; + } + use UserCreationTrait { + createUser as drupalCreateUser; + createRole as drupalCreateRole; + createAdminRole as drupalCreateAdminRole; + } + use ContentTypeCreationTrait { + createContentType as drupalCreateContentType; + } + use EntityViewTrait { + buildEntityView as drupalBuildEntityView; + } + + /** + * {@inheritdoc} + */ + public static $modules = [ + 'node', + 'datetime', + 'user', + 'system', + 'filter', + 'field', + 'text', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installSchema('system', 'sequences'); + $this->installSchema('node', 'node_access'); + $this->installEntitySchema('user'); + $this->installEntitySchema('node'); + $this->installEntitySchema('date_format'); + $this->installConfig('filter'); + $this->installConfig('node'); + + // Create a node type. + $this->drupalCreateContentType([ + 'type' => 'page', + 'name' => 'Basic page', + 'display_submitted' => FALSE, + ]); + + DateFormat::create([ + 'id' => 'fallback', + 'label' => 'Fallback', + 'pattern' => 'Y-m-d', + ])->save(); + + // Enable multibyte support. + //Unicode::setStatus(Unicode::STATUS_MULTIBYTE); + } + /** * Tests the node summary length functionality. */