function HtmxHeadersTest::testLocationHeaderResponseData
Test location header with complex data.
File
-
core/
tests/ Drupal/ Tests/ Core/ Htmx/ HtmxHeadersTest.php, line 71
Class
- HtmxHeadersTest
- Test all header-related Htmx public methods.
Namespace
Drupal\Tests\Core\HtmxCode
public function testLocationHeaderResponseData() : void {
$data = new HtmxLocationResponseData(path: $this->url, source: 'source-value', event: 'event-value', handler: 'handler-value', target: 'target-value', swap: 'swap-value', values: [
'one' => '1',
'two' => '2',
], headers: [
'Header-one' => 'one',
], select: 'select-value');
$this->htmx
->locationHeader($data);
$render = $this->apply();
$this->assertTrue(isset($render['#attached']['http_header']));
$this->assertIsArray($render['#attached']['http_header']);
$value = reset($render['#attached']['http_header']);
$this->assertEquals('hx-location', $value[0]);
$this->assertEquals('{"path":"https:\\/\\/www.example.test\\/common-test\\/destination","source":"source-value","event":"event-value","headers":{"Header-one":"one"},"handler":"handler-value","target":"target-value","swap":"swap-value","select":"select-value","values":{"one":"1","two":"2"}}', $value[1]);
$this->assertEquals(TRUE, $value[2]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.