ResourceSorter.php
<?php
namespace Lia\Test\Compo;
class ResourceSorter extends \Taeluf\Tester {
public function testSortCss(){
$lia = new \Liaison(['bare'=>true]);
$package = new \Liaison\Test\Mock\Package($lia);
$res = new \Lia\Compo\Resources($package);
$sorter = new \Lia\Compo\ResourceSorter($package);
$input = [
'three.css',
'NotActuallyFirst.css',
'AppendWherever.css',
'one.css',
'2ndAppendWherever.css',
'two.css',
];
$dir = dirname(__DIR__).'/extra/ResourceSorter/';
foreach ($input as $if){
$lia->addResourceFile($dir.$if);
}
$lia->setResourceOrder('css',
['NotActuallyFirst.css',
'one.css', 'two.css', 'three.css',
'ResourceSorter/NotActuallyFirst.css'
]
);
$resources = $res->getSortedFiles('css');
$resources = array_map(function($f){return basename(dirname($f)).'/'.basename($f);}
,$resources);
$target = [
'one.css',
'two.css',
'three.css',
'NotActuallyFirst.css',
];
$target = array_map(function($f){return 'ResourceSorter/'.$f;}
,$target);
$actualSorted = array_slice($resources,0,4);
return true
&& $this->test('Sorts files correctly')
&& $this->compare($target, $actualSorted)
&& $this->test('Has unsorted files, too')
&& $this->compare(6, count($resources))
;
}
}
ResourceSorter::runAll();