NodeLinksTest.php

Same filename in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeLinksTest.php
  2. 8.9.x core/modules/node/tests/src/Functional/NodeLinksTest.php
  3. 10 core/modules/node/tests/src/Functional/NodeLinksTest.php

Namespace

Drupal\Tests\node\Functional

File

core/modules/node/tests/src/Functional/NodeLinksTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\node\Functional;

use Drupal\node\NodeInterface;

/**
 * Tests the output of node links (read more, add new comment, etc).
 *
 * @group node
 */
class NodeLinksTest extends NodeTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'views',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests that the links can be hidden in the view display settings.
     */
    public function testHideLinks() : void {
        $node = $this->drupalCreateNode([
            'type' => 'article',
            'promote' => NodeInterface::PROMOTED,
        ]);
        // Links are displayed by default.
        $this->drupalGet('node');
        $this->assertSession()
            ->pageTextContains($node->getTitle());
        $this->assertSession()
            ->linkExists('Read more');
        // Hide links.
        \Drupal::service('entity_display.repository')->getViewDisplay('node', 'article', 'teaser')
            ->removeComponent('links')
            ->save();
        $this->drupalGet('node');
        $this->assertSession()
            ->pageTextContains($node->getTitle());
        $this->assertSession()
            ->linkNotExists('Read more');
    }

}

Classes

Title Deprecated Summary
NodeLinksTest Tests the output of node links (read more, add new comment, etc).

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.