Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / node / tests / src / Functional / AssertButtonsTrait.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional;
4
5 /**
6  * Asserts that buttons are present on a page.
7  */
8 trait AssertButtonsTrait {
9
10   /**
11    * Assert method to verify the buttons in the dropdown element.
12    *
13    * @param array $buttons
14    *   A collection of buttons to assert for on the page.
15    * @param bool $dropbutton
16    *   Whether to check if the buttons are in a dropbutton widget or not.
17    */
18   public function assertButtons(array $buttons, $dropbutton = TRUE) {
19
20     // Try to find a Save button.
21     $save_button = $this->xpath('//input[@type="submit"][@value="Save"]');
22
23     // Verify that the number of buttons passed as parameters is
24     // available in the dropbutton widget.
25     if ($dropbutton) {
26       $i = 0;
27       $count = count($buttons);
28
29       // Assert there is no save button.
30       $this->assertTrue(empty($save_button));
31
32       // Dropbutton elements.
33       /** @var \Behat\Mink\Element\NodeElement[] $elements */
34       $elements = $this->xpath('//div[@class="dropbutton-wrapper"]//input[@type="submit"]');
35       $this->assertEqual($count, count($elements));
36       foreach ($elements as $element) {
37         $value = $element->getValue() ?: '';
38         $this->assertEqual($buttons[$i], $value);
39         $i++;
40       }
41     }
42     else {
43       // Assert there is a save button.
44       $this->assertTrue(!empty($save_button));
45       $this->assertNoRaw('dropbutton-wrapper');
46     }
47   }
48
49 }