X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffilter%2Ftests%2Fsrc%2FKernel%2FTextFormatElementFormTest.php;fp=web%2Fcore%2Fmodules%2Ffilter%2Ftests%2Fsrc%2FKernel%2FTextFormatElementFormTest.php;h=8fca62e965b247f44f869935795c87e8c692c748;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/filter/tests/src/Kernel/TextFormatElementFormTest.php b/web/core/modules/filter/tests/src/Kernel/TextFormatElementFormTest.php new file mode 100644 index 000000000..8fca62e96 --- /dev/null +++ b/web/core/modules/filter/tests/src/Kernel/TextFormatElementFormTest.php @@ -0,0 +1,130 @@ +installEntitySchema('user'); + $this->installSchema('system', ['sequences']); + $this->installConfig(['filter', 'filter_test']); + // Filter tips link to the full-page. + \Drupal::service('router.builder')->rebuild(); + /* @var \Drupal\Core\Render\ElementInfoManager $manager */ + $manager = \Drupal::service('plugin.manager.element_info'); + $manager->clearCachedDefinitions(); + $manager->getDefinitions(); + /* @var \Drupal\filter\FilterFormatInterface $filter_test_format */ + $filter_test_format = FilterFormat::load('filter_test'); + + /* @var \Drupal\user\RoleInterface $role */ + $role = Role::create([ + 'id' => 'admin', + 'label' => 'admin', + ]); + $role->grantPermission($filter_test_format->getPermissionName()); + $role->save(); + $this->testUser = User::create([ + 'name' => 'foobar', + 'mail' => 'foobar@example.com', + ]); + $this->testUser->addRole($role->id()); + $this->testUser->save(); + \Drupal::service('current_user')->setAccount($this->testUser); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'test_text_area_element'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) { + // A textformat field. + $form['textformat'] = [ + '#type' => 'text_format', + '#required' => TRUE, + '#title' => 'Text', + '#base_type' => 'textfield', + '#format' => NULL, + '#default_value' => 'test value', + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) {} + + /** + * Form validation handler. + * + * @param array $form + * An associative array containing the structure of the form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + */ + public function validateForm(array &$form, FormStateInterface $form_state) {} + + /** + * Tests that values are returned. + */ + public function testTextFormatElement() { + /* @var \Drupal\Core\Form\FormBuilder $form_builder */ + $form_builder = $this->container->get('form_builder'); + $form = $form_builder->getForm($this); + $output = $this->render($form); + $this->setRawContent($output); + $this->assertFieldByName('textformat[value]'); + $this->assertRaw('

Full HTML

'); + $this->assertRaw('

Filtered HTML

'); + $this->assertRaw('

Test format

'); + $this->assertNoPattern('|]*>|', 'No empty H4 element found.'); + } + + /** + * {@inheritdoc} + */ + protected function getUrl() { + // \Drupal\simpletest\AssertContentTrait needs this for ::assertFieldByName + // to work. + return 'Internal rendering'; + } + +}