3 namespace Drupal\Tests\views\Functional\Handler;
5 use Drupal\Tests\views\Functional\ViewTestBase;
8 * Tests the dropbutton field handler.
11 * @see \Drupal\system\Plugin\views\field\Dropbutton
13 class FieldDropButtonTest extends ViewTestBase {
16 * Views used by this test.
20 public static $testViews = ['test_dropbutton'];
27 public static $modules = ['node'];
32 protected function setUp($import_test_views = TRUE) {
33 parent::setUp($import_test_views);
35 $admin_user = $this->drupalCreateUser(['access content overview', 'administer nodes', 'bypass node access']);
36 $this->drupalLogin($admin_user);
40 * Tests dropbutton field.
42 public function testDropbutton() {
43 // Create some test nodes.
45 for ($i = 0; $i < 5; $i++) {
46 $nodes[] = $this->drupalCreateNode();
49 $this->drupalGet('test-dropbutton');
50 foreach ($nodes as $node) {
51 $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [':path' => '/node/' . $node->id(), ':title' => $node->label()]);
52 $this->assertEqual(count($result), 1, 'Just one node title link was found.');
53 $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', [':path' => '/node/' . $node->id(), ':title' => 'Custom Text']);
54 $this->assertEqual(count($result), 1, 'Just one custom link was found.');
57 // Check if the dropbutton.js library is available.
58 $this->drupalGet('admin/content');
59 $this->assertRaw('dropbutton.js');
60 // Check if the dropbutton.js library is available on a cached page to
61 // ensure that bubbleable metadata is not lost in the views render workflow.
62 $this->drupalGet('admin/content');
63 $this->assertRaw('dropbutton.js');