[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Domain / Model / DownloadQueueTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Domain\Model;
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 use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
17
18 /**
19 * Download queue test
20 *
21 */
22 class DownloadQueueTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
23 {
24 /**
25 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\Components\TestingFramework\Core\AccessibleObjectInterface|\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue
26 */
27 protected $downloadQueueMock;
28
29 /**
30 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Extensionmanager\Domain\Model\Extension
31 */
32 protected $extensionMock;
33
34 /**
35 * @return void
36 */
37 protected function setUp()
38 {
39 $this->downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['dummy']);
40 $this->extensionMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
41 ->setMethods(['dummy'])
42 ->getMock();
43 $this->extensionMock->setExtensionKey('foobar');
44 $this->extensionMock->setVersion('1.0.0');
45 }
46
47 /**
48 * @test
49 * @return void
50 */
51 public function addExtensionToQueueAddsExtensionToDownloadStorageArray()
52 {
53 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock);
54 $extensionStorage = $this->downloadQueueMock->_get('extensionStorage');
55
56 $this->assertArrayHasKey('foobar', $extensionStorage['download']);
57 }
58
59 /**
60 * @test
61 * @return void
62 */
63 public function addExtensionToQueueAddsExtensionToUpdateStorageArray()
64 {
65 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock, 'update');
66 $extensionStorage = $this->downloadQueueMock->_get('extensionStorage');
67
68 $this->assertArrayHasKey('foobar', $extensionStorage['update']);
69 }
70
71 /**
72 * @test
73 */
74 public function addExtensionToQueueThrowsExceptionIfUnknownStackIsGiven()
75 {
76 $this->expectException(ExtensionManagerException::class);
77 $this->expectExceptionCode(1342432103);
78 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock, 'unknownStack');
79 }
80
81 /**
82 * @test
83 * @return void
84 */
85 public function addExtensionToQueueThrowsExceptionIfExtensionWithSameKeyAndDifferentValuesAlreadyExists()
86 {
87 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionMock2 */
88 $extensionMock2 = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
89 ->setMethods(['dummy'])
90 ->getMock();
91 $extensionMock2->setExtensionKey('foobar');
92 $extensionMock2->setVersion('1.0.3');
93
94 $this->expectException(ExtensionManagerException::class);
95 $this->expectExceptionCode(1342432101);
96 $this->downloadQueueMock->addExtensionToQueue($extensionMock2);
97 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock);
98 }
99
100 /**
101 * @test
102 * @return void
103 */
104 public function removeExtensionFromQueueRemovesExtension()
105 {
106 $extensionMock2 = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['dummy']);
107 $extensionMock2->_set('extensionKey', 'foobarbaz');
108 $extensionMock2->_set('version', '1.0.3');
109 $this->downloadQueueMock->_set('extensionStorage', [
110 'download' => [
111 'foobar' => $this->extensionMock,
112 'foobarbaz' => $extensionMock2
113 ]
114 ]);
115 $extensionStorageBefore = $this->downloadQueueMock->_get('extensionStorage');
116
117 $this->assertTrue(array_key_exists('foobar', $extensionStorageBefore['download']));
118
119 $this->downloadQueueMock->removeExtensionFromQueue($this->extensionMock);
120 $extensionStorageAfter = $this->downloadQueueMock->_get('extensionStorage');
121
122 $this->assertFalse(array_key_exists('foobar', $extensionStorageAfter['download']));
123 }
124 }