From ac9d645e4e44aa5671c3920c280a757dc3e25787 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 29 Mar 2017 08:19:48 +1300 Subject: [PATCH] Root-level module support in Module->getResourcePath() See https://github.com/silverstripe/silverstripe-framework/pull/6733 --- src/Core/Manifest/Module.php | 6 +++--- tests/php/Core/Manifest/ModuleManifestTest.php | 17 ++++++++++++++++- .../Manifest/fixtures/classmanifest/_config.php | 1 + .../fixtures/classmanifest/composer.json | 8 ++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tests/php/Core/Manifest/fixtures/classmanifest/_config.php create mode 100644 tests/php/Core/Manifest/fixtures/classmanifest/composer.json diff --git a/src/Core/Manifest/Module.php b/src/Core/Manifest/Module.php index 0d0726830..d806f85cb 100644 --- a/src/Core/Manifest/Module.php +++ b/src/Core/Manifest/Module.php @@ -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}", '/\\'); } /** diff --git a/tests/php/Core/Manifest/ModuleManifestTest.php b/tests/php/Core/Manifest/ModuleManifestTest.php index 5e8d98d37..2bdefa5f5 100644 --- a/tests/php/Core/Manifest/ModuleManifestTest.php +++ b/tests/php/Core/Manifest/ModuleManifestTest.php @@ -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') + ); + } } diff --git a/tests/php/Core/Manifest/fixtures/classmanifest/_config.php b/tests/php/Core/Manifest/fixtures/classmanifest/_config.php new file mode 100644 index 000000000..b3d9bbc7f --- /dev/null +++ b/tests/php/Core/Manifest/fixtures/classmanifest/_config.php @@ -0,0 +1 @@ +