class CommandLineOrUnsafeMethodTest in Drupal 8
Same name and namespace in other branches
- 9 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\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\PageCache\CommandLineOrUnsafeMethodTest
Expanded class hierarchy of CommandLineOrUnsafeMethodTest
File
- core/
tests/ Drupal/ Tests/ Core/ PageCache/ CommandLineOrUnsafeMethodTest.php, line 13
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;
protected function 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')
->setMethods([
'isCli',
])
->getMock();
}
/**
* Asserts that check() returns DENY for unsafe HTTP methods.
*
* @dataProvider providerTestHttpMethod
* @covers ::check
*/
public function testHttpMethod($expected_result, $method) {
$this->policy
->expects($this
->once())
->method('isCli')
->will($this
->returnValue(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 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() {
$this->policy
->expects($this
->once())
->method('isCli')
->will($this
->returnValue(TRUE));
$request = Request::create('/', 'GET');
$actual_result = $this->policy
->check($request);
$this
->assertSame(RequestPolicyInterface::DENY, $actual_result);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommandLineOrUnsafeMethodTest:: |
protected | property | The request policy under test. | |
CommandLineOrUnsafeMethodTest:: |
public | function | Provides test data and expected results for the HTTP method test. | |
CommandLineOrUnsafeMethodTest:: |
protected | function |
Overrides UnitTestCase:: |
|
CommandLineOrUnsafeMethodTest:: |
public | function | Asserts that check() returns DENY for unsafe HTTP methods. | |
CommandLineOrUnsafeMethodTest:: |
public | function | Asserts that check() returns DENY if running from the command line. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |