StandardJavascriptTest.php

Same filename in other branches
  1. 9 core/profiles/standard/tests/src/FunctionalJavascript/StandardJavascriptTest.php
  2. 8.9.x core/profiles/standard/tests/src/FunctionalJavascript/StandardJavascriptTest.php
  3. 10 core/profiles/standard/tests/src/FunctionalJavascript/StandardJavascriptTest.php

Namespace

Drupal\Tests\standard\FunctionalJavascript

File

core/profiles/standard/tests/src/FunctionalJavascript/StandardJavascriptTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\standard\FunctionalJavascript;

use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\Node;

/**
 * Tests Standard installation profile JavaScript expectations.
 *
 * @group standard
 */
class StandardJavascriptTest extends WebDriverTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected $profile = 'standard';
    
    /**
     * Tests BigPipe accelerates particular Standard installation profile routes.
     */
    public function testBigPipe() : void {
        $this->drupalLogin($this->drupalCreateUser([
            'access content',
            'post comments',
            'skip comment approval',
        ]));
        $node = Node::create([
            'type' => 'article',
        ])->setTitle($this->randomMachineName())
            ->setPromoted(TRUE)
            ->setPublished();
        $node->save();
        // Front page: one placeholder, for messages.
        $this->drupalGet('');
        $this->assertBigPipePlaceholderReplacementCount(1);
        // Node page: 2 placeholders:
        // 1. messages
        // 2. comment form
        $this->drupalGet($node->toUrl());
        $this->assertBigPipePlaceholderReplacementCount(2);
    }
    
    /**
     * Asserts the number of BigPipe placeholders that are replaced on the page.
     *
     * @param int $expected_count
     *   The expected number of BigPipe placeholders.
     */
    protected function assertBigPipePlaceholderReplacementCount($expected_count) : void {
        $web_assert = $this->assertSession();
        $web_assert->waitForElement('css', 'script[data-big-pipe-event="stop"]');
        $page = $this->getSession()
            ->getPage();
        // Settings are removed as soon as they are processed.
        $this->assertCount(0, $this->getDrupalSettings()['bigPipePlaceholderIds']);
        $this->assertCount($expected_count, $page->findAll('css', 'script[data-big-pipe-replacement-for-placeholder-with-id]'));
    }

}

Classes

Title Deprecated Summary
StandardJavascriptTest Tests Standard installation profile JavaScript expectations.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.