8abf51e6a21c0d48cfc43f1505a2d47ca1dab172
[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 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog, <susanne.moog@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Download queue test
29 *
30 */
31 class DownloadQueueTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
32
33 /**
34 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue
35 */
36 protected $downloadQueueMock;
37
38 /**
39 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Extensionmanager\Domain\Model\Extension
40 */
41 protected $extensionMock;
42
43 /**
44 * @return void
45 */
46 public function setUp() {
47 $this->downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('dummy'));
48 $this->extensionMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
49 $this->extensionMock->setExtensionKey('foobar');
50 $this->extensionMock->setVersion('1.0.0');
51
52 }
53
54 /**
55 * @test
56 * @return void
57 */
58 public function addExtensionToQueueAddsExtensionToDownloadStorageArray() {
59 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock);
60 $extensionStorage = $this->downloadQueueMock->_get('extensionStorage');
61
62 $this->assertArrayHasKey('foobar', $extensionStorage['download']);
63 }
64
65 /**
66 * @test
67 * @return void
68 */
69 public function addExtensionToQueueAddsExtensionToUpdateStorageArray() {
70 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock, 'update');
71 $extensionStorage = $this->downloadQueueMock->_get('extensionStorage');
72
73 $this->assertArrayHasKey('foobar', $extensionStorage['update']);
74 }
75
76 /**
77 * @test
78 * @return void
79 */
80 public function addExtensionToQueueThrowsExceptionIfUnknownStackIsGiven() {
81 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', $this->any(), 1342432103);
82 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock, 'unknownStack');
83 }
84
85 /**
86 * @test
87 * @return void
88 */
89 public function addExtensionToQueueThrowsExceptionIfExtensionWithSameKeyAndDifferentValuesAlreadyExists() {
90 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionMock2 */
91 $extensionMock2 = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
92 $extensionMock2->setExtensionKey('foobar');
93 $extensionMock2->setVersion('1.0.3');
94 $this->downloadQueueMock->_set('extensionStorage', array('foobar' => $extensionMock2));
95
96 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', $this->any(), 1342432101);
97 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock);
98 }
99
100 /**
101 * @test
102 * @return void
103 */
104 public function removeExtensionFromQueueRemovesExtension() {
105 $extensionMock2 = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
106 $extensionMock2->_set('extensionKey', 'foobarbaz');
107 $extensionMock2->_set('version', '1.0.3');
108 $this->downloadQueueMock->_set('extensionStorage', array(
109 'download' => array(
110 'foobar' => $this->extensionMock,
111 'foobarbaz' => $extensionMock2
112 )
113 ));
114 $extensionStorageBefore = $this->downloadQueueMock->_get('extensionStorage');
115
116 $this->assertTrue(array_key_exists('foobar', $extensionStorageBefore['download']));
117
118 $this->downloadQueueMock->removeExtensionFromQueue($this->extensionMock);
119 $extensionStorageAfter = $this->downloadQueueMock->_get('extensionStorage');
120
121 $this->assertFalse(array_key_exists('foobar', $extensionStorageAfter['download']));
122 }
123
124 }