function ArgumentDefaultTest::testArgumentDefaultNode

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultNode()
  2. 10 core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultNode()
  3. 11.x core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultNode()

Tests node default argument.

File

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

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,
    ]);
    $this->drupalGet('node/' . $node1->id());
    $this->assertSession()
        ->elementTextContains('xpath', '//*[@id="block-' . $id . '"]', $node1->getTitle());
    $this->drupalGet('node/' . $node2->id());
    $this->assertSession()
        ->elementTextContains('xpath', '//*[@id="block-' . $id . '"]', $node2->getTitle());
}

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