function FieldDropButtonTest::testDropbutton

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/Handler/FieldDropButtonTest.php \Drupal\Tests\views\Functional\Handler\FieldDropButtonTest::testDropbutton()
  2. 10 core/modules/views/tests/src/Functional/Handler/FieldDropButtonTest.php \Drupal\Tests\views\Functional\Handler\FieldDropButtonTest::testDropbutton()
  3. 11.x core/modules/views/tests/src/Functional/Handler/FieldDropButtonTest.php \Drupal\Tests\views\Functional\Handler\FieldDropButtonTest::testDropbutton()

Tests dropbutton field.

File

core/modules/views/tests/src/Functional/Handler/FieldDropButtonTest.php, line 51

Class

FieldDropButtonTest
Tests the dropbutton field handler.

Namespace

Drupal\Tests\views\Functional\Handler

Code

public function testDropbutton() {
    // Create some test nodes.
    $nodes = [];
    for ($i = 0; $i < 5; $i++) {
        $nodes[] = $this->drupalCreateNode();
    }
    $this->drupalGet('test-dropbutton');
    foreach ($nodes as $node) {
        $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [
            ':path' => '/node/' . $node->id(),
            ':title' => $node->label(),
        ]);
        $this->assertCount(1, $result, 'Just one node title link was found.');
        $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [
            ':path' => '/node/' . $node->id(),
            ':title' => 'Custom Text',
        ]);
        $this->assertCount(1, $result, 'Just one custom link was found.');
    }
    // Check if the dropbutton.js library is available.
    $this->drupalGet('admin/content');
    $this->assertRaw('dropbutton.js');
    // Check if the dropbutton.js library is available on a cached page to
    // ensure that bubbleable metadata is not lost in the views render workflow.
    $this->drupalGet('admin/content');
    $this->assertRaw('dropbutton.js');
}

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