ResourceSorter.php

<?php

namespace Lia\Test\Addon;

class ResourceSorter extends \Tlf\Tester {

    public function testSortCss(){
        $lia = new \Lia();
        $package = new \Lia\Package($lia, 'test:sorter');
        $res = new \Lia\Addon\Resources($package);
        $sorter = new \Lia\Addon\ResourceSorter($package);
        $res->init_lia();
        $sorter->init_lia();

        $input = [
            'three.css',
            'NotActuallyFirst.css',
            'AppendWherever.css',
            'one.css',
            '2ndAppendWherever.css',
            'two.css',
        ];
        $dir = $this->dir();
        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))
        ;
    }

    public function dir(){
        return $this->cli->pwd.'/test/input/ResourceSorter/';
    }

}