ManyPlaceholderTest.php in Drupal 9
File
core/modules/big_pipe/tests/src/Unit/Render/ManyPlaceholderTest.php
View source
<?php
namespace Drupal\Tests\big_pipe\Unit\Render;
use Drupal\big_pipe\Render\BigPipe;
use Drupal\big_pipe\Render\BigPipeResponse;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Render\HtmlResponse;
use Drupal\Core\Render\RendererInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class ManyPlaceholderTest extends UnitTestCase {
public function testManyNoJsPlaceHolders() {
$bigpipe = new BigPipe($this
->prophesize(RendererInterface::class)
->reveal(), $this
->prophesize(SessionInterface::class)
->reveal(), $this
->prophesize(RequestStack::class)
->reveal(), $this
->prophesize(HttpKernelInterface::class)
->reveal(), $this
->prophesize(EventDispatcherInterface::class)
->reveal(), $this
->prophesize(ConfigFactoryInterface::class)
->reveal());
$response = new BigPipeResponse(new HtmlResponse());
$many_placeholders = [];
for ($i = 0; $i < 400; $i++) {
$many_placeholders[$this
->randomMachineName(80)] = $this
->randomMachineName(80);
}
$attachments = [
'library' => [],
'big_pipe_nojs_placeholders' => $many_placeholders,
];
$response
->setAttachments($attachments);
$content = '<html><body>content<drupal-big-pipe-scripts-bottom-marker>script-bottom<drupal-big-pipe-scripts-bottom-marker></body></html>';
$response
->setContent($content);
ob_start();
$bigpipe
->sendContent($response);
$result = ob_get_clean();
$this
->assertNotEmpty($result);
}
}