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