AssertButtonsTrait.php 1.7 KB

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