ActionsTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Drupal\KernelTests\Core\Render\Element;
  3. use Drupal\Core\Form\FormInterface;
  4. use Drupal\Core\Form\FormStateInterface;
  5. use Drupal\KernelTests\KernelTestBase;
  6. /**
  7. * @coversDefaultClass \Drupal\Core\Render\Element\Actions
  8. * @group Render
  9. */
  10. class ActionsTest extends KernelTestBase implements FormInterface {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public static $modules = ['system'];
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function getFormId() {
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function buildForm(array $form, FormStateInterface $form_state) {
  24. $form['actions'] = ['#type' => 'actions'];
  25. $form['actions']['key'] = [
  26. '#type' => 'submit',
  27. '#value' => 'Key',
  28. '#dropbutton' => 'submit',
  29. '#cache' => [
  30. 'tags' => ['foo'],
  31. ],
  32. '#attached' => [
  33. 'library' => [
  34. 'system/base',
  35. ],
  36. ],
  37. ];
  38. $form['actions']['submit'] = [
  39. '#type' => 'submit',
  40. '#value' => 'Save',
  41. ];
  42. return $form;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function validateForm(array &$form, FormStateInterface $form_state) {
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function submitForm(array &$form, FormStateInterface $form_state) {
  53. }
  54. public function testDropbuttonWithBubbleableMetadata() {
  55. $result = \Drupal::formBuilder()->getForm($this);
  56. \Drupal::service('renderer')->renderRoot($result);
  57. $this->assertEquals(['system/base', 'core/drupal.dropbutton'], $result['#attached']['library']);
  58. $this->assertEquals(['foo'], $result['#cache']['tags']);
  59. }
  60. }