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