]> _ Git - couzy.git/blob
a516daf074117dcd6819e995dd853f271c7d30cb
[couzy.git] /
1 <?php
2 namespace Composer\Installers\Test;
3
4 use Composer\Installers\Installer;
5 use Composer\Util\Filesystem;
6 use Composer\Package\Package;
7 use Composer\Package\RootPackage;
8 use Composer\Composer;
9 use Composer\Config;
10
11 class InstallerTest extends TestCase
12 {
13     private $composer;
14     private $config;
15     private $vendorDir;
16     private $binDir;
17     private $dm;
18     private $repository;
19     private $io;
20     private $fs;
21
22     /**
23      * setUp
24      *
25      * @return void
26      */
27     public function setUp()
28     {
29         $this->fs = new Filesystem;
30
31         $this->composer = new Composer();
32         $this->config = new Config();
33         $this->composer->setConfig($this->config);
34
35         $this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'baton-test-vendor';
36         $this->ensureDirectoryExistsAndClear($this->vendorDir);
37
38         $this->binDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'baton-test-bin';
39         $this->ensureDirectoryExistsAndClear($this->binDir);
40
41         $this->config->merge(array(
42             'config' => array(
43                 'vendor-dir' => $this->vendorDir,
44                 'bin-dir' => $this->binDir,
45             ),
46         ));
47
48         $this->dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
49             ->disableOriginalConstructor()
50             ->getMock();
51         $this->composer->setDownloadManager($this->dm);
52
53         $this->repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
54         $this->io = $this->getMock('Composer\IO\IOInterface');
55     }
56
57     /**
58      * tearDown
59      *
60      * @return void
61      */
62     public function tearDown()
63     {
64         $this->fs->removeDirectory($this->vendorDir);
65         $this->fs->removeDirectory($this->binDir);
66     }
67
68     /**
69      * testSupports
70      *
71      * @return void
72      *
73      * @dataProvider dataForTestSupport
74      */
75     public function testSupports($type, $expected)
76     {
77         $installer = new Installer($this->io, $this->composer);
78         $this->assertSame($expected, $installer->supports($type), sprintf('Failed to show support for %s', $type));
79     }
80
81     /**
82      * dataForTestSupport
83      */
84     public function dataForTestSupport()
85     {
86         return array(
87             array('agl-module', true),
88             array('aimeos-extension', true),
89             array('annotatecms-module', true),
90             array('annotatecms-component', true),
91             array('annotatecms-service', true),
92             array('bitrix-module', true),
93             array('bitrix-component', true),
94             array('bitrix-theme', true),
95             array('cakephp', false),
96             array('cakephp-', false),
97             array('cakephp-app', false),
98             array('cakephp-plugin', true),
99             array('chef-cookbook', true),
100             array('chef-role', true),
101             array('codeigniter-app', false),
102             array('codeigniter-library', true),
103             array('codeigniter-third-party', true),
104             array('codeigniter-module', true),
105             array('concrete5-block', true),
106             array('concrete5-package', true),
107             array('concrete5-theme', true),
108             array('concrete5-update', true),
109             array('craft-plugin', true),
110             array('croogo-plugin', true),
111             array('croogo-theme', true),
112             array('dokuwiki-plugin', true),
113             array('dokuwiki-template', true),
114             array('drupal-module', true),
115             array('dolibarr-module', true),
116             array('elgg-plugin', true),
117             array('fuel-module', true),
118             array('fuel-package', true),
119             array('fuel-theme', true),
120             array('fuelphp-component', true),
121             array('hurad-plugin', true),
122             array('hurad-theme', true),
123             array('joomla-library', true),
124             array('kirby-plugin', true),
125             array('kohana-module', true),
126             array('laravel-library', true),
127             array('lithium-library', true),
128             array('magento-library', true),
129             array('mako-package', true),
130             array('modxevo-snippet', true),
131             array('modxevo-plugin', true),
132             array('modxevo-module', true),
133             array('modxevo-template', true),
134             array('modxevo-lib', true),
135             array('mediawiki-extension', true),
136             array('mediawiki-skin', true),
137             array('microweber-module', true),
138             array('modulework-module', true),
139             array('moodle-mod', true),
140             array('october-module', true),
141             array('october-plugin', true),
142             array('piwik-plugin', true),
143             array('phpbb-extension', true),
144             array('pimcore-plugin', true),
145             array('ppi-module', true),
146             array('prestashop-module', true),
147             array('prestashop-theme', true),
148             array('puppet-module', true),
149             array('redaxo-addon', true),
150             array('redaxo-bestyle-plugin', true),
151             array('roundcube-plugin', true),
152             array('shopware-backend-plugin', true),
153             array('shopware-core-plugin', true),
154             array('shopware-frontend-plugin', true),
155             array('shopware-theme', true),
156             array('silverstripe-module', true),
157             array('silverstripe-theme', true),
158             array('smf-module', true),
159             array('smf-theme', true),
160             array('symfony1-plugin', true),
161             array('thelia-module', true),
162             array('thelia-frontoffice-template', true),
163             array('thelia-backoffice-template', true),
164             array('thelia-email-template', true),
165             array('tusk-task', true),
166             array('tusk-asset', true),
167             array('typo3-flow-plugin', true),
168             array('typo3-cms-extension', true),
169             array('whmcs-gateway', true),
170             array('wolfcms-plugin', true),
171             array('wordpress-plugin', true),
172             array('wordpress-core', false),
173             array('zend-library', true),
174             array('zikula-module', true),
175             array('zikula-theme', true),
176         );
177     }
178
179     /**
180      * testInstallPath
181      *
182      * @dataProvider dataForTestInstallPath
183      */
184     public function testInstallPath($type, $path, $name, $version = '1.0.0')
185     {
186         $installer = new Installer($this->io, $this->composer);
187         $package = new Package($name, $version, $version);
188
189         $package->setType($type);
190         $result = $installer->getInstallPath($package);
191         $this->assertEquals($path, $result);
192     }
193
194     /**
195      * dataFormTestInstallPath
196      */
197     public function dataForTestInstallPath()
198     {
199         return array(
200             array('agl-module', 'More/MyTestPackage/', 'agl/my_test-package'),
201             array('aimeos-extension', 'ext/ai-test/', 'author/ai-test'),
202             array('annotatecms-module', 'addons/modules/my_module/', 'vysinsky/my_module'),
203             array('annotatecms-component', 'addons/components/my_component/', 'vysinsky/my_component'),
204             array('annotatecms-service', 'addons/services/my_service/', 'vysinsky/my_service'),
205             array('bitrix-module', 'local/modules/my_module/', 'author/my_module'),
206             array('bitrix-component', 'local/components/my_component/', 'author/my_component'),
207             array('bitrix-theme', 'local/templates/my_theme/', 'author/my_theme'),
208             array('cakephp-plugin', 'Plugin/Ftp/', 'shama/ftp'),
209             array('chef-cookbook', 'Chef/mre/my_cookbook/', 'mre/my_cookbook'),
210             array('chef-role', 'Chef/roles/my_role/', 'mre/my_role'),
211             array('codeigniter-library', 'application/libraries/my_package/', 'shama/my_package'),
212             array('codeigniter-module', 'application/modules/my_package/', 'shama/my_package'),
213             array('concrete5-block', 'blocks/concrete5_block/', 'remo/concrete5_block'),
214             array('concrete5-package', 'packages/concrete5_package/', 'remo/concrete5_package'),
215             array('concrete5-theme', 'themes/concrete5_theme/', 'remo/concrete5_theme'),
216             array('concrete5-update', 'updates/concrete5/', 'concrete5/concrete5'),
217             array('craft-plugin', 'craft/plugins/my_plugin/', 'mdcpepper/my_plugin'),
218             array('croogo-plugin', 'Plugin/Sitemaps/', 'fahad19/sitemaps'),
219             array('croogo-theme', 'View/Themed/Readable/', 'rchavik/readable'),
220             array('dokuwiki-plugin', 'lib/plugins/someplugin/', 'author/someplugin'),
221             array('dokuwiki-template', 'lib/tpl/sometemplate/', 'author/sometemplate'),
222             array('dolibarr-module', 'htdocs/custom/my_module/', 'shama/my_module'),
223             array('drupal-module', 'modules/my_module/', 'shama/my_module'),
224             array('drupal-theme', 'themes/my_module/', 'shama/my_module'),
225             array('drupal-profile', 'profiles/my_module/', 'shama/my_module'),
226             array('drupal-drush', 'drush/my_module/', 'shama/my_module'),
227             array('elgg-plugin', 'mod/sample_plugin/', 'test/sample_plugin'),
228             array('fuel-module', 'fuel/app/modules/module/', 'fuel/module'),
229             array('fuel-package', 'fuel/packages/orm/', 'fuel/orm'),
230             array('fuel-theme', 'fuel/app/themes/theme/', 'fuel/theme'),
231             array('fuelphp-component', 'components/demo/', 'fuelphp/demo'),
232             array('hurad-plugin', 'plugins/Akismet/', 'atkrad/akismet'),
233             array('hurad-theme', 'plugins/Hurad2013/', 'atkrad/Hurad2013'),
234             array('joomla-plugin', 'plugins/my_plugin/', 'shama/my_plugin'),
235             array('kirby-plugin', 'site/plugins/my_plugin/', 'shama/my_plugin'),
236             array('kohana-module', 'modules/my_package/', 'shama/my_package'),
237             array('laravel-library', 'libraries/my_package/', 'shama/my_package'),
238             array('lithium-library', 'libraries/li3_test/', 'user/li3_test'),
239             array('magento-library', 'lib/foo/', 'test/foo'),
240             array('modxevo-snippet', 'assets/snippets/my_snippet/', 'shama/my_snippet'),
241             array('modxevo-plugin', 'assets/plugins/my_plugin/', 'shama/my_plugin'),
242             array('modxevo-module', 'assets/modules/my_module/', 'shama/my_module'),
243             array('modxevo-template', 'assets/templates/my_template/', 'shama/my_template'),
244             array('modxevo-lib', 'assets/lib/my_lib/', 'shama/my_lib'),
245             array('mako-package', 'app/packages/my_package/', 'shama/my_package'),
246             array('mediawiki-extension', 'extensions/APC/', 'author/APC'),
247             array('mediawiki-extension', 'extensions/APC/', 'author/APC-extension'),
248             array('mediawiki-extension', 'extensions/UploadWizard/', 'author/upload-wizard'),
249             array('mediawiki-extension', 'extensions/SyntaxHighlight_GeSHi/', 'author/syntax-highlight_GeSHi'),
250             array('mediawiki-skin', 'skins/someskin/', 'author/someskin-skin'),
251             array('mediawiki-skin', 'skins/someskin/', 'author/someskin'),
252             array('microweber-module', 'userfiles/modules/my-thing/', 'author/my-thing-module'),
253             array('modulework-module', 'modules/my_package/', 'shama/my_package'),
254             array('moodle-mod', 'mod/my_package/', 'shama/my_package'),
255             array('october-module', 'modules/my_plugin/', 'shama/my_plugin'),
256             array('october-plugin', 'plugins/shama/my_plugin/', 'shama/my_plugin'),
257             array('october-theme', 'themes/my_theme/', 'shama/my_theme'),
258             array('piwik-plugin', 'plugins/VisitSummary/', 'shama/visit-summary'),
259             array('prestashop-module', 'modules/a-module/', 'vendor/a-module'),
260             array('prestashop-theme', 'themes/a-theme/', 'vendor/a-theme'),
261             array('phpbb-extension', 'ext/test/foo/', 'test/foo'),
262             array('phpbb-style', 'styles/foo/', 'test/foo'),
263             array('phpbb-language', 'language/foo/', 'test/foo'),
264             array('pimcore-plugin', 'plugins/MyPlugin/', 'ubikz/my_plugin'),
265             array('ppi-module', 'modules/foo/', 'test/foo'),
266             array('puppet-module', 'modules/puppet-name/', 'puppet/puppet-name'),
267             array('redaxo-addon', 'redaxo/include/addons/my_plugin/', 'shama/my_plugin'),
268             array('redaxo-bestyle-plugin', 'redaxo/include/addons/be_style/plugins/my_plugin/', 'shama/my_plugin'),
269             array('roundcube-plugin', 'plugins/base/', 'test/base'),
270             array('roundcube-plugin', 'plugins/replace_dash/', 'test/replace-dash'),
271             array('shopware-backend-plugin', 'engine/Shopware/Plugins/Local/Backend/ShamaMyBackendPlugin/', 'shama/my-backend-plugin'),
272             array('shopware-core-plugin', 'engine/Shopware/Plugins/Local/Core/ShamaMyCorePlugin/', 'shama/my-core-plugin'),
273             array('shopware-frontend-plugin', 'engine/Shopware/Plugins/Local/Frontend/ShamaMyFrontendPlugin/', 'shama/my-frontend-plugin'),
274             array('shopware-theme', 'templates/my_theme/', 'shama/my-theme'),
275             array('silverstripe-module', 'my_module/', 'shama/my_module'),
276             array('silverstripe-module', 'sapphire/', 'silverstripe/framework', '2.4.0'),
277             array('silverstripe-module', 'framework/', 'silverstripe/framework', '3.0.0'),
278             array('silverstripe-module', 'framework/', 'silverstripe/framework', '3.0.0-rc1'),
279             array('silverstripe-module', 'framework/', 'silverstripe/framework', 'my/branch'),
280             array('silverstripe-theme', 'themes/my_theme/', 'shama/my_theme'),
281             array('smf-module', 'Sources/my_module/', 'shama/my_module'),
282             array('smf-theme', 'Themes/my_theme/', 'shama/my_theme'),
283             array('symfony1-plugin', 'plugins/sfShamaPlugin/', 'shama/sfShamaPlugin'),
284             array('symfony1-plugin', 'plugins/sfShamaPlugin/', 'shama/sf-shama-plugin'),
285             array('thelia-module', 'local/modules/my_module/', 'shama/my_module'),
286             array('thelia-frontoffice-template', 'templates/frontOffice/my_template_fo/', 'shama/my_template_fo'),
287             array('thelia-backoffice-template', 'templates/backOffice/my_template_bo/', 'shama/my_template_bo'),
288             array('thelia-email-template', 'templates/email/my_template_email/', 'shama/my_template_email'),
289             array('tusk-task', '.tusk/tasks/my_task/', 'shama/my_task'),
290             array('typo3-flow-package', 'Packages/Application/my_package/', 'shama/my_package'),
291             array('typo3-flow-build', 'Build/my_package/', 'shama/my_package'),
292             array('typo3-cms-extension', 'typo3conf/ext/my_extension/', 'shama/my_extension'),
293             array('whmcs-gateway', 'modules/gateways/gateway_name/', 'vendor/gateway_name'),
294             array('wolfcms-plugin', 'wolf/plugins/my_plugin/', 'shama/my_plugin'),
295             array('wordpress-plugin', 'wp-content/plugins/my_plugin/', 'shama/my_plugin'),
296             array('wordpress-muplugin', 'wp-content/mu-plugins/my_plugin/', 'shama/my_plugin'),
297             array('zend-extra', 'extras/library/zend_test/', 'shama/zend_test'),
298             array('zikula-module', 'modules/my-test_module/', 'my/test_module'),
299             array('zikula-theme', 'themes/my-test_theme/', 'my/test_theme'),
300         );
301     }
302
303     /**
304      * testGetCakePHPInstallPathException
305      *
306      * @return void
307      *
308      * @expectedException \InvalidArgumentException
309      */
310     public function testGetCakePHPInstallPathException()
311     {
312         $installer = new Installer($this->io, $this->composer);
313         $package = new Package('shama/ftp', '1.0.0', '1.0.0');
314
315         $package->setType('cakephp-whoops');
316         $result = $installer->getInstallPath($package);
317     }
318
319     /**
320      * testCustomInstallPath
321      */
322     public function testCustomInstallPath()
323     {
324         $installer = new Installer($this->io, $this->composer);
325         $package = new Package('shama/ftp', '1.0.0', '1.0.0');
326         $package->setType('cakephp-plugin');
327         $consumerPackage = new RootPackage('foo/bar', '1.0.0', '1.0.0');
328         $this->composer->setPackage($consumerPackage);
329         $consumerPackage->setExtra(array(
330             'installer-paths' => array(
331                 'my/custom/path/{$name}/' => array(
332                     'shama/ftp',
333                     'foo/bar',
334                 ),
335             ),
336         ));
337         $result = $installer->getInstallPath($package);
338         $this->assertEquals('my/custom/path/Ftp/', $result);
339     }
340
341     /**
342      * testCustomInstallerName
343      */
344     public function testCustomInstallerName()
345     {
346         $installer = new Installer($this->io, $this->composer);
347         $package = new Package('shama/cakephp-ftp-plugin', '1.0.0', '1.0.0');
348         $package->setType('cakephp-plugin');
349         $package->setExtra(array(
350             'installer-name' => 'FTP',
351         ));
352         $result = $installer->getInstallPath($package);
353         $this->assertEquals('Plugin/FTP/', $result);
354     }
355
356     /**
357      * testCustomTypePath
358      */
359     public function testCustomTypePath()
360     {
361         $installer = new Installer($this->io, $this->composer);
362         $package = new Package('slbmeh/my_plugin', '1.0.0', '1.0.0');
363         $package->setType('wordpress-plugin');
364         $consumerPackage = new RootPackage('foo/bar', '1.0.0', '1.0.0');
365         $this->composer->setPackage($consumerPackage);
366         $consumerPackage->setExtra(array(
367             'installer-paths' => array(
368                 'my/custom/path/{$name}/' => array(
369                     'type:wordpress-plugin'
370                 ),
371             ),
372         ));
373         $result = $installer->getInstallPath($package);
374         $this->assertEquals('my/custom/path/my_plugin/', $result);
375     }
376
377     /**
378      * testNoVendorName
379      */
380     public function testNoVendorName()
381     {
382         $installer = new Installer($this->io, $this->composer);
383         $package = new Package('sfPhpunitPlugin', '1.0.0', '1.0.0');
384
385         $package->setType('symfony1-plugin');
386         $result = $installer->getInstallPath($package);
387         $this->assertEquals('plugins/sfPhpunitPlugin/', $result);
388     }
389
390     /**
391      * testTypo3Inflection
392      */
393     public function testTypo3Inflection()
394     {
395         $installer = new Installer($this->io, $this->composer);
396         $package = new Package('typo3/fluid', '1.0.0', '1.0.0');
397
398         $package->setAutoload(array(
399             'psr-0' => array(
400                 'TYPO3\\Fluid' => 'Classes',
401             ),
402         ));
403
404         $package->setType('typo3-flow-package');
405         $result = $installer->getInstallPath($package);
406         $this->assertEquals('Packages/Application/TYPO3.Fluid/', $result);
407     }
408
409     public function testUninstallAndDeletePackageFromLocalRepo()
410     {
411         $package = new Package('foo', '1.0.0', '1.0.0');
412
413         $installer = $this->getMock('Composer\Installers\Installer', array('getInstallPath'), array($this->io, $this->composer));
414         $installer->expects($this->once())->method('getInstallPath')->with($package)->will($this->returnValue(sys_get_temp_dir().'/foo'));
415
416         $repo = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
417         $repo->expects($this->once())->method('hasPackage')->with($package)->will($this->returnValue(true));
418         $repo->expects($this->once())->method('removePackage')->with($package);
419
420         $installer->uninstall($repo, $package);
421     }
422 }