ActionsTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Render/Element/ActionsTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Render\Element;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\KernelTests\KernelTestBase;
class ActionsTest extends KernelTestBase implements FormInterface {
protected static $modules = [
'system',
];
public function getFormId() {
return __CLASS__;
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['key'] = [
'#type' => 'submit',
'#value' => 'Key',
'#dropbutton' => 'submit',
'#cache' => [
'tags' => [
'foo',
],
],
'#attached' => [
'library' => [
'system/base',
],
],
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => 'Save',
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
public function testDropbuttonWithBubbleableMetadata() {
$result = \Drupal::formBuilder()
->getForm($this);
\Drupal::service('renderer')
->renderRoot($result);
$this
->assertEquals([
'system/base',
'core/drupal.dropbutton',
], $result['#attached']['library']);
$this
->assertEquals([
'foo',
], $result['#cache']['tags']);
}
}