3 namespace Drupal\Tests\filter\Kernel;
5 use Drupal\Core\Form\FormInterface;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\filter\Entity\FilterFormat;
8 use Drupal\KernelTests\KernelTestBase;
9 use Drupal\user\Entity\Role;
10 use Drupal\user\Entity\User;
13 * Tests PathElement validation and conversion functionality.
17 class TextFormatElementFormTest extends KernelTestBase implements FormInterface {
22 * @var \Drupal\user\UserInterface
31 public static $modules = ['system', 'user', 'filter', 'filter_test', 'editor'];
36 protected function setUp() {
38 $this->installEntitySchema('user');
39 $this->installSchema('system', ['sequences']);
40 $this->installConfig(['filter', 'filter_test']);
41 // Filter tips link to the full-page.
42 \Drupal::service('router.builder')->rebuild();
43 /* @var \Drupal\Core\Render\ElementInfoManager $manager */
44 $manager = \Drupal::service('plugin.manager.element_info');
45 $manager->clearCachedDefinitions();
46 $manager->getDefinitions();
47 /* @var \Drupal\filter\FilterFormatInterface $filter_test_format */
48 $filter_test_format = FilterFormat::load('filter_test');
50 /* @var \Drupal\user\RoleInterface $role */
51 $role = Role::create([
55 $role->grantPermission($filter_test_format->getPermissionName());
57 $this->testUser = User::create([
59 'mail' => 'foobar@example.com',
61 $this->testUser->addRole($role->id());
62 $this->testUser->save();
63 \Drupal::service('current_user')->setAccount($this->testUser);
69 public function getFormId() {
70 return 'test_text_area_element';
76 public function buildForm(array $form, FormStateInterface $form_state) {
77 // A textformat field.
78 $form['textformat'] = [
79 '#type' => 'text_format',
82 '#base_type' => 'textfield',
84 '#default_value' => 'test value',
93 public function submitForm(array &$form, FormStateInterface $form_state) {}
96 * Form validation handler.
99 * An associative array containing the structure of the form.
100 * @param \Drupal\Core\Form\FormStateInterface $form_state
101 * The current state of the form.
103 public function validateForm(array &$form, FormStateInterface $form_state) {}
106 * Tests that values are returned.
108 public function testTextFormatElement() {
109 /* @var \Drupal\Core\Form\FormBuilder $form_builder */
110 $form_builder = $this->container->get('form_builder');
111 $form = $form_builder->getForm($this);
112 $output = $this->render($form);
113 $this->setRawContent($output);
114 $this->assertFieldByName('textformat[value]');
115 $this->assertRaw('<h4>Full HTML</h4>');
116 $this->assertRaw('<h4>Filtered HTML</h4>');
117 $this->assertRaw('<h4>Test format</h4>');
118 $this->assertNoPattern('|<h4[^>]*></h4>|', 'No empty H4 element found.');
124 protected function getUrl() {
125 // \Drupal\simpletest\AssertContentTrait needs this for ::assertFieldByName
127 return 'Internal rendering';