function HtmxAttributesTest::testSwap

Test swap method.

File

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

Class

HtmxAttributesTest
Test all attribute-related Htmx public methods.

Namespace

Drupal\Tests\Core\Htmx

Code

public function testSwap() : void {
  // Simple case.
  $this->htmx
    ->swap('afterbegin');
  $render = $this->apply();
  $this->assertTrue(isset($render['#attributes']['data-hx-swap']));
  $this->assertEquals('afterbegin ignoreTitle:true', $render['#attributes']['data-hx-swap']);
  // Don't ignore the title.
  $this->htmx
    ->swap('afterbegin', '', FALSE);
  $render = $this->apply();
  $this->assertTrue(isset($render['#attributes']['data-hx-swap']));
  $this->assertEquals('afterbegin', $render['#attributes']['data-hx-swap']);
  // Use a modifier.
  $this->htmx
    ->swap('beforeend', 'scroll:bottom');
  $render = $this->apply();
  $this->assertTrue(isset($render['#attributes']['data-hx-swap']));
  $this->assertEquals('beforeend scroll:bottom ignoreTitle:true', $render['#attributes']['data-hx-swap']);
}

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