Root-level module support in Module->getResourcePath()

See https://github.com/silverstripe/silverstripe-framework/pull/6733
This commit is contained in:
Ingo Schommer 2017-03-29 08:19:48 +13:00 committed by Damian Mooyman
parent 59ee2c1037
commit ac9d645e4e
4 changed files with 28 additions and 4 deletions

View File

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

View File

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