TYPO3 CMS  TYPO3_8-7
PackageTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script belongs to the TYPO3 Flow framework. *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
19 
23 class PackageTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
27  protected function setUp()
28  {
29  vfsStream::setup('Packages');
30  }
31 
36  {
37  $this->expectException(InvalidPackagePathException::class);
38  $this->expectExceptionCode(1166631890);
39 
40  $packageManagerMock = $this->createMock(PackageManager::class);
41  $packageManagerMock->expects($this->any())->method('isPackageKeyValid')->willReturn(true);
42  new Package($packageManagerMock, 'Vendor.TestPackage', './ThisPackageSurelyDoesNotExist');
43  }
44 
47  public function validPackageKeys()
48  {
49  return [
50  ['Doctrine.DBAL'],
51  ['TYPO3.CMS'],
52  ['My.Own.TwitterPackage'],
53  ['GoFor.IT'],
54  ['Symfony.Symfony']
55  ];
56  }
57 
62  public function constructAcceptsValidPackageKeys($packageKey)
63  {
64  $packagePath = 'vfs://Packages/' . str_replace('\\', '/', $packageKey) . '/';
65  mkdir($packagePath, 0777, true);
66  file_put_contents($packagePath . 'composer.json', '{"name": "' . $packageKey . '", "type": "flow-test"}');
67  file_put_contents($packagePath . 'ext_emconf.php', '');
68 
69  $packageManagerMock = $this->createMock(PackageManager::class);
70  $packageManagerMock->expects($this->any())->method('isPackageKeyValid')->willReturn(true);
71  $package = new Package($packageManagerMock, $packageKey, $packagePath);
72  $this->assertEquals($packageKey, $package->getPackageKey());
73  }
74 
77  public function invalidPackageKeys()
78  {
79  return [
80  ['TYPO3..Flow'],
81  ['RobertLemke.Flow. Twitter'],
82  ['Schalke*4']
83  ];
84  }
85 
90  public function constructRejectsInvalidPackageKeys($packageKey)
91  {
92  $this->expectException(InvalidPackageKeyException::class);
93  $this->expectExceptionCode(1217959511);
94 
95  $packagePath = 'vfs://Packages/' . str_replace('\\', '/', $packageKey) . '/';
96  mkdir($packagePath, 0777, true);
97 
98  $packageManagerMock = $this->createMock(PackageManager::class);
99  new Package($packageManagerMock, $packageKey, $packagePath);
100  }
101 
106  {
107  $packagePath = 'vfs://Packages/Application/Vendor/Dummy/';
108  mkdir($packagePath, 0700, true);
109  file_put_contents($packagePath . 'composer.json', '{"name": "vendor/dummy", "type": "flow-test"}');
110  file_put_contents($packagePath . 'ext_emconf.php', '');
111 
112  $packageManagerMock = $this->createMock(PackageManager::class);
113  $packageManagerMock->expects($this->any())->method('isPackageKeyValid')->willReturn(true);
114  $package = new Package($packageManagerMock, 'Vendor.Dummy', $packagePath);
115 
116  $this->assertFalse($package->isProtected());
117  $package->setProtected(true);
118  $this->assertTrue($package->isProtected());
119  }
120 }