AssertButtonsTrait.php 1.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

namespace Drupal\Tests\node\Functional;

/**
 * Asserts that buttons are present on a page.
 */
trait AssertButtonsTrait {

  /**
   * Assert method to verify the buttons in the dropdown element.
   *
   * @param array $buttons
   *   A collection of buttons to assert for on the page.
   * @param bool $dropbutton
   *   Whether to check if the buttons are in a dropbutton widget or not.
   */
  public function assertButtons(array $buttons, $dropbutton = TRUE) {
    // Verify that the number of buttons passed as parameters is
    // available in the dropbutton widget.
    if ($dropbutton) {
      $i = 0;
      $count = count($buttons);

      // Assert there is no save button.
26
      $this->assertSession()->buttonNotExists('Save');
27
28
29
30

      // Dropbutton elements.
      /** @var \Behat\Mink\Element\NodeElement[] $elements */
      $elements = $this->xpath('//div[@class="dropbutton-wrapper"]//input[@type="submit"]');
31
      $this->assertCount($count, $elements);
32
33
34
35
36
37
38
39
      foreach ($elements as $element) {
        $value = $element->getValue() ?: '';
        $this->assertEqual($buttons[$i], $value);
        $i++;
      }
    }
    else {
      // Assert there is a save button.
40
      $this->assertSession()->buttonExists('Save');
41
42
43
44
45
      $this->assertNoRaw('dropbutton-wrapper');
    }
  }

}