TYPO3 CMS  TYPO3_7-6
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 
17 
23 {
26  protected function setUp()
27  {
28  vfsStream::setup('Packages');
29  }
30 
36  {
37  $packageManagerMock = $this->getMock(PackageManager::class);
38  $packageManagerMock->expects($this->any())->method('isPackageKeyValid')->willReturn(true);
39  new Package($packageManagerMock, 'Vendor.TestPackage', './ThisPackageSurelyDoesNotExist');
40  }
41 
44  public function validPackageKeys()
45  {
46  return [
47  ['Doctrine.DBAL'],
48  ['TYPO3.CMS'],
49  ['My.Own.TwitterPackage'],
50  ['GoFor.IT'],
51  ['Symfony.Symfony']
52  ];
53  }
54 
59  public function constructAcceptsValidPackageKeys($packageKey)
60  {
61  $packagePath = 'vfs://Packages/' . str_replace('\\', '/', $packageKey) . '/';
62  mkdir($packagePath, 0777, true);
63  file_put_contents($packagePath . 'composer.json', '{"name": "' . $packageKey . '", "type": "flow-test"}');
64  file_put_contents($packagePath . 'ext_emconf.php', '');
65 
66  $packageManagerMock = $this->getMock(PackageManager::class);
67  $packageManagerMock->expects($this->any())->method('isPackageKeyValid')->willReturn(true);
68  $package = new Package($packageManagerMock, $packageKey, $packagePath);
69  $this->assertEquals($packageKey, $package->getPackageKey());
70  }
71 
74  public function invalidPackageKeys()
75  {
76  return [
77  ['TYPO3..Flow'],
78  ['RobertLemke.Flow. Twitter'],
79  ['Schalke*4']
80  ];
81  }
82 
88  public function constructRejectsInvalidPackageKeys($packageKey)
89  {
90  $packagePath = 'vfs://Packages/' . str_replace('\\', '/', $packageKey) . '/';
91  mkdir($packagePath, 0777, true);
92 
93  $packageManagerMock = $this->getMock(PackageManager::class);
94  new Package($packageManagerMock, $packageKey, $packagePath);
95  }
96 
101  {
102  $packagePath = 'vfs://Packages/Application/Vendor/Dummy/';
103  mkdir($packagePath, 0700, true);
104  file_put_contents($packagePath . 'composer.json', '{"name": "vendor/dummy", "type": "flow-test"}');
105  file_put_contents($packagePath . 'ext_emconf.php', '');
106 
107  $packageManagerMock = $this->getMock(PackageManager::class);
108  $packageManagerMock->expects($this->any())->method('isPackageKeyValid')->willReturn(true);
109  $package = new Package($packageManagerMock, 'Vendor.Dummy', $packagePath);
110 
111  $this->assertFalse($package->isProtected());
112  $package->setProtected(true);
113  $this->assertTrue($package->isProtected());
114  }
115 }