class HtmxRequestInfoTest
Test all HtmxRequestInfoTrait methods.
Attributes
#[CoversClass(HtmxRequestInfoTrait::class)]
#[Group('Htmx')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Htmx\HtmxRequestInfoTest uses \Drupal\Core\Htmx\HtmxRequestInfoTrait extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of HtmxRequestInfoTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Htmx/ HtmxRequestInfoTest.php, line 16
Namespace
Drupal\Tests\Core\HtmxView source
class HtmxRequestInfoTest extends UnitTestCase {
use HtmxRequestInfoTrait;
/**
* A simulated request.
*/
protected Request $request;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->request = new Request();
}
/**
* Tests the isHtmxRequest method.
*/
public function testIsHtmxRequest() : void {
// Test with the header not present.
$this->assertFalse($this->isHtmxRequest());
// Test with the header present.
$this->request->headers
->set('HX-Request', 'true');
$this->assertTrue($this->isHtmxRequest());
}
/**
* Tests the isHtmxBoosted method.
*/
public function testIsHtmxBoosted() : void {
// Test with the header not present.
$this->assertFalse($this->isHtmxBoosted());
// Test with the header present.
$this->request->headers
->set('HX-Boosted', 'true');
$this->assertTrue($this->isHtmxBoosted());
}
/**
* Tests the getHtmxCurrentUrl method.
*/
public function testGetHtmxCurrentUrl() : void {
// Test with the header not present.
$this->assertEquals('', $this->getHtmxCurrentUrl());
// Test with the header present.
$this->request->headers
->set('HX-Current-URL', 'https://example.com/page');
$this->assertEquals('https://example.com/page', $this->getHtmxCurrentUrl());
}
/**
* Tests the isHtmxHistoryRestoration method.
*/
public function testIsHtmxHistoryRestoration() : void {
// Test with the header not present.
$this->assertFalse($this->isHtmxHistoryRestoration());
// Test with the header present.
$this->request->headers
->set('HX-History-Restore-Request', 'true');
$this->assertTrue($this->isHtmxHistoryRestoration());
}
/**
* Tests the getHtmxPrompt method.
*/
public function testGetHtmxPrompt() : void {
// Test with the header not present.
$this->assertEquals('', $this->getHtmxPrompt());
// Test with the header present.
$this->request->headers
->set('HX-Prompt', 'Enter a value');
$this->assertEquals('Enter a value', $this->getHtmxPrompt());
}
/**
* Tests the getHtmxTarget method.
*/
public function testGetHtmxTarget() : void {
// Test with the header not present.
$this->assertEquals('', $this->getHtmxTarget());
// Test with the header present.
$this->request->headers
->set('HX-Target', 'submit-button');
$this->assertEquals('submit-button', $this->getHtmxTarget());
}
/**
* Tests the getHtmxTrigger method.
*/
public function testGetHtmxTrigger() : void {
// Test with the header not present.
$this->assertEquals('', $this->getHtmxTrigger());
// Test with the header present.
$this->request->headers
->set('HX-Trigger', 'submit-button');
$this->assertEquals('submit-button', $this->getHtmxTrigger());
}
/**
* Tests the getHtmxTriggerName method.
*/
public function testGetHtmxTriggerName() : void {
// Test with the header not present.
$this->assertEquals('', $this->getHtmxTriggerName());
// Test with the header present.
$this->request->headers
->set('HX-Trigger-Name', 'submit-button');
$this->assertEquals('submit-button', $this->getHtmxTriggerName());
}
/**
* {@inheritdoc}
*/
protected function getRequest() {
return $this->request;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
HtmxRequestInfoTest::$request | protected | property | A simulated request. | |
HtmxRequestInfoTest::getRequest | protected | function | Gets the request object. | Overrides HtmxRequestInfoTrait::getRequest |
HtmxRequestInfoTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
HtmxRequestInfoTest::testGetHtmxCurrentUrl | public | function | Tests the getHtmxCurrentUrl method. | |
HtmxRequestInfoTest::testGetHtmxPrompt | public | function | Tests the getHtmxPrompt method. | |
HtmxRequestInfoTest::testGetHtmxTarget | public | function | Tests the getHtmxTarget method. | |
HtmxRequestInfoTest::testGetHtmxTrigger | public | function | Tests the getHtmxTrigger method. | |
HtmxRequestInfoTest::testGetHtmxTriggerName | public | function | Tests the getHtmxTriggerName method. | |
HtmxRequestInfoTest::testIsHtmxBoosted | public | function | Tests the isHtmxBoosted method. | |
HtmxRequestInfoTest::testIsHtmxHistoryRestoration | public | function | Tests the isHtmxHistoryRestoration method. | |
HtmxRequestInfoTest::testIsHtmxRequest | public | function | Tests the isHtmxRequest method. | |
HtmxRequestInfoTrait::getHtmxCurrentUrl | protected | function | Retrieves the URL of the requesting page from an HTMX request header. | |
HtmxRequestInfoTrait::getHtmxPrompt | protected | function | Retrieves the prompt from an HTMX request header. | |
HtmxRequestInfoTrait::getHtmxTarget | protected | function | Retrieves the target identifier from an HTMX request header. | |
HtmxRequestInfoTrait::getHtmxTrigger | protected | function | Retrieves the trigger identifier from an HTMX request header. | |
HtmxRequestInfoTrait::getHtmxTriggerName | protected | function | Retrieves the trigger name from an HTMX request header. | |
HtmxRequestInfoTrait::isHtmxBoosted | protected | function | Determines if the request is boosted by HTMX. | |
HtmxRequestInfoTrait::isHtmxHistoryRestoration | protected | function | Determines if if the request is for history restoration. | |
HtmxRequestInfoTrait::isHtmxRequest | protected | function | Determines if the request is sent by HTMX. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.