2017-11-11 07:22:27 +01:00
|
|
|
<?php
|
|
|
|
namespace Todaymade\Daux\Tree;
|
2015-10-28 00:01:41 +01:00
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
use Todaymade\Daux\Daux;
|
|
|
|
use Todaymade\Daux\ConfigBuilder;
|
2017-11-11 07:22:27 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2015-10-28 00:01:41 +01:00
|
|
|
|
2017-11-11 07:22:27 +01:00
|
|
|
class DirectoryTest extends TestCase
|
2016-07-27 21:32:51 +02:00
|
|
|
{
|
2015-10-28 00:01:41 +01:00
|
|
|
public function providerSort()
|
|
|
|
{
|
2016-07-27 21:32:51 +02:00
|
|
|
return [
|
|
|
|
[['005_Fifth', '01_First'], ['01_First', '005_Fifth']],
|
|
|
|
[['005_Fifth', 'Another', '01_First'], ['01_First', '005_Fifth', 'Another']],
|
|
|
|
[['005_Fifth', 'Another', '-Sticky', '01_First'], ['01_First', '005_Fifth', 'Another', '-Sticky']],
|
|
|
|
[['01_before', '-Down'], ['01_before', '-Down']],
|
|
|
|
[['01_before', '-Down-after', '-Down'], ['01_before', '-Down', '-Down-after']],
|
|
|
|
[['01_numeric', '01_before'], ['01_before', '01_numeric']],
|
|
|
|
[['A_File', '01_A_File'], ['01_A_File', 'A_File']],
|
|
|
|
[['A_File', '01_Continuing', '-01_Coming', '-02_Soon'], ['01_Continuing', 'A_File', '-01_Coming', '-02_Soon']],
|
2017-11-08 21:49:30 +01:00
|
|
|
[['+A_File', '01_Continuing', '+01_Coming', '-02_Soon'], ['+01_Coming', '+A_File', '01_Continuing', '-02_Soon']],
|
2016-07-27 21:32:51 +02:00
|
|
|
[['01_Getting_Started', 'API_Calls', '200_Something_Else-Cool', '_5_Ways_to_Be_Happy'], ['01_Getting_Started', '200_Something_Else-Cool', '_5_Ways_to_Be_Happy', 'API_Calls']],
|
|
|
|
[['01_Getting_Started', 'API_Calls', 'index', '200_Something_Else-Cool', '_5_Ways_to_Be_Happy'], ['index', '01_Getting_Started', '200_Something_Else-Cool', '_5_Ways_to_Be_Happy', 'API_Calls']],
|
|
|
|
[['Before_but_after', 'A_File', 'Continuing'], ['A_File', 'Before_but_after', 'Continuing']],
|
|
|
|
[['01_GitHub_Flavored_Markdown', 'Code_Test', '05_Code_Highlighting'], ['01_GitHub_Flavored_Markdown', '05_Code_Highlighting', 'Code_Test']],
|
|
|
|
];
|
2015-10-28 00:01:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerSort
|
|
|
|
*/
|
|
|
|
public function testSort($list, $expected)
|
|
|
|
{
|
|
|
|
shuffle($list);
|
2016-07-27 23:27:51 +02:00
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
$config = ConfigBuilder::withMode()
|
|
|
|
->build();
|
2016-07-27 23:27:51 +02:00
|
|
|
|
|
|
|
$directory = new Directory(new Root($config), 'dir');
|
2015-10-28 00:01:41 +01:00
|
|
|
|
|
|
|
foreach ($list as $value) {
|
|
|
|
$entry = new Content($directory, $value);
|
|
|
|
$entry->setName($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$directory->sort();
|
|
|
|
|
|
|
|
$final = [];
|
|
|
|
foreach ($directory->getEntries() as $obj) {
|
|
|
|
$final[] = $obj->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $final);
|
|
|
|
}
|
|
|
|
}
|