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