Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / filter / tests / src / Functional / FilterHooksTest.php
1 <?php
2
3 namespace Drupal\Tests\filter\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\user\RoleInterface;
7
8 /**
9  * Tests hooks for text formats insert/update/disable.
10  *
11  * @group filter
12  */
13 class FilterHooksTest extends BrowserTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['node', 'filter_test'];
21
22   /**
23    * Tests hooks on format management.
24    *
25    * Tests that hooks run correctly on creating, editing, and deleting a text
26    * format.
27    */
28   public function testFilterHooks() {
29     // Create content type, with underscores.
30     $type_name = 'test_' . strtolower($this->randomMachineName());
31     $type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
32     $node_permission = "create $type_name content";
33
34     $admin_user = $this->drupalCreateUser(['administer filters', 'administer nodes', $node_permission]);
35     $this->drupalLogin($admin_user);
36
37     // Add a text format.
38     $name = $this->randomMachineName();
39     $edit = [];
40     $edit['format'] = mb_strtolower($this->randomMachineName());
41     $edit['name'] = $name;
42     $edit['roles[' . RoleInterface::ANONYMOUS_ID . ']'] = 1;
43     $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
44     $this->assertRaw(t('Added text format %format.', ['%format' => $name]));
45     $this->assertText('hook_filter_format_insert invoked.');
46
47     $format_id = $edit['format'];
48
49     // Update text format.
50     $edit = [];
51     $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
52     $this->drupalPostForm('admin/config/content/formats/manage/' . $format_id, $edit, t('Save configuration'));
53     $this->assertRaw(t('The text format %format has been updated.', ['%format' => $name]));
54     $this->assertText('hook_filter_format_update invoked.');
55
56     // Use the format created.
57     $title = $this->randomMachineName(8);
58     $edit = [];
59     $edit['title[0][value]'] = $title;
60     $edit['body[0][value]'] = $this->randomMachineName(32);
61     $edit['body[0][format]'] = $format_id;
62     $this->drupalPostForm("node/add/{$type->id()}", $edit, t('Save'));
63     $this->assertText(t('@type @title has been created.', ['@type' => $type_name, '@title' => $title]));
64
65     // Disable the text format.
66     $this->drupalPostForm('admin/config/content/formats/manage/' . $format_id . '/disable', [], t('Disable'));
67     $this->assertRaw(t('Disabled text format %format.', ['%format' => $name]));
68     $this->assertText('hook_filter_format_disable invoked.');
69   }
70
71 }