trait AssertButtonsTrait

Same name in other branches
  1. 8.9.x core/modules/node/src/Tests/AssertButtonsTrait.php \Drupal\node\Tests\AssertButtonsTrait
  2. 8.9.x core/modules/node/tests/src/Functional/AssertButtonsTrait.php \Drupal\Tests\node\Functional\AssertButtonsTrait

Asserts that buttons are present on a page.

Hierarchy

File

core/modules/node/tests/src/Functional/AssertButtonsTrait.php, line 10

Namespace

Drupal\Tests\node\Functional
View source
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) {
            $count = count($buttons);
            // Assert there is no save button.
            $this->assertSession()
                ->buttonNotExists('Save');
            // Dropbutton elements.
            $this->assertSession()
                ->elementsCount('xpath', '//div[@class="dropbutton-wrapper"]//input[@type="submit"]', $count);
            for ($i = 1; $i++; $i <= $count) {
                $this->assertSession()
                    ->elementTextEquals('xpath', "(//div[@class='dropbutton-wrapper']//input[@type='submit'])[{$i}]", $buttons[$i - 1]);
            }
        }
        else {
            // Assert there is a save button.
            $this->assertSession()
                ->buttonExists('Save');
            $this->assertSession()
                ->responseNotContains('dropbutton-wrapper');
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
AssertButtonsTrait::assertButtons public function Assert method to verify the buttons in the dropdown element.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.