ORIENT/tests/unit/system/classes/CombineAssetsTest.php

105 lines
2.9 KiB
PHP
Raw Normal View History

2014-05-14 13:24:20 +00:00
<?php
use Cms\Classes\Theme;
use System\Classes\CombineAssets;
2014-05-14 13:24:20 +00:00
class CombineAssetsTest extends TestCase
2014-05-14 13:24:20 +00:00
{
public function setUp()
{
parent::setUp();
2014-05-14 13:24:20 +00:00
CombineAssets::resetCache();
}
//
// Tests
//
public function testCombiner()
{
$combiner = CombineAssets::instance();
2014-05-14 13:24:20 +00:00
/*
* Supported file extensions should exist
*/
$jsExt = $cssExt = self::getProtectedProperty($combiner, 'jsExtensions');
$this->assertInternalType('array', $jsExt);
$cssExt = self::getProtectedProperty($combiner, 'cssExtensions');
$this->assertInternalType('array', $cssExt);
/*
* Check service methods
*/
$this->assertTrue(method_exists($combiner, 'combine'));
$this->assertTrue(method_exists($combiner, 'resetCache'));
}
public function testCombine()
{
$combiner = CombineAssets::instance();
2014-05-14 13:24:20 +00:00
$url = $combiner->combine(
[
2015-03-02 08:01:30 +00:00
'assets/css/style1.css',
'assets/css/style2.css'
],
base_path().'/tests/fixtures/themes/test'
);
$this->assertNotNull($url);
$this->assertRegExp('/\w+[-]\d+/i', $url); // Must contain hash-number
$url = $combiner->combine(
[
'assets/js/script1.js',
'assets/js/script2.js'
2015-03-02 08:01:30 +00:00
],
base_path().'/tests/fixtures/themes/test'
);
2014-05-14 13:24:20 +00:00
$this->assertNotNull($url);
2015-03-02 08:01:30 +00:00
$this->assertRegExp('/\w+[-]\d+/i', $url); // Must contain hash-number
2014-05-14 13:24:20 +00:00
}
public function testPutCache()
{
$sampleId = md5('testhash');
$sampleStore = ['version' => 12345678];
$samplePath = '/tests/fixtures/Cms/themes/test';
$combiner = CombineAssets::instance();
2014-05-14 13:24:20 +00:00
$value = self::callProtectedMethod($combiner, 'putCache', [$sampleId, $sampleStore]);
$this->assertTrue($value);
}
public function testGetTargetPath()
{
$combiner = CombineAssets::instance();
$value = self::callProtectedMethod($combiner, 'getTargetPath', ['/combine']);
$this->assertEquals('combine/', $value);
$value = self::callProtectedMethod($combiner, 'getTargetPath', ['/index.php/combine']);
$this->assertEquals('index-php/combine/', $value);
}
2014-05-14 13:24:20 +00:00
public function testMakeCacheId()
{
$sampleResources = ['assets/css/style1.css', 'assets/css/style2.css'];
2015-03-02 08:01:30 +00:00
$samplePath = base_path().'/tests/fixtures/cms/themes/test';
2014-05-14 13:24:20 +00:00
$combiner = CombineAssets::instance();
2015-03-02 08:01:30 +00:00
self::setProtectedProperty($combiner, 'localPath', $samplePath);
2014-05-14 13:24:20 +00:00
2016-06-03 20:13:25 +00:00
$value = self::callProtectedMethod($combiner, 'getCacheKey', [$sampleResources]);
2014-05-14 13:24:20 +00:00
$this->assertEquals(md5($samplePath.implode('|', $sampleResources)), $value);
}
public function testResetCache()
{
$combiner = CombineAssets::instance();
2014-05-14 13:24:20 +00:00
$this->assertNull($combiner->resetCache());
}
2014-09-15 21:36:05 +00:00
}