function HtmxRendererTest::testWrapperFormat

Test triggering the renderer with _wrapper_format.

File

core/tests/Drupal/KernelTests/Core/Htmx/HtmxRendererTest.php, line 65

Class

HtmxRendererTest
Verifies HtmxRenderer.

Namespace

Drupal\KernelTests\Core\Htmx

Code

public function testWrapperFormat() : void {
  // Verify the "Powered by" block is rendered on a standard page.
  $url = Url::fromRoute('test_htmx.attachments.replace');
  $request = Request::create($url->toString());
  $response = $this->httpKernel
    ->handle($request);
  $this->assertEquals(200, $response->getStatusCode());
  $this->assertStringContainsString('Powered by', $response->getContent());
  // Verify the body contains only the main content when using the new
  // wrapper format.
  $options = [
    'query' => [
      MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_htmx',
    ],
  ];
  $url = Url::fromRoute('test_htmx.attachments.replace', [], $options);
  $request = Request::create($url->toString());
  $response = $this->httpKernel
    ->handle($request);
  $this->assertEquals(200, $response->getStatusCode());
  $this->assertEquals('text/html; charset=UTF-8', $response->headers
    ->get('Content-Type'));
  $oneLine = str_replace([
    "\r",
    "\n",
  ], "", $response->getContent());
  $this->assertStringContainsString('<body><div class="ajax-content">Initial Content</div></body>', $oneLine);
}

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