You are here

public function ArgumentDefaultTest::testArgumentDefaultNode in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultNode()

Test node default argument.

File

core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php, line 146

Class

ArgumentDefaultTest
Tests pluggable argument_default for views.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testArgumentDefaultNode() {

  // Create a user that has permission to place a view block.
  $permissions = [
    'administer views',
    'administer blocks',
    'bypass node access',
    'access user profiles',
    'view all revisions',
  ];
  $views_admin = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($views_admin);

  // Create nodes where should show themselves again as view block.
  $node_type = NodeType::create([
    'type' => 'page',
    'label' => 'Page',
  ]);
  $node_type
    ->save();
  $node1 = Node::create([
    'title' => 'Test node 1',
    'type' => 'page',
  ]);
  $node1
    ->save();
  $node2 = Node::create([
    'title' => 'Test node 2',
    'type' => 'page',
  ]);
  $node2
    ->save();

  // Place the block, visit the pages that display the block, and check that
  // the nodes we expect appear in the respective pages.
  $id = 'view-block-id';
  $this
    ->drupalPlaceBlock("views_block:test_argument_default_node-block_1", [
    'id' => $id,
  ]);
  $xpath = '//*[@id="block-' . $id . '"]';
  $this
    ->drupalGet('node/' . $node1
    ->id());
  $this
    ->assertStringContainsString($node1
    ->getTitle(), $this
    ->xpath($xpath)[0]
    ->getText());
  $this
    ->drupalGet('node/' . $node2
    ->id());
  $this
    ->assertStringContainsString($node2
    ->getTitle(), $this
    ->xpath($xpath)[0]
    ->getText());
}