TYPO3 CMS  TYPO3_8-7
ThumbnailControllerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
25 class ThumbnailControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
30  protected $subject;
31 
35  protected static $parameters = [
36  'fileId' => 123,
37  'configuration' => [
38  'width' => 64,
39  'heigth' => 64,
40  ],
41  ];
42 
43  protected function setUp()
44  {
45  $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']
46  = '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6';
47  $this->subject = $this->createPartialMock(
48  ThumbnailController::class,
49  ['generateThumbnail']
50  );
51  }
52 
59  public function exceptionIsThrownOnInvalidHMAC(string $hmac = null)
60  {
61  $this->expectException(\InvalidArgumentException::class);
62  $this->expectExceptionCode(1534484203);
63 
64  $queryParameters = [
65  'parameters' => json_encode(static::$parameters),
66  'hmac' => $hmac,
67  ];
68 
69  $request = (new \TYPO3\CMS\Core\Http\ServerRequest())
70  ->withQueryParams($queryParameters);
71  $this->subject->render($request);
72  }
73 
78  {
79  return [
80  'null' => [null],
81  'empty' => [''],
82  'invalid' => ['invalid'],
83  ];
84  }
85 
92  public function generateThumbnailIsInvoked(array $parameters = null)
93  {
94  $this->subject->expects(static::once())
95  ->method('generateThumbnail')
96  ->willReturn(new Response());
97 
98  $queryParameters = [
99  'parameters' => json_encode($parameters),
100  'hmac' => GeneralUtility::hmac(
101  json_encode($parameters),
102  ThumbnailController::class
103  ),
104  ];
105 
106  $request = (new \TYPO3\CMS\Core\Http\ServerRequest())
107  ->withQueryParams($queryParameters);
108  static::assertInstanceOf(
109  Response::class,
110  $this->subject->render($request)
111  );
112  }
113 
117  public function generateThumbnailIsInvokedDataProvider(): array
118  {
119  return [
120  'null' => [null],
121  'empty array' => [[]],
122  'parameters' => [static::$parameters],
123  ];
124  }
125 }
static hmac($input, $additionalSecret='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']