‪TYPO3CMS  9.5
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 
17 use PHPUnit\Framework\MockObject\MockObject;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪ThumbnailControllerTest extends UnitTestCase
27 {
31  protected ‪$subject;
32 
36  protected static ‪$parameters = [
37  'fileId' => 123,
38  'configuration' => [
39  'width' => 64,
40  'heigth' => 64,
41  ],
42  ];
43 
44  protected function ‪setUp()
45  {
46  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']
47  = '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6';
48  $this->subject = $this->createPartialMock(
49  ThumbnailController::class,
50  ['generateThumbnail']
51  );
52  }
53 
60  public function ‪exceptionIsThrownOnInvalidHMAC(string $hmac = null)
61  {
62  $this->expectException(\InvalidArgumentException::class);
63  $this->expectExceptionCode(1534484203);
64 
65  $queryParameters = [
66  'parameters' => json_encode(static::$parameters),
67  'hmac' => $hmac,
68  ];
69 
70  $request = (new \TYPO3\CMS\Core\Http\ServerRequest())
71  ->withQueryParams($queryParameters);
72  $this->subject->render($request);
73  }
74 
78  public function ‪exceptionIsThrownOnInvalidHMACDataProvider(): array
79  {
80  return [
81  'null' => [null],
82  'empty' => [''],
83  'invalid' => ['invalid'],
84  ];
85  }
86 
93  public function ‪generateThumbnailIsInvoked(array ‪$parameters = null)
94  {
95  $this->subject->expects(static::once())
96  ->method('generateThumbnail')
97  ->willReturn(new Response());
98 
99  $queryParameters = [
100  'parameters' => json_encode(‪$parameters),
101  'hmac' => GeneralUtility::hmac(
102  json_encode(‪$parameters),
103  ThumbnailController::class
104  ),
105  ];
106 
107  $request = (new \TYPO3\CMS\Core\Http\ServerRequest())
108  ->withQueryParams($queryParameters);
109  static::assertInstanceOf(
110  Response::class,
111  $this->subject->render($request)
112  );
113  }
114 
118  public function ‪generateThumbnailIsInvokedDataProvider(): array
119  {
120  return [
121  'null' => [null],
122  'empty array' => [[]],
123  'parameters' => [static::$parameters],
124  ];
125  }
126 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File
Definition: FileControllerTest.php:2
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\exceptionIsThrownOnInvalidHMAC
‪exceptionIsThrownOnInvalidHMAC(string $hmac=null)
Definition: ThumbnailControllerTest.php:58
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\setUp
‪setUp()
Definition: ThumbnailControllerTest.php:42
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\generateThumbnailIsInvokedDataProvider
‪array generateThumbnailIsInvokedDataProvider()
Definition: ThumbnailControllerTest.php:116
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\exceptionIsThrownOnInvalidHMACDataProvider
‪array exceptionIsThrownOnInvalidHMACDataProvider()
Definition: ThumbnailControllerTest.php:76
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\$subject
‪ThumbnailController MockObject $subject
Definition: ThumbnailControllerTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest
Definition: ThumbnailControllerTest.php:27
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\generateThumbnailIsInvoked
‪generateThumbnailIsInvoked(array $parameters=null)
Definition: ThumbnailControllerTest.php:91
‪TYPO3\CMS\Backend\Tests\Unit\Controller\File\ThumbnailControllerTest\$parameters
‪static array $parameters
Definition: ThumbnailControllerTest.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Controller\File\ThumbnailController
Definition: ThumbnailController.php:30