a303e1236e0521233471e905ac9b66e38082827b
[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 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 * @package Extension Manager
29 * @subpackage Tests
30 */
31 class DownloadQueueTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
32
33 /**
34 * @test
35 * @return void
36 */
37 public function addExtensionToQueueAddsExtensionToDownloadStorageArray() {
38 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
39 $extensionModelMock->_set('extensionKey', 'foobar');
40 $extensionModelMock->_set('version', '1.0.0');
41 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('dummy'));
42 $downloadQueueMock->addExtensionToQueue($extensionModelMock);
43 $extensionStorage = $downloadQueueMock->_get('extensionStorage');
44 $this->assertArrayHasKey('foobar', $extensionStorage['download']);
45 }
46
47 /**
48 * @test
49 * @return void
50 */
51 public function addExtensionToQueueAddsExtensionToUpdateStorageArray() {
52 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
53 $extensionModelMock->_set('extensionKey', 'foobar');
54 $extensionModelMock->_set('version', '1.0.0');
55 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('dummy'));
56 $downloadQueueMock->addExtensionToQueue($extensionModelMock, 'update');
57 $extensionStorage = $downloadQueueMock->_get('extensionStorage');
58 $this->assertArrayHasKey('foobar', $extensionStorage['update']);
59 }
60
61 /**
62 * @test
63 * @return void
64 */
65 public function addExtensionToQueueThrowsExceptionIfUnknownStackIsGiven() {
66 /** @var $extensionModelMock \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
67 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
68 $extensionModelMock->_set('extensionKey', 'foobar');
69 $extensionModelMock->_set('version', '1.0.0');
70 /** @var $downloadQueueMock \TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue */
71 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('dummy'));
72 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', $this->any(), 1342432103);
73 $downloadQueueMock->addExtensionToQueue($extensionModelMock, 'unknownStack');
74 }
75
76 /**
77 * @test
78 * @return void
79 */
80 public function addExtensionToQueueThrowsExceptionIfExtensionWithSameKeyAndDifferentValuesAlreadyExists() {
81 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
82 $extensionModelMock->_set('extensionKey', 'foobar');
83 $extensionModelMock->_set('version', '1.0.0');
84 $extensionModelMock2 = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
85 $extensionModelMock2->_set('extensionKey', 'foobar');
86 $extensionModelMock2->_set('version', '1.0.3');
87 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('dummy'));
88 $downloadQueueMock->_set('extensionStorage', array('foobar' => $extensionModelMock2));
89 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', $this->any(), 1342432101);
90 $downloadQueueMock->addExtensionToQueue($extensionModelMock);
91 }
92
93 /**
94 * @test
95 * @return void
96 */
97 public function removeExtensionFromQueueRemovesExtension() {
98 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
99 $extensionModelMock->_set('extensionKey', 'foobar');
100 $extensionModelMock->_set('version', '1.0.0');
101 $extensionModelMock2 = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
102 $extensionModelMock2->_set('extensionKey', 'foobarbaz');
103 $extensionModelMock2->_set('version', '1.0.3');
104 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('dummy'));
105 $downloadQueueMock->_set('extensionStorage', array(
106 'download' => array(
107 'foobar' => $extensionModelMock,
108 'foobarbaz' => $extensionModelMock2
109 )
110 ));
111 $extensionStorageBefore = $downloadQueueMock->_get('extensionStorage');
112 $this->assertTrue(array_key_exists('foobar', $extensionStorageBefore['download']));
113 $downloadQueueMock->removeExtensionFromQueue($extensionModelMock);
114 $extensionStorageAfter = $downloadQueueMock->_get('extensionStorage');
115 $this->assertFalse(array_key_exists('foobar', $extensionStorageAfter['download']));
116 }
117
118 }
119
120
121 ?>