[TASK] Re-work/simplify copyright header in PHP files - Part 9
[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 * @return void
69 */
70 public function addExtensionToQueueThrowsExceptionIfUnknownStackIsGiven() {
71 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', $this->any(), 1342432103);
72 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock, 'unknownStack');
73 }
74
75 /**
76 * @test
77 * @return void
78 */
79 public function addExtensionToQueueThrowsExceptionIfExtensionWithSameKeyAndDifferentValuesAlreadyExists() {
80 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionMock2 */
81 $extensionMock2 = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
82 $extensionMock2->setExtensionKey('foobar');
83 $extensionMock2->setVersion('1.0.3');
84 $this->downloadQueueMock->_set('extensionStorage', array('foobar' => $extensionMock2));
85
86 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', $this->any(), 1342432101);
87 $this->downloadQueueMock->addExtensionToQueue($this->extensionMock);
88 }
89
90 /**
91 * @test
92 * @return void
93 */
94 public function removeExtensionFromQueueRemovesExtension() {
95 $extensionMock2 = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
96 $extensionMock2->_set('extensionKey', 'foobarbaz');
97 $extensionMock2->_set('version', '1.0.3');
98 $this->downloadQueueMock->_set('extensionStorage', array(
99 'download' => array(
100 'foobar' => $this->extensionMock,
101 'foobarbaz' => $extensionMock2
102 )
103 ));
104 $extensionStorageBefore = $this->downloadQueueMock->_get('extensionStorage');
105
106 $this->assertTrue(array_key_exists('foobar', $extensionStorageBefore['download']));
107
108 $this->downloadQueueMock->removeExtensionFromQueue($this->extensionMock);
109 $extensionStorageAfter = $this->downloadQueueMock->_get('extensionStorage');
110
111 $this->assertFalse(array_key_exists('foobar', $extensionStorageAfter['download']));
112 }
113
114 }