TYPO3 CMS  TYPO3_8-7
DownloadQueueTest.php
Go to the documentation of this file.
1 <?php
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  */
17 
21 class DownloadQueueTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
22 {
26  protected $downloadQueueMock;
27 
31  protected $extensionMock;
32 
35  protected function setUp()
36  {
37  $this->downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['dummy']);
38  $this->extensionMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
39  ->setMethods(['dummy'])
40  ->getMock();
41  $this->extensionMock->setExtensionKey('foobar');
42  $this->extensionMock->setVersion('1.0.0');
43  }
44 
49  {
50  $this->downloadQueueMock->addExtensionToQueue($this->extensionMock);
51  $extensionStorage = $this->downloadQueueMock->_get('extensionStorage');
52 
53  $this->assertArrayHasKey('foobar', $extensionStorage['download']);
54  }
55 
60  {
61  $this->downloadQueueMock->addExtensionToQueue($this->extensionMock, 'update');
62  $extensionStorage = $this->downloadQueueMock->_get('extensionStorage');
63 
64  $this->assertArrayHasKey('foobar', $extensionStorage['update']);
65  }
66 
71  {
72  $this->expectException(ExtensionManagerException::class);
73  $this->expectExceptionCode(1342432103);
74  $this->downloadQueueMock->addExtensionToQueue($this->extensionMock, 'unknownStack');
75  }
76 
80  public function addExtensionToQueueThrowsExceptionIfExtensionWithSameKeyAndDifferentValuesAlreadyExists()
81  {
83  $extensionMock2 = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
84  ->setMethods(['dummy'])
85  ->getMock();
86  $extensionMock2->setExtensionKey('foobar');
87  $extensionMock2->setVersion('1.0.3');
88 
89  $this->expectException(ExtensionManagerException::class);
90  $this->expectExceptionCode(1342432101);
91  $this->downloadQueueMock->addExtensionToQueue($extensionMock2);
92  $this->downloadQueueMock->addExtensionToQueue($this->extensionMock);
93  }
94 
99  {
100  $extensionMock2 = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['dummy']);
101  $extensionMock2->_set('extensionKey', 'foobarbaz');
102  $extensionMock2->_set('version', '1.0.3');
103  $this->downloadQueueMock->_set('extensionStorage', [
104  'download' => [
105  'foobar' => $this->extensionMock,
106  'foobarbaz' => $extensionMock2
107  ]
108  ]);
109  $extensionStorageBefore = $this->downloadQueueMock->_get('extensionStorage');
110 
111  $this->assertTrue(array_key_exists('foobar', $extensionStorageBefore['download']));
112 
113  $this->downloadQueueMock->removeExtensionFromQueue($this->extensionMock);
114  $extensionStorageAfter = $this->downloadQueueMock->_get('extensionStorage');
115 
116  $this->assertFalse(array_key_exists('foobar', $extensionStorageAfter['download']));
117  }
118 }