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