function HtmxUtilitiesTest::testCreateFromRenderArray
Test ::createFromRenderArray.
File
-
core/
tests/ Drupal/ Tests/ Core/ Htmx/ HtmxUtilitiesTest.php, line 125
Class
- HtmxUtilitiesTest
- Test all Htmx public utility methods.
Namespace
Drupal\Tests\Core\HtmxCode
public function testCreateFromRenderArray() : void {
$source = [
'#attributes' => [
'data-hx-apple' => 'orange',
'banana' => 'grape',
],
'#attached' => [
'http_header' => [
[
'pear',
'kiwi',
TRUE,
],
[
'hx-mango',
'peach',
TRUE,
],
],
],
'#cache' => [
'tags' => [
'node:3',
'node:12',
],
],
];
$htmx = Htmx::createFromRenderArray($source);
$this->assertTrue($htmx->hasAttribute('data-hx-apple'));
$this->assertFalse($htmx->hasAttribute('banana'));
$this->assertTrue($htmx->hasHeader('hx-mango'));
$this->assertFalse($htmx->hasHeader('pear'));
$render = [];
$htmx->applyTo($render);
$this->assertEquals(1, count($render['#attributes']));
$this->assertEquals(1, count($render['#attached']['http_header']));
$this->assertEquals([
'node:3',
'node:12',
], $render['#cache']['tags']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.