comparison core/profiles/standard/tests/src/FunctionalJavascript/StandardJavascriptTest.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2
3 namespace Drupal\Tests\standard\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
6 use Drupal\node\Entity\Node;
7
8 /**
9 * Tests Standard installation profile JavaScript expectations.
10 *
11 * @group standard
12 */
13 class StandardJavascriptTest extends JavascriptTestBase {
14
15 /**
16 * {@inheritdoc}
17 */
18 protected $profile = 'standard';
19
20 /**
21 * Tests BigPipe accelerates particular Standard installation profile routes.
22 */
23 public function testBigPipe() {
24 $this->drupalLogin($this->drupalCreateUser([
25 'access content',
26 'post comments',
27 'skip comment approval',
28 ]));
29
30 $node = Node::create(['type' => 'article'])
31 ->setTitle($this->randomMachineName())
32 ->setPromoted(TRUE)
33 ->setPublished(TRUE);
34 $node->save();
35
36 // Front page: one placeholder, for messages.
37 $this->drupalGet('');
38 $this->assertBigPipePlaceholderReplacementCount(1);
39
40 // Node page: 3 placeholders:
41 // 1. messages
42 // 2. local tasks block
43 // 3. comment form
44 $this->drupalGet($node->toUrl());
45 $this->assertBigPipePlaceholderReplacementCount(3);
46 }
47
48 /**
49 * Asserts the number of BigPipe placeholders that are replaced on the page.
50 *
51 * @param int $expected_count
52 * The expected number of BigPipe placeholders.
53 */
54 protected function assertBigPipePlaceholderReplacementCount($expected_count) {
55 $web_assert = $this->assertSession();
56 $web_assert->waitForElement('css', 'script[data-big-pipe-event="stop"]');
57 $page = $this->getSession()->getPage();
58 $this->assertCount($expected_count, $this->getDrupalSettings()['bigPipePlaceholderIds']);
59 $this->assertCount($expected_count, $page->findAll('css', 'script[data-big-pipe-replacement-for-placeholder-with-id]'));
60 }
61
62 }