[!!!][TASK] Remove support for non namespaced classes in Extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Controller / DownloadControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Controller;
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;
18
19 /**
20 * Download from TER controller test
21 */
22 class DownloadControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
24 /**
25 * @test
26 */
27 public function installFromTerReturnsArrayWithBooleanResultAndErrorArrayWhenExtensionManagerExceptionIsThrown()
28 {
29 $dummyExceptionMessage = 'exception message';
30 $dummyException = new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException($dummyExceptionMessage, 1476108614);
31
32 $dummyExtensionName = 'dummy_extension';
33 $dummyExtension = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)->getMock();
34 $dummyExtension->expects($this->any())->method('getExtensionKey')->will($this->returnValue($dummyExtensionName));
35
36 /** @var \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility|MockObject $downloadUtilityMock */
37 $downloadUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class)->getMock();
38 $downloadUtilityMock->expects($this->any())->method('setDownloadPath')->willThrowException($dummyException);
39
40 /** @var \TYPO3\CMS\Extensionmanager\Controller\DownloadController $subject */
41 $subject = new \TYPO3\CMS\Extensionmanager\Controller\DownloadController();
42 $subject->injectDownloadUtility($downloadUtilityMock);
43
44 $reflectionClass = new \ReflectionClass($subject);
45 $reflectionMethod = $reflectionClass->getMethod('installFromTer');
46 $reflectionMethod->setAccessible(true);
47
48 $result = $reflectionMethod->invokeArgs($subject, [$dummyExtension]);
49
50 $expectedResult = [
51 false,
52 [
53 $dummyExtensionName => [
54 [
55 'code' => 1476108614,
56 'message' => $dummyExceptionMessage
57 ]
58 ]
59 ]
60 ];
61
62 $this->assertSame($expectedResult, $result);
63 }
64 }