2017-03-14 03:20:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace SilverStripe\Core\Tests\Manifest;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Manifest\ModuleManifest;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
|
|
|
class ModuleManifestTest extends SapphireTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $base;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ModuleManifest
|
|
|
|
*/
|
|
|
|
protected $manifest;
|
|
|
|
|
2017-03-24 04:00:54 +01:00
|
|
|
protected function setUp()
|
2017-03-14 03:20:51 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->base = dirname(__FILE__) . '/fixtures/classmanifest';
|
|
|
|
$this->manifest = new ModuleManifest($this->base, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetModules()
|
|
|
|
{
|
|
|
|
$modules = $this->manifest->getModules();
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
2017-03-28 21:19:48 +02:00
|
|
|
'silverstripe/root-module',
|
2017-03-14 03:20:51 +01:00
|
|
|
'module',
|
|
|
|
'silverstripe/awesome-module',
|
|
|
|
],
|
|
|
|
array_keys($modules)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLegacyModule()
|
|
|
|
{
|
|
|
|
$module = $this->manifest->getModule('module');
|
|
|
|
$this->assertNotEmpty($module);
|
|
|
|
$this->assertEquals('module', $module->getName());
|
|
|
|
$this->assertEquals('module', $module->getShortName());
|
|
|
|
$this->assertEquals('module', $module->getRelativePath());
|
|
|
|
$this->assertEmpty($module->getComposerName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetComposerModule()
|
|
|
|
{
|
|
|
|
// Get by installer-name (folder)
|
|
|
|
$moduleByShortName = $this->manifest->getModule('moduleb');
|
|
|
|
$this->assertNotEmpty($moduleByShortName);
|
|
|
|
|
|
|
|
// Can also get this by full composer name
|
|
|
|
$module = $this->manifest->getModule('silverstripe/awesome-module');
|
|
|
|
$this->assertNotEmpty($module);
|
|
|
|
$this->assertEquals($moduleByShortName->getPath(), $module->getPath());
|
|
|
|
|
|
|
|
// correctly respects vendor
|
|
|
|
$this->assertEmpty($this->manifest->getModule('wrongvendor/awesome-module'));
|
|
|
|
$this->assertEmpty($this->manifest->getModule('wrongvendor/moduleb'));
|
|
|
|
|
|
|
|
// Properties of module
|
|
|
|
$this->assertEquals('silverstripe/awesome-module', $module->getName());
|
|
|
|
$this->assertEquals('silverstripe/awesome-module', $module->getComposerName());
|
|
|
|
$this->assertEquals('moduleb', $module->getShortName());
|
|
|
|
$this->assertEquals('moduleb', $module->getRelativePath());
|
|
|
|
}
|
2017-03-23 21:58:54 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: Tests experimental API
|
|
|
|
* @internal
|
|
|
|
*/
|
2017-03-28 21:19:48 +02:00
|
|
|
public function testGetResourcePath()
|
2017-03-23 21:58:54 +01:00
|
|
|
{
|
|
|
|
$module = $this->manifest->getModule('moduleb');
|
|
|
|
$this->assertTrue($module->hasResource('composer.json'));
|
|
|
|
$this->assertFalse($module->hasResource('package.json'));
|
|
|
|
$this->assertEquals(
|
|
|
|
'moduleb/composer.json',
|
2017-03-28 06:22:30 +02:00
|
|
|
$module->getResourcePath('composer.json')
|
2017-03-23 21:58:54 +01:00
|
|
|
);
|
|
|
|
}
|
2017-03-28 21:19:48 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: Tests experimental API
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
public function testGetResourcePathOnRoot()
|
|
|
|
{
|
|
|
|
$module = $this->manifest->getModule('silverstripe/root-module');
|
|
|
|
$this->assertTrue($module->hasResource('composer.json'));
|
|
|
|
$this->assertEquals(
|
|
|
|
'composer.json',
|
|
|
|
$module->getResourcePath('composer.json')
|
|
|
|
);
|
|
|
|
}
|
2017-03-14 03:20:51 +01:00
|
|
|
}
|