function HtmxAttributesTest::testModifiers

Tests modifiers.

File

core/tests/Drupal/Tests/Core/Htmx/HtmxAttributesTest.php, line 370

Class

HtmxAttributesTest
Test all attribute-related Htmx public methods.

Namespace

Drupal\Tests\Core\Htmx

Code

public function testModifiers() : void {
  // No modifier is the default.  Including for completeness.
  $this->htmx
    ->select('selector', Htmx::NO_MODIFIER);
  $render = $this->apply();
  $this->assertTrue(isset($render['#attributes']['data-hx-select']));
  $this->assertEquals('selector', $render['#attributes']['data-hx-select']);
  // Inherited.
  $this->htmx
    ->select('selector', Htmx::INHERITED);
  $render = $this->apply();
  $this->assertTrue(isset($render['#attributes']['data-hx-select']));
  $this->assertEquals('selector', $render['#attributes']['data-hx-select:inherited']);
  // Append.
  $this->htmx
    ->select('selector', Htmx::APPEND);
  $render = $this->apply();
  $this->assertTrue(isset($render['#attributes']['data-hx-select']));
  $this->assertEquals('selector', $render['#attributes']['data-hx-select:append']);
  // Combined.
  $this->htmx
    ->select('selector', Htmx::INHERITED | Htmx::APPEND);
  $render = $this->apply();
  $this->assertTrue(isset($render['#attributes']['data-hx-select']));
  $this->assertEquals('selector', $render['#attributes']['data-hx-select:inherited:append']);
}

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