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