Merge pull request #6750 from open-sausages/pulls/4.0/fix-module-resource-trim

Root-level module support in Module->getResourcePath()
This commit is contained in:
Damian Mooyman 2017-03-29 10:44:16 +13:00 committed by GitHub
commit 1aa2677353
4 changed files with 28 additions and 4 deletions

View File

@ -162,9 +162,9 @@ class Module implements Serializable
*/ */
public function getResourcePath($path) public function getResourcePath($path)
{ {
$base = rtrim($this->getRelativePath(), '/\\'); $base = trim($this->getRelativePath(), '/\\');
$path = rtrim($path, '/\\'); $path = trim($path, '/\\');
return "{$base}/{$path}"; return trim("{$base}/{$path}", '/\\');
} }
/** /**

View File

@ -31,6 +31,7 @@ class ModuleManifestTest extends SapphireTest
$modules = $this->manifest->getModules(); $modules = $this->manifest->getModules();
$this->assertEquals( $this->assertEquals(
[ [
'silverstripe/root-module',
'module', 'module',
'silverstripe/awesome-module', 'silverstripe/awesome-module',
], ],
@ -74,7 +75,7 @@ class ModuleManifestTest extends SapphireTest
* Note: Tests experimental API * Note: Tests experimental API
* @internal * @internal
*/ */
public function testGetResource() public function testGetResourcePath()
{ {
$module = $this->manifest->getModule('moduleb'); $module = $this->manifest->getModule('moduleb');
$this->assertTrue($module->hasResource('composer.json')); $this->assertTrue($module->hasResource('composer.json'));
@ -84,4 +85,18 @@ class ModuleManifestTest extends SapphireTest
$module->getResourcePath('composer.json') $module->getResourcePath('composer.json')
); );
} }
/*
* 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')
);
}
} }

View File

@ -0,0 +1 @@
<?php

View File

@ -0,0 +1,8 @@
{
"name": "silverstripe/root-module",
"description": "dummy test module",
"require": {},
"extra": {
"installer-name": "root-module"
}
}