class CommandLineOrUnsafeMethodTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/PageCache/CommandLineOrUnsafeMethodTest.php \Drupal\Tests\Core\PageCache\CommandLineOrUnsafeMethodTest
- 8.9.x core/tests/Drupal/Tests/Core/PageCache/CommandLineOrUnsafeMethodTest.php \Drupal\Tests\Core\PageCache\CommandLineOrUnsafeMethodTest
- 10 core/tests/Drupal/Tests/Core/PageCache/CommandLineOrUnsafeMethodTest.php \Drupal\Tests\Core\PageCache\CommandLineOrUnsafeMethodTest
@coversDefaultClass \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod @group PageCache
Hierarchy
- class \Drupal\Tests\Core\PageCache\CommandLineOrUnsafeMethodTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of CommandLineOrUnsafeMethodTest
File
-
core/
tests/ Drupal/ Tests/ Core/ PageCache/ CommandLineOrUnsafeMethodTest.php, line 15
Namespace
Drupal\Tests\Core\PageCacheView source
class CommandLineOrUnsafeMethodTest extends UnitTestCase {
/**
* The request policy under test.
*
* @var \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod|\PHPUnit\Framework\MockObject\MockObject
*/
protected $policy;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Note that it is necessary to partially mock the class under test in
// order to disable the isCli-check.
$this->policy = $this->getMockBuilder('Drupal\\Core\\PageCache\\RequestPolicy\\CommandLineOrUnsafeMethod')
->onlyMethods([
'isCli',
])
->getMock();
}
/**
* Asserts that check() returns DENY for unsafe HTTP methods.
*
* @dataProvider providerTestHttpMethod
* @covers ::check
*/
public function testHttpMethod($expected_result, $method) : void {
$this->policy
->expects($this->once())
->method('isCli')
->willReturn(FALSE);
$request = Request::create('/', $method);
$actual_result = $this->policy
->check($request);
$this->assertSame($expected_result, $actual_result);
}
/**
* Provides test data and expected results for the HTTP method test.
*
* @return array
* Test data and expected results.
*/
public static function providerTestHttpMethod() {
return [
[
NULL,
'GET',
],
[
NULL,
'HEAD',
],
[
RequestPolicyInterface::DENY,
'POST',
],
[
RequestPolicyInterface::DENY,
'PUT',
],
[
RequestPolicyInterface::DENY,
'DELETE',
],
[
RequestPolicyInterface::DENY,
'OPTIONS',
],
[
RequestPolicyInterface::DENY,
'TRACE',
],
[
RequestPolicyInterface::DENY,
'CONNECT',
],
];
}
/**
* Asserts that check() returns DENY if running from the command line.
*
* @covers ::check
*/
public function testIsCli() : void {
$this->policy
->expects($this->once())
->method('isCli')
->willReturn(TRUE);
$request = Request::create('/', 'GET');
$actual_result = $this->policy
->check($request);
$this->assertSame(RequestPolicyInterface::DENY, $actual_result);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
CommandLineOrUnsafeMethodTest::$policy | protected | property | The request policy under test. | |
CommandLineOrUnsafeMethodTest::providerTestHttpMethod | public static | function | Provides test data and expected results for the HTTP method test. | |
CommandLineOrUnsafeMethodTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
CommandLineOrUnsafeMethodTest::testHttpMethod | public | function | Asserts that check() returns DENY for unsafe HTTP methods. | |
CommandLineOrUnsafeMethodTest::testIsCli | public | function | Asserts that check() returns DENY if running from the command line. | |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
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::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
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::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.