Version 1
[yaffs-website] / web / core / modules / views / tests / src / Functional / Handler / FieldDropButtonTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Handler;
4
5 use Drupal\Tests\views\Functional\ViewTestBase;
6
7 /**
8  * Tests the dropbutton field handler.
9  *
10  * @group views
11  * @see \Drupal\system\Plugin\views\field\Dropbutton
12  */
13 class FieldDropButtonTest extends ViewTestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['test_dropbutton'];
21
22   /**
23    * Modules to enable.
24    *
25    * @var array
26    */
27   public static $modules = ['node'];
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function setUp($import_test_views = TRUE) {
33     parent::setUp($import_test_views);
34
35     $admin_user = $this->drupalCreateUser(['access content overview', 'administer nodes', 'bypass node access']);
36     $this->drupalLogin($admin_user);
37   }
38
39   /**
40    * Tests dropbutton field.
41    */
42   public function testDropbutton() {
43     // Create some test nodes.
44     $nodes = [];
45     for ($i = 0; $i < 5; $i++) {
46       $nodes[] = $this->drupalCreateNode();
47     }
48
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.');
55     }
56
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');
64   }
65
66 }