silverstripe-framework/tests/php/Core/Manifest/ModuleResourceTest.php
Maxime Rainville 1e01deea39 NEW Make resources dir configurable (#8519)
* NEW Make resources dir configurable.

* Removing reference to old `resources` and updating doc #8519

* Rrtarget to 4.4 release.

* DOC Reference SS_RESOURCES_DIR in Environment doc.

* API Add a Resources method to SilverStripe\Core\Manifest\Module to read the resources-dir from composer.json

* Clean up reference to SS_RESOURCES_DIR env var

* Set default resources-dir

* Update test to use RESOURCES_DIR const in expected resource url method

* Correcting typos

Co-Authored-By: maxime-rainville <maxime@rainville.me>

* MINOR Correctubg minor typos

* DOCS Document the intricacies of exposing static assets.
2019-01-09 15:35:45 +13:00

88 lines
2.8 KiB
PHP

<?php
namespace SilverStripe\Core\Tests\Manifest;
use SilverStripe\Control\Director;
use SilverStripe\Core\Manifest\ModuleManifest;
use SilverStripe\Dev\SapphireTest;
class ModuleResourceTest extends SapphireTest
{
/**
* @var string
*/
protected $base;
/**
* @var ModuleManifest
*/
protected $manifest;
protected function setUp()
{
parent::setUp();
$this->base = dirname(__FILE__) . '/fixtures/classmanifest';
$this->manifest = new ModuleManifest($this->base);
$this->manifest->init();
Director::config()->set('alternate_base_url', 'http://www.mysite.com/basefolder/');
Director::config()->set('alternate_public_dir', 'public');
}
public function testBaseModuleResource()
{
$modulea = $this->manifest->getModule('module');
$resource = $modulea->getResource('client/script.js');
// Test main resource
$this->assertTrue($resource->exists());
$this->assertEquals('module/client/script.js', $resource->getRelativePath());
$this->assertEquals(
__DIR__ . '/fixtures/classmanifest/module/client/script.js',
$resource->getPath()
);
$this->assertStringStartsWith(
'/basefolder/'. RESOURCES_DIR . '/module/client/script.js?m=',
$resource->getURL()
);
}
public function testVendorModuleResources()
{
$modulec = $this->manifest->getModule('silverstripe/modulec');
$resource = $modulec->getResource('client/script.js');
// Test main resource
$this->assertTrue($resource->exists());
$this->assertEquals('vendor/silverstripe/modulec/client/script.js', $resource->getRelativePath());
$this->assertEquals(
__DIR__ . '/fixtures/classmanifest/vendor/silverstripe/modulec/client/script.js',
$resource->getPath()
);
$this->assertStringStartsWith(
'/basefolder/'. RESOURCES_DIR . '/vendor/silverstripe/modulec/client/script.js?m=',
$resource->getURL()
);
}
public function testRelativeResources()
{
$modulec = $this->manifest->getModule('silverstripe/modulec');
$resource = $modulec
->getResource('client')
->getRelativeResource('script.js');
// Test main resource
$this->assertTrue($resource->exists());
$this->assertEquals('vendor/silverstripe/modulec/client/script.js', $resource->getRelativePath());
$this->assertEquals(
__DIR__ . '/fixtures/classmanifest/vendor/silverstripe/modulec/client/script.js',
$resource->getPath()
);
$this->assertStringStartsWith(
'/basefolder/'. RESOURCES_DIR . '/vendor/silverstripe/modulec/client/script.js?m=',
$resource->getURL()
);
}
}