class HtmxRequestInfoTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Htmx/HtmxRequestInfoTest.php \Drupal\Tests\Core\Htmx\HtmxRequestInfoTest
Test all HtmxRequestInfoTrait methods.
Attributes
#[CoversClass(HtmxRequestInfoTrait::class)]
#[Group('Htmx')]
Hierarchy
- class \Drupal\Tests\DrupalTestCase uses \Drupal\Tests\DrupalTestCaseTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\UnitTestCase uses \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\RandomGeneratorTrait extends \Drupal\Tests\DrupalTestCase
- class \Drupal\Tests\Core\Htmx\HtmxRequestInfoTest uses \Drupal\Core\Htmx\HtmxRequestInfoTrait extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\UnitTestCase uses \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\RandomGeneratorTrait extends \Drupal\Tests\DrupalTestCase
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 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', 'input#submit-button');
$this->assertEquals('input#submit-button', $this->getHtmxTarget());
}
/**
* Tests the getHtmxTrigger method.
*/
public function testGetHtmxSource() : void {
// Test with the header not present.
$this->assertEquals('', $this->getHtmxSource());
// Test with the header present.
$this->request->headers
->set('HX-Source', 'input#submit-button');
$this->assertEquals('input#submit-button', $this->getHtmxSource());
}
/**
* 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-Source', 'input[name="submit-button"]');
$this->assertEquals('submit-button', $this->getHtmxTriggerName());
}
/**
* Tests the getHtmxRequestType method.
*/
public function testGetHtmxRequestType() : void {
// Test with the header not present.
$this->assertEquals('', $this->getHtmxRequestType());
// Test with the header present.
$this->request->headers
->set('HX-Request-Type', 'request-type');
$this->assertEquals('request-type', $this->getHtmxRequestType());
}
/**
* {@inheritdoc}
*/
protected function getRequest() : Request {
return $this->request;
}
}
Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|---|
| DrupalTestCase::$root | protected | property | The Drupal root directory. | |||
| DrupalTestCase::getDrupalRoot | Deprecated | protected | function | Returns the Drupal root directory. | 1 | |
| DrupalTestCase::setUpRoot | final protected | function | Ensure that the $root property is set initially. | |||
| DrupalTestCase::skipTestWithAttribute | final protected | function | Supports skipping tests with the Skip attribute. | |||
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | 1 | ||
| DrupalTestCaseTrait::expectExceptionMessageIs | protected | function | Expects an exactly matching exception message. | |||
| DrupalTestCaseTrait::expectExceptionMessageIsOrContains | protected | function | Expects an exception message containing a specified string. | |||
| DrupalTestCaseTrait::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |||
| 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::testGetHtmxRequestType | public | function | Tests the getHtmxRequestType method. | |||
| HtmxRequestInfoTest::testGetHtmxSource | public | function | Tests the getHtmxTrigger method. | |||
| HtmxRequestInfoTest::testGetHtmxTarget | public | function | Tests the getHtmxTarget 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::getHtmxRequestType | protected | function | Retrieves the request type from an HTMX request header. | |||
| HtmxRequestInfoTrait::getHtmxSource | protected | function | Retrieves the trigger identifier from an HTMX request header. | |||
| HtmxRequestInfoTrait::getHtmxTarget | protected | function | Retrieves the target identifier from an HTMX request header. | |||
| HtmxRequestInfoTrait::getHtmxTriggerName | protected | function | Extracts the trigger name from the HX-Source 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::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::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.