2011-02-27 12:20:20 +01:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
namespace SilverStripe\Core\Tests\Manifest;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\Manifest\ManifestFileFinder;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2011-02-27 12:20:20 +01:00
|
|
|
/**
|
|
|
|
* Tests for the {@link ManifestFileFinder} class.
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
class ManifestFileFinderTest extends SapphireTest
|
|
|
|
{
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
protected $base;
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
2017-05-10 11:24:12 +02:00
|
|
|
$this->defaultBase = dirname(__FILE__) . '/fixtures/manifestfilefinder';
|
2016-12-16 05:34:21 +01:00
|
|
|
parent::__construct();
|
|
|
|
}
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2017-05-10 11:24:12 +02:00
|
|
|
public function assertFinderFinds($finder, $base, $expect, $message = null)
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
2017-05-10 11:24:12 +02:00
|
|
|
if (!$base) {
|
|
|
|
$base = $this->defaultBase;
|
|
|
|
}
|
|
|
|
|
|
|
|
$found = $finder->find($base);
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
foreach ($expect as $k => $file) {
|
2017-05-10 11:24:12 +02:00
|
|
|
$expect[$k] = "{$base}/$file";
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
sort($expect);
|
|
|
|
sort($found);
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals($expect, $found, $message);
|
|
|
|
}
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testBasicOperation()
|
|
|
|
{
|
|
|
|
$finder = new ManifestFileFinder();
|
|
|
|
$finder->setOption('name_regex', '/\.txt$/');
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertFinderFinds(
|
|
|
|
$finder,
|
2017-05-10 11:24:12 +02:00
|
|
|
null,
|
2016-12-16 05:34:21 +01:00
|
|
|
array(
|
|
|
|
'module/module.txt'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testIgnoreTests()
|
|
|
|
{
|
|
|
|
$finder = new ManifestFileFinder();
|
|
|
|
$finder->setOption('name_regex', '/\.txt$/');
|
|
|
|
$finder->setOption('ignore_tests', false);
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertFinderFinds(
|
|
|
|
$finder,
|
2017-05-10 11:24:12 +02:00
|
|
|
null,
|
2016-12-16 05:34:21 +01:00
|
|
|
array(
|
|
|
|
'module/module.txt',
|
|
|
|
'module/tests/tests.txt',
|
|
|
|
'module/code/tests/tests2.txt'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testIncludeThemes()
|
|
|
|
{
|
|
|
|
$finder = new ManifestFileFinder();
|
|
|
|
$finder->setOption('name_regex', '/\.txt$/');
|
|
|
|
$finder->setOption('include_themes', true);
|
2011-02-27 12:20:20 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertFinderFinds(
|
|
|
|
$finder,
|
2017-05-10 11:24:12 +02:00
|
|
|
null,
|
2016-12-16 05:34:21 +01:00
|
|
|
array(
|
|
|
|
'module/module.txt',
|
|
|
|
'themes/themes.txt'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2017-05-10 11:24:12 +02:00
|
|
|
|
|
|
|
public function testIncludeWithRootConfigFile()
|
|
|
|
{
|
|
|
|
$finder = new ManifestFileFinder();
|
|
|
|
|
|
|
|
$this->assertFinderFinds(
|
|
|
|
$finder,
|
|
|
|
dirname(__FILE__) . '/fixtures/manifestfilefinder_rootconfigfile',
|
|
|
|
array(
|
|
|
|
'code/code.txt',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIncludeWithRootConfigFolder()
|
|
|
|
{
|
|
|
|
$finder = new ManifestFileFinder();
|
|
|
|
|
|
|
|
$this->assertFinderFinds(
|
|
|
|
$finder,
|
|
|
|
dirname(__FILE__) . '/fixtures/manifestfilefinder_rootconfigfolder',
|
|
|
|
array(
|
|
|
|
'code/code.txt',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|