schemadotorg_demo_profile-1.0.x-dev/tests/src/FunctionalJavascript/SchemaDotOrgDemoJavascriptTest.php
tests/src/FunctionalJavascript/SchemaDotOrgDemoJavascriptTest.php
<?php
namespace Drupal\Tests\schemadotorg_demo_profile\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\Node;
/**
* Tests Schema.org Blueprints Demo installation profile JavaScript expectations.
*
* @group schemadotorg_demo_profile
*/
class SchemaDotOrgDemoJavascriptTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected $profile = 'schemadotorg_demo_profile';
/**
* Tests BigPipe accelerates particular Schema.org Blueprints Demo installation profile routes.
*/
public function testBigPipe() {
$this->drupalLogin($this->drupalCreateUser([
'access content',
]));
$node = Node::create(['type' => 'page'])
->setTitle($this->randomMachineName())
->setPromoted(TRUE)
->setPublished();
$node->save();
// Front page: one placeholder, for messages.
$this->drupalGet('');
$this->assertBigPipePlaceholderReplacementCount(1);
}
/**
* 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();
$this->assertCount($expected_count, $this->getDrupalSettings()['bigPipePlaceholderIds']);
$this->assertCount($expected_count, $page->findAll('css', 'script[data-big-pipe-replacement-for-placeholder-with-id]'));
}
}
