3 namespace Drupal\Tests\Core\PageCache;
5 use Drupal\Core\PageCache\RequestPolicyInterface;
6 use Drupal\Tests\UnitTestCase;
7 use Symfony\Component\HttpFoundation\Request;
10 * @coversDefaultClass \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod
13 class CommandLineOrUnsafeMethodTest extends UnitTestCase {
16 * The request policy under test.
18 * @var \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod|\PHPUnit_Framework_MockObject_MockObject
22 protected function setUp() {
23 // Note that it is necessary to partially mock the class under test in
24 // order to disable the isCli-check.
25 $this->policy = $this->getMock('Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod', ['isCli']);
29 * Asserts that check() returns DENY for unsafe HTTP methods.
31 * @dataProvider providerTestHttpMethod
34 public function testHttpMethod($expected_result, $method) {
35 $this->policy->expects($this->once())
37 ->will($this->returnValue(FALSE));
39 $request = Request::create('/', $method);
40 $actual_result = $this->policy->check($request);
41 $this->assertSame($expected_result, $actual_result);
45 * Provides test data and expected results for the HTTP method test.
48 * Test data and expected results.
50 public function providerTestHttpMethod() {
54 [RequestPolicyInterface::DENY, 'POST'],
55 [RequestPolicyInterface::DENY, 'PUT'],
56 [RequestPolicyInterface::DENY, 'DELETE'],
57 [RequestPolicyInterface::DENY, 'OPTIONS'],
58 [RequestPolicyInterface::DENY, 'TRACE'],
59 [RequestPolicyInterface::DENY, 'CONNECT'],
64 * Asserts that check() returns DENY if running from the command line.
68 public function testIsCli() {
69 $this->policy->expects($this->once())
71 ->will($this->returnValue(TRUE));
73 $request = Request::create('/', 'GET');
74 $actual_result = $this->policy->check($request);
75 $this->assertSame(RequestPolicyInterface::DENY, $actual_result);