3 namespace Drupal\Tests\big_pipe\FunctionalJavascript;
5 use Drupal\big_pipe\Render\BigPipe;
6 use Drupal\big_pipe_regression_test\BigPipeRegressionTestController;
7 use Drupal\comment\CommentInterface;
8 use Drupal\comment\Entity\Comment;
9 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
10 use Drupal\comment\Tests\CommentTestTrait;
12 use Drupal\editor\Entity\Editor;
13 use Drupal\filter\Entity\FilterFormat;
14 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
15 use Drupal\simpletest\ContentTypeCreationTrait;
16 use Drupal\simpletest\NodeCreationTrait;
19 * BigPipe regression tests.
23 class BigPipeRegressionTest extends WebDriverTestBase {
26 use ContentTypeCreationTrait;
27 use NodeCreationTrait;
32 public static $modules = [
34 'big_pipe_regression_test',
40 public function setUp() {
43 // Use the big_pipe_test_theme theme.
44 $this->container->get('theme_installer')->install(['big_pipe_test_theme']);
45 $this->container->get('config.factory')->getEditable('system.theme')->set('default', 'big_pipe_test_theme')->save();
49 * Ensure comment form works with history and big_pipe modules.
51 * @see https://www.drupal.org/node/2698811
53 public function testCommentForm_2698811() {
54 $this->assertTrue($this->container->get('module_installer')->install(['comment', 'history', 'ckeditor'], TRUE), 'Installed modules.');
56 // Ensure an `article` node type exists.
57 $this->createContentType(['type' => 'article']);
58 $this->addDefaultCommentField('node', 'article');
61 $format = $this->randomMachineName();
62 FilterFormat::create([
64 'name' => $this->randomString(),
68 $settings['toolbar']['rows'] = [
79 $editor = Editor::create([
81 'editor' => 'ckeditor',
83 $editor->setSettings($settings);
86 $admin_user = $this->drupalCreateUser([
89 'use text format ' . $format,
91 $this->drupalLogin($admin_user);
93 $node = $this->createNode([
95 'comment' => CommentItemInterface::OPEN,
97 // Create some comments.
98 foreach (range(1, 5) as $i) {
99 $comment = Comment::create([
100 'status' => CommentInterface::PUBLISHED,
101 'field_name' => 'comment',
102 'entity_type' => 'node',
103 'entity_id' => $node->id(),
107 $this->drupalGet($node->toUrl()->toString());
108 // Confirm that CKEditor loaded.
111 return Object.keys(CKEDITOR.instances).length > 0;
114 $this->assertJsCondition($javascript);
118 * Ensure BigPipe works despite inline JS containing the string "</body>".
120 * @see https://www.drupal.org/node/2678662
122 public function testMultipleClosingBodies_2678662() {
123 $this->assertTrue($this->container->get('module_installer')->install(['render_placeholder_message_test'], TRUE), 'Installed modules.');
125 $this->drupalLogin($this->drupalCreateUser());
126 $this->drupalGet(Url::fromRoute('big_pipe_regression_test.2678662'));
128 // Confirm that AJAX behaviors were instantiated, if not, this points to a
129 // JavaScript syntax error.
132 return Object.keys(Drupal.ajax.instances).length > 0;
135 $this->assertJsCondition($javascript);
137 // Besides verifying there is no JavaScript syntax error, also verify the
139 $this->assertSession()
140 ->responseContains(BigPipe::STOP_SIGNAL . "\n\n\n</body></html>", 'The BigPipe stop signal is present just before the closing </body> and </html> tags.');
141 $js_code_until_closing_body_tag = substr(BigPipeRegressionTestController::MARKER_2678662, 0, strpos(BigPipeRegressionTestController::MARKER_2678662, '</body>'));
142 $this->assertSession()
143 ->responseNotContains($js_code_until_closing_body_tag . "\n" . BigPipe::START_SIGNAL, 'The BigPipe start signal does NOT start at the closing </body> tag string in an inline script.');
147 * Ensure messages set in placeholders always appear.
149 * @see https://www.drupal.org/node/2712935
151 public function testMessages_2712935() {
152 $this->assertTrue($this->container->get('module_installer')->install(['render_placeholder_message_test'], TRUE), 'Installed modules.');
154 $this->drupalLogin($this->drupalCreateUser());
155 $messages_markup = '<div role="contentinfo" aria-label="Status message"';
158 // Messages placeholder rendered first.
159 'render_placeholder_message_test.first',
160 // Messages placeholder rendered after one, before another.
161 'render_placeholder_message_test.middle',
162 // Messages placeholder rendered last.
163 'render_placeholder_message_test.last',
166 $assert = $this->assertSession();
167 foreach ($test_routes as $route) {
168 // Verify that we start off with zero messages queued.
169 $this->drupalGet(Url::fromRoute('render_placeholder_message_test.queued'));
170 $assert->responseNotContains($messages_markup);
172 // Verify the test case at this route behaves as expected.
173 $this->drupalGet(Url::fromRoute($route));
174 $assert->elementContains('css', 'p.logged-message:nth-of-type(1)', 'Message: P1');
175 $assert->elementContains('css', 'p.logged-message:nth-of-type(2)', 'Message: P2');
176 $assert->responseContains($messages_markup);
177 $assert->elementExists('css', 'div[aria-label="Status message"] ul');
178 $assert->elementContains('css', 'div[aria-label="Status message"] ul li:nth-of-type(1)', 'P1');
179 $assert->elementContains('css', 'div[aria-label="Status message"] ul li:nth-of-type(2)', 'P2');
181 // Verify that we end with all messages printed, hence again zero queued.
182 $this->drupalGet(Url::fromRoute('render_placeholder_message_test.queued'));
183 $assert->responseNotContains($messages_markup);
188 * Ensure default BigPipe placeholder HTML cannot split paragraphs.
190 * @see https://www.drupal.org/node/2802923
192 public function testPlaceholderInParagraph_2802923() {
193 $this->drupalLogin($this->drupalCreateUser());
194 $this->drupalGet(Url::fromRoute('big_pipe_regression_test.2802923'));
196 $this->assertJsCondition('document.querySelectorAll(\'p\').length === 1');