[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Mvc / Web / CacheHashEnforcerTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Web;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Extbase\Mvc\Web\CacheHashEnforcer;
19 use TYPO3\CMS\Extbase\Mvc\Web\Request;
20 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
21 use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 /**
25 * Test case
26 */
27 class CacheHashEnforcerTest extends UnitTestCase
28 {
29 /**
30 * @var \TYPO3\CMS\Extbase\Mvc\Web\CacheHashEnforcer
31 */
32 protected $subject;
33
34 /**
35 * @var TypoScriptFrontendController|\PHPUnit_Framework_MockObject_MockObject
36 */
37 protected $frontendControllerMock;
38
39 protected function setUp()
40 {
41 $this->frontendControllerMock = $this->getMockBuilder(TypoScriptFrontendController::class)->disableOriginalConstructor()->getMock();
42 $this->frontendControllerMock->id = 42;
43 $cacheHashCalculator = new CacheHashCalculator();
44 $this->subject = new CacheHashEnforcer(
45 $cacheHashCalculator,
46 $this->frontendControllerMock
47 );
48 }
49
50 /**
51 * @test
52 */
53 public function validateCallsReqCHashIfRequestArgumentsArePresent()
54 {
55 $request = new Request();
56 $request->setArguments(['foo' => 'bar']);
57 $this->frontendControllerMock
58 ->expects($this->once())
59 ->method('reqCHash');
60
61 $this->subject->enforceForRequest($request, 'tx_foo');
62 }
63
64 /**
65 * @test
66 */
67 public function validateDoesNotCallsReqCHashIfNoRequestArgumentsArePresent()
68 {
69 $request = new Request();
70 $this->frontendControllerMock
71 ->expects($this->never())
72 ->method('reqCHash');
73
74 $this->subject->enforceForRequest($request, 'tx_foo');
75 }
76 }