3 namespace Drupal\Tests\node\Functional;
6 * Asserts that buttons are present on a page.
8 trait AssertButtonsTrait {
11 * Assert method to verify the buttons in the dropdown element.
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.
18 public function assertButtons(array $buttons, $dropbutton = TRUE) {
20 // Try to find a Save button.
21 $save_button = $this->xpath('//input[@type="submit"][@value="Save"]');
23 // Verify that the number of buttons passed as parameters is
24 // available in the dropbutton widget.
27 $count = count($buttons);
29 // Assert there is no save button.
30 $this->assertTrue(empty($save_button));
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);
43 // Assert there is a save button.
44 $this->assertTrue(!empty($save_button));
45 $this->assertNoRaw('dropbutton-wrapper');