2 declare(strict_types = 1);
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 protected function setUp(): void
44 $subject = $this->getMockBuilder(FormProtectionTesting::class)
45 ->setMethods([
'retrieveSessionToken'])
47 $subject->expects($this->once())->method(
'retrieveSessionToken')->will($this->returnValue(
'token'));
57 $subject = $this->getMockBuilder(FormProtectionTesting::class)
58 ->setMethods([
'retrieveSessionToken'])
60 $subject->expects($this->once())->method(
'retrieveSessionToken')->will($this->returnValue(
'token'));
71 $tokenId = $this->subject->generateToken($formName);
72 $this->subject->clean();
73 $this->assertFalse($this->subject->validateToken($tokenId, $formName));
81 $subject = $this->getMockBuilder(FormProtectionTesting::class)
82 ->setMethods([
'persistSessionToken'])
84 $subject->expects($this->once())->method(
'persistSessionToken');
96 $this->expectException(\InvalidArgumentException::class);
97 $this->expectExceptionCode(1294586643);
98 $this->subject->generateToken(
'',
'edit',
'bar');
106 $this->subject->generateToken(
'foo',
'',
'42');
114 $this->subject->generateToken(
'foo',
'edit',
'');
122 $this->subject->generateToken(
'foo');
130 $this->assertRegExp(
'/^[0-9a-f]{40}$/', $this->subject->generateToken(
'foo'));
138 $this->assertEquals($this->subject->generateToken(
'foo',
'edit',
'bar'), $this->subject->generateToken(
'foo',
'edit',
'bar'));
149 $this->subject->validateToken(
'',
'',
'',
'');
157 $this->subject->validateToken(
'',
'');
167 $formInstanceName =
'bar';
168 $this->assertTrue($this->subject->validateToken($this->subject->generateToken($formName, $action, $formInstanceName), $formName, $action, $formInstanceName));
177 $this->assertTrue($this->subject->validateToken($this->subject->generateToken($formName), $formName));
187 $formInstanceName =
'bar';
188 $tokenId = $this->subject->generateToken($formName, $action, $formInstanceName);
189 $this->subject->validateToken($tokenId, $formName, $action, $formInstanceName);
190 $this->assertTrue($this->subject->validateToken($tokenId, $formName, $action, $formInstanceName));
200 $formInstanceName =
'bar';
201 $this->subject->generateToken($formName, $action, $formInstanceName);
202 $this->assertFalse($this->subject->validateToken(
'Hello world!', $formName, $action, $formInstanceName));
212 $formInstanceName =
'bar';
213 $tokenId = $this->subject->generateToken($formName, $action, $formInstanceName);
214 $this->assertFalse($this->subject->validateToken($tokenId,
'espresso', $action, $formInstanceName));
224 $formInstanceName =
'bar';
225 $tokenId = $this->subject->generateToken($formName, $action, $formInstanceName);
226 $this->assertFalse($this->subject->validateToken($tokenId, $formName,
'delete', $formInstanceName));
236 $formInstanceName =
'bar';
237 $tokenId = $this->subject->generateToken($formName, $action, $formInstanceName);
238 $this->assertFalse($this->subject->validateToken($tokenId, $formName, $action,
'beer'));
247 $subject = $this->getMockBuilder(FormProtectionTesting::class)
248 ->setMethods([
'createValidationErrorMessage'])
250 $subject->expects($this->never())->method(
'createValidationErrorMessage');
253 $formInstanceName =
'bar';
265 $subject = $this->getMockBuilder(FormProtectionTesting::class)
266 ->setMethods([
'createValidationErrorMessage'])
268 $subject->expects($this->once())->method(
'createValidationErrorMessage');
271 $formInstanceName =
'bar';
283 $subject = $this->getMockBuilder(FormProtectionTesting::class)
284 ->setMethods([
'createValidationErrorMessage'])
286 $subject->expects($this->once())->method(
'createValidationErrorMessage');
289 $formInstanceName =
'bar';