2011-03-24 21:30:57 +11:00
|
|
|
<?php
|
2016-07-14 00:36:52 +12:00
|
|
|
|
2016-12-16 17:34:21 +13:00
|
|
|
namespace SilverStripe\Core\Tests\Manifest;
|
|
|
|
|
2017-09-21 17:54:06 +12:00
|
|
|
use SilverStripe\Control\Director;
|
2017-07-13 10:27:27 +12:00
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
2016-07-19 14:09:15 +12:00
|
|
|
use SilverStripe\View\ThemeResourceLoader;
|
2016-07-14 00:36:52 +12:00
|
|
|
use SilverStripe\View\ThemeManifest;
|
2016-08-19 10:51:35 +12:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-07-13 10:27:27 +12:00
|
|
|
use SilverStripe\Core\Manifest\ModuleManifest;
|
2024-09-18 13:53:44 +12:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2011-03-24 21:30:57 +11:00
|
|
|
/**
|
2016-07-14 00:36:52 +12:00
|
|
|
* Tests for the {@link TemplateLoader} class.
|
2011-03-24 21:30:57 +11:00
|
|
|
*/
|
2016-12-16 17:34:21 +13:00
|
|
|
class ThemeResourceLoaderTest extends SapphireTest
|
|
|
|
{
|
2017-03-14 15:20:51 +13:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-12-16 17:34:21 +13:00
|
|
|
private $base;
|
2016-07-19 13:17:07 +12:00
|
|
|
|
2016-12-16 17:34:21 +13:00
|
|
|
/**
|
|
|
|
* @var ThemeManifest
|
|
|
|
*/
|
|
|
|
private $manifest;
|
2014-08-15 18:53:05 +12:00
|
|
|
|
2016-12-16 17:34:21 +13:00
|
|
|
/**
|
|
|
|
* @var ThemeResourceLoader
|
|
|
|
*/
|
|
|
|
private $loader;
|
2016-07-19 14:09:15 +12:00
|
|
|
|
2016-12-16 17:34:21 +13:00
|
|
|
/**
|
|
|
|
* Set up manifest before each test
|
|
|
|
*/
|
2021-10-27 15:39:47 +13:00
|
|
|
protected function setUp(): void
|
2016-12-16 17:34:21 +13:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2014-08-15 18:53:05 +12:00
|
|
|
|
2016-12-16 17:34:21 +13:00
|
|
|
// Fake project root
|
|
|
|
$this->base = dirname(__FILE__) . '/fixtures/templatemanifest';
|
2017-09-21 17:54:06 +12:00
|
|
|
Director::config()->set('alternate_base_folder', $this->base);
|
2017-07-13 10:27:27 +12:00
|
|
|
ModuleManifest::config()->set('module_priority', ['$project', '$other_modules']);
|
|
|
|
ModuleManifest::config()->set('project', 'myproject');
|
|
|
|
|
|
|
|
$moduleManifest = new ModuleManifest($this->base);
|
|
|
|
$moduleManifest->init();
|
|
|
|
$moduleManifest->sort();
|
|
|
|
ModuleLoader::inst()->pushManifest($moduleManifest);
|
|
|
|
|
2016-12-16 17:34:21 +13:00
|
|
|
// New ThemeManifest for that root
|
2017-07-13 10:27:27 +12:00
|
|
|
$this->manifest = new ThemeManifest($this->base);
|
|
|
|
$this->manifest->setProject('myproject');
|
2017-06-22 22:50:45 +12:00
|
|
|
$this->manifest->init();
|
2016-12-16 17:34:21 +13:00
|
|
|
// New Loader for that root
|
|
|
|
$this->loader = new ThemeResourceLoader($this->base);
|
|
|
|
$this->loader->addSet('$default', $this->manifest);
|
2018-10-04 17:49:35 +02:00
|
|
|
|
2018-10-05 14:58:48 +02:00
|
|
|
// Ensure the cache is flushed between tests
|
|
|
|
ThemeResourceLoader::flush();
|
2016-12-16 17:34:21 +13:00
|
|
|
}
|
2016-07-14 00:36:52 +12:00
|
|
|
|
2021-10-27 15:39:47 +13:00
|
|
|
protected function tearDown(): void
|
2017-07-13 10:27:27 +12:00
|
|
|
{
|
|
|
|
ModuleLoader::inst()->popManifest();
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2016-12-16 17:34:21 +13:00
|
|
|
public function testFindThemedCSS()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
"myproject/css/project.css",
|
|
|
|
$this->loader->findThemedCSS('project', ['$default', 'theme'])
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
"themes/theme/css/project.css",
|
|
|
|
$this->loader->findThemedCSS('project', ['theme', '$default'])
|
|
|
|
);
|
|
|
|
$this->assertEmpty(
|
|
|
|
$this->loader->findThemedCSS('nofile', ['theme', '$default'])
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'module/css/content.css',
|
|
|
|
$this->loader->findThemedCSS('content', ['/module', 'theme'])
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'module/css/content.css',
|
|
|
|
$this->loader->findThemedCSS('content', ['/module', 'theme', '$default'])
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'module/css/content.css',
|
|
|
|
$this->loader->findThemedCSS('content', ['$default', '/module', 'theme'])
|
|
|
|
);
|
|
|
|
}
|
2016-07-19 14:09:15 +12:00
|
|
|
|
2016-12-16 17:34:21 +13:00
|
|
|
public function testFindThemedJavascript()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
"myproject/javascript/project.js",
|
|
|
|
$this->loader->findThemedJavascript('project', ['$default', 'theme'])
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
"themes/theme/javascript/project.js",
|
|
|
|
$this->loader->findThemedJavascript('project', ['theme', '$default'])
|
|
|
|
);
|
|
|
|
$this->assertEmpty(
|
|
|
|
$this->loader->findThemedJavascript('nofile', ['theme', '$default'])
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'module/javascript/content.js',
|
|
|
|
$this->loader->findThemedJavascript('content', ['/module', 'theme'])
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'module/javascript/content.js',
|
|
|
|
$this->loader->findThemedJavascript('content', ['/module', 'theme', '$default'])
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'module/javascript/content.js',
|
|
|
|
$this->loader->findThemedJavascript('content', ['$default', '/module', 'theme'])
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 18:53:05 +12:00
|
|
|
|
2024-09-18 13:53:44 +12:00
|
|
|
public static function providerTestGetPath()
|
2017-09-21 17:54:06 +12:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
// Legacy theme
|
|
|
|
[
|
|
|
|
'theme',
|
|
|
|
'themes/theme',
|
|
|
|
],
|
|
|
|
// Module themes
|
|
|
|
[
|
|
|
|
'silverstripe/vendormodule:vendortheme',
|
|
|
|
'vendor/silverstripe/vendormodule/themes/vendortheme',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'module:subtheme',
|
|
|
|
'module/themes/subtheme',
|
|
|
|
],
|
|
|
|
// Module absolute paths
|
|
|
|
[
|
|
|
|
'silverstripe/vendormodule:/themes/vendortheme',
|
|
|
|
'vendor/silverstripe/vendormodule/themes/vendortheme',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'module:/themes/subtheme',
|
|
|
|
'module/themes/subtheme',
|
|
|
|
],
|
|
|
|
// Module root directory
|
|
|
|
[
|
|
|
|
'silverstripe/vendormodule:/',
|
|
|
|
'vendor/silverstripe/vendormodule',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'silverstripe/vendormodule:',
|
|
|
|
'vendor/silverstripe/vendormodule',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'silverstripe/vendormodule',
|
|
|
|
'vendor/silverstripe/vendormodule',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'module:',
|
|
|
|
'module',
|
|
|
|
],
|
|
|
|
// Absolute paths
|
|
|
|
[
|
|
|
|
'/vendor/silverstripe/vendormodule/themes/vendortheme',
|
|
|
|
'vendor/silverstripe/vendormodule/themes/vendortheme',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'/module/themes/subtheme',
|
|
|
|
'module/themes/subtheme'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name Theme identifier
|
|
|
|
* @param string $path Path to theme
|
|
|
|
*/
|
2024-09-18 13:53:44 +12:00
|
|
|
#[DataProvider('providerTestGetPath')]
|
2017-09-21 17:54:06 +12:00
|
|
|
public function testGetPath($name, $path)
|
|
|
|
{
|
|
|
|
$this->assertEquals($path, $this->loader->getPath($name));
|
|
|
|
}
|
2012-03-24 16:04:52 +13:00
|
|
|
}
|