‪TYPO3CMS  10.4
ThumbnailControllerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use PHPUnit\Framework\MockObject\MockObject;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪ThumbnailControllerTest extends UnitTestCase
29 {
33  protected ‪$subject;
34 
38  protected static ‪$parameters = [
39  'fileId' => 123,
40  'configuration' => [
41  'width' => 64,
42  'height' => 64,
43  ],
44  ];
45 
46  protected function ‪setUp(): void
47  {
48  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']
49  = '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6';
50  $this->subject = $this->createPartialMock(
51  ThumbnailController::class,
52  ['generateThumbnail']
53  );
54  }
55 
62  public function ‪exceptionIsThrownOnInvalidHMAC(string $hmac = null)
63  {
64  $this->expectException(\InvalidArgumentException::class);
65  $this->expectExceptionCode(1534484203);
66 
67  $queryParameters = [
68  'parameters' => json_encode(static::$parameters),
69  'hmac' => $hmac,
70  ];
71 
72  $request = (new ‪ServerRequest())
73  ->withQueryParams($queryParameters);
74  $this->subject->render($request);
75  }
76 
80  public function ‪exceptionIsThrownOnInvalidHMACDataProvider(): array
81  {
82  return [
83  'null' => [null],
84  'empty' => [''],
85  'invalid' => ['invalid'],
86  ];
87  }
88 
95  public function ‪generateThumbnailIsInvoked(array ‪$parameters = null)
96  {
97  $this->subject->expects(self::once())
98  ->method('generateThumbnail')
99  ->willReturn(new Response());
100 
101  $queryParameters = [
102  'parameters' => json_encode(‪$parameters),
103  'hmac' => GeneralUtility::hmac(
104  json_encode(‪$parameters),
105  ThumbnailController::class
106  ),
107  ];
108 
109  $request = (new ServerRequest())
110  ->withQueryParams($queryParameters);
111  self::assertInstanceOf(
112  Response::class,
113  $this->subject->render($request)
114  );
115  }
116 
120  public function ‪generateThumbnailIsInvokedDataProvider(): array
121  {
122  return [
123  'null' => [null],
124  'empty array' => [[]],
125  'parameters' => [static::$parameters],
126  ];
127  }
128 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File
Definition: FileControllerTest.php:16
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\exceptionIsThrownOnInvalidHMAC
‪exceptionIsThrownOnInvalidHMAC(string $hmac=null)
Definition: ThumbnailControllerTest.php:60
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\setUp
‪setUp()
Definition: ThumbnailControllerTest.php:44
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\generateThumbnailIsInvokedDataProvider
‪array generateThumbnailIsInvokedDataProvider()
Definition: ThumbnailControllerTest.php:118
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\exceptionIsThrownOnInvalidHMACDataProvider
‪array exceptionIsThrownOnInvalidHMACDataProvider()
Definition: ThumbnailControllerTest.php:78
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest
Definition: ThumbnailControllerTest.php:29
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\generateThumbnailIsInvoked
‪generateThumbnailIsInvoked(array $parameters=null)
Definition: ThumbnailControllerTest.php:93
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\$parameters
‪static array $parameters
Definition: ThumbnailControllerTest.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller\File\ThumbnailController
Definition: ThumbnailController.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\$subject
‪TYPO3 CMS Backend Controller File ThumbnailController MockObject $subject
Definition: ThumbnailControllerTest.php:32