TYPO3 CMS  TYPO3_6-2
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 
15 use TYPO3\CMS\Core\Package\Package as TYPO3Package;
17 
23 
26  public function setUp() {
27  vfsStream::setup('Packages');
28  }
29 
35  new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), 'Vendor.TestPackage', './ThisPackageSurelyDoesNotExist');
36  }
37 
40  public function validPackageKeys() {
41  return array(
42  array('Doctrine.DBAL'),
43  array('TYPO3.Flow'),
44  array('RobertLemke.Flow.Twitter'),
45  array('Sumphonos.Stem'),
46  array('Schalke04.Soccer.MagicTrainer')
47  );
48  }
49 
54  public function constructAcceptsValidPackageKeys($packageKey) {
55  $packagePath = 'vfs://Packages/' . str_replace('\\', '/', $packageKey) . '/';
56  mkdir($packagePath, 0777, TRUE);
57  file_put_contents($packagePath . 'composer.json', '{"name": "' . $packageKey . '", "type": "flow-test"}');
58 
59  $package = new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), $packageKey, $packagePath);
60  $this->assertEquals($packageKey, $package->getPackageKey());
61  }
62 
65  public function invalidPackageKeys() {
66  return array(
67  array('TYPO3..Flow'),
68  array('RobertLemke.Flow. Twitter'),
69  array('Schalke*4')
70  );
71  }
72 
78  public function constructRejectsInvalidPackageKeys($packageKey) {
79  $packagePath = 'vfs://Packages/' . str_replace('\\', '/', $packageKey) . '/';
80  mkdir($packagePath, 0777, TRUE);
81  new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), $packageKey, $packagePath);
82  }
83 
88  $packagePath = 'vfs://Packages/Application/Acme.MyPackage/';
89  mkdir($packagePath, 0777, TRUE);
90  file_put_contents($packagePath . 'composer.json', '{"name": "acme/mypackage", "type": "flow-test"}');
91  $package = new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), 'Acme.MyPackage', $packagePath);
92  $this->assertEquals('Acme\\MyPackage', $package->getNamespace());
93  }
94 
99  $package = new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), 'TYPO3.CMS.Core', PATH_typo3 . 'sysext/core/');
100  $packageMetaDataPath = $package->getMetaPath();
101  $this->assertSame($package->getPackagePath() . FlowPackage::DIRECTORY_METADATA, $packageMetaDataPath);
102  }
103 
108  $package = new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), 'TYPO3.CMS.Core', PATH_typo3 . 'sysext/core/');
109  $packageDocumentationPath = $package->getDocumentationPath();
110 
111  $this->assertEquals($package->getPackagePath() . FlowPackage::DIRECTORY_DOCUMENTATION, $packageDocumentationPath);
112  }
113 
118  $packageManagerMock = $this->getMock('TYPO3\CMS\Core\Package\PackageManager');
119  $packageManagerMock->expects($this->any())->method('isPackageKeyValid')->willReturn(TRUE);
120  $package = new TYPO3Package($packageManagerMock, 'core', PATH_typo3 . 'sysext/core/', TYPO3Package::DIRECTORY_CLASSES);
121  $packageClassesPath = $package->getClassesPath();
122  $expected = $package->getPackagePath() . TYPO3Package::DIRECTORY_CLASSES;
123  $this->assertEquals($expected, $packageClassesPath);
124  }
125 
130  $packagePath = 'vfs://Packages/Application/Acme/MyPackage/';
131  mkdir($packagePath, 0777, TRUE);
132  file_put_contents($packagePath . 'composer.json', '{"name": "acme/mypackage", "type": "flow-test"}');
133 
134  $package = new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), 'Acme.MyPackage', $packagePath, 'no/trailing/slash');
135 
136  $packageClassesPath = $package->getClassesPath();
137  $expected = $package->getPackagePath() . 'no/trailing/slash/';
138 
139  $this->assertEquals($expected, $packageClassesPath);
140  }
141 
146  vfsStream::setup('testDirectory');
147 
148  $packagePath = vfsStream::url('testDirectory') . '/';
149  file_put_contents($packagePath . 'composer.json', '{"name": "typo3/flow", "type": "flow-test"}');
150 
151  $package = new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), 'TYPO3.Flow', $packagePath);
152  $documentations = $package->getPackageDocumentations();
153 
154  $this->assertEquals(array(), $documentations);
155  }
156 
161  $packagePath = 'vfs://Packages/Application/Vendor/Dummy/';
162  mkdir($packagePath, 0700, TRUE);
163  file_put_contents($packagePath . 'composer.json', '{"name": "vendor/dummy", "type": "flow-test"}');
164  $package = new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), 'Vendor.Dummy', $packagePath);
165 
166  $this->assertFalse($package->isProtected());
167  $package->setProtected(TRUE);
168  $this->assertTrue($package->isProtected());
169  }
170 
175  $packagePath = 'vfs://Packages/Application/Vendor/Dummy/';
176  mkdir($packagePath, 0700, TRUE);
177  file_put_contents($packagePath . 'composer.json', '{"name": "vendor/dummy", "type": "flow-test"}');
178  $package = new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), 'Vendor.Dummy', $packagePath);
179 
180  $this->assertTrue($package->isObjectManagementEnabled());
181  }
182 
187  $packagePath = 'vfs://Packages/Application/Acme.MyPackage/';
188  mkdir($packagePath, 0777, TRUE);
189  file_put_contents($packagePath . 'composer.json', '{"name": "acme/mypackage", "type": "flow-test"}');
190 
191  mkdir($packagePath . 'Classes/Acme/MyPackage/Controller', 0770, TRUE);
192  mkdir($packagePath . 'Classes/Acme/MyPackage/Domain/Model', 0770, TRUE);
193 
194  file_put_contents($packagePath . 'Classes/Acme/MyPackage/Controller/FooController.php', '');
195  file_put_contents($packagePath . 'Classes/Acme/MyPackage/Domain/Model/Foo.php', '');
196  file_put_contents($packagePath . 'Classes/Acme/MyPackage/Domain/Model/Bar.php', '');
197 
198  $expectedClassFilesArray = array(
199  'Acme\MyPackage\Controller\FooController' => 'Classes/Acme/MyPackage/Controller/FooController.php',
200  'Acme\MyPackage\Domain\Model\Foo' => 'Classes/Acme/MyPackage/Domain/Model/Foo.php',
201  'Acme\MyPackage\Domain\Model\Bar' => 'Classes/Acme/MyPackage/Domain/Model/Bar.php',
202  );
203 
204  $package = new FlowPackage($this->getMock('TYPO3\CMS\Core\Package\PackageManager'), 'Acme.MyPackage', $packagePath, 'Classes');
205  $actualClassFilesArray = $package->getClassFiles();
206 
207  $this->assertEquals($expectedClassFilesArray, $actualClassFilesArray);
208  }
209 
210 }