2011-12-17 02:03:53 +01:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
namespace SilverStripe\Core\Tests\Manifest;
|
|
|
|
|
2017-09-19 06:55:39 +02:00
|
|
|
use SilverStripe\Admin\ModelAdmin;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\ClassInfo;
|
2016-09-09 08:43:05 +02:00
|
|
|
use SilverStripe\Core\Manifest\ClassManifest;
|
|
|
|
use SilverStripe\Core\Manifest\ClassLoader;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2016-12-16 05:34:21 +01:00
|
|
|
use ReflectionMethod;
|
2017-09-19 06:55:39 +02:00
|
|
|
use SilverStripe\Security\PermissionProvider;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2011-12-17 02:03:53 +01:00
|
|
|
/**
|
2016-09-09 08:43:05 +02:00
|
|
|
* Tests for the {@link ClassManifest} class.
|
2011-12-17 02:03:53 +01:00
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
class NamespacedClassManifestTest extends SapphireTest
|
|
|
|
{
|
2017-03-14 03:20:51 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
protected $base;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ClassManifest
|
|
|
|
*/
|
|
|
|
protected $manifest;
|
|
|
|
|
2017-03-24 04:00:54 +01:00
|
|
|
protected function setUp()
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->base = dirname(__FILE__) . '/fixtures/namespaced_classmanifest';
|
2017-06-22 12:50:45 +02:00
|
|
|
$this->manifest = new ClassManifest($this->base);
|
|
|
|
$this->manifest->init();
|
2017-05-19 04:38:06 +02:00
|
|
|
ClassLoader::inst()->pushManifest($this->manifest, false);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
2017-03-24 04:00:54 +01:00
|
|
|
protected function tearDown()
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::tearDown();
|
2017-05-19 04:38:06 +02:00
|
|
|
ClassLoader::inst()->popManifest();
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testClassInfoIsCorrect()
|
|
|
|
{
|
2017-09-19 06:55:39 +02:00
|
|
|
$this->assertContains(
|
|
|
|
'SilverStripe\\Framework\\Tests\\ClassI',
|
|
|
|
ClassInfo::implementorsOf(PermissionProvider::class)
|
|
|
|
);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2017-03-14 03:20:51 +01:00
|
|
|
// because we're using a nested manifest we have to "coalesce" the descendants again to correctly populate the
|
2016-12-16 05:34:21 +01:00
|
|
|
// descendants of the core classes we want to test against - this is a limitation of the test manifest not
|
|
|
|
// including all core classes
|
|
|
|
$method = new ReflectionMethod($this->manifest, 'coalesceDescendants');
|
|
|
|
$method->setAccessible(true);
|
2017-09-19 06:55:39 +02:00
|
|
|
$method->invoke($this->manifest, ModelAdmin::class);
|
|
|
|
$this->assertContains('SilverStripe\\Framework\\Tests\\ClassI', ClassInfo::subclassesFor(ModelAdmin::class));
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetItemPath()
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
$expect = [
|
2017-09-19 06:55:39 +02:00
|
|
|
'SILVERSTRIPE\\TEST\\CLASSA' => 'module/classes/ClassA.php',
|
|
|
|
'Silverstripe\\Test\\ClassA' => 'module/classes/ClassA.php',
|
|
|
|
'silverstripe\\test\\classa' => 'module/classes/ClassA.php',
|
|
|
|
'SILVERSTRIPE\\TEST\\INTERFACEA' => 'module/interfaces/InterfaceA.php',
|
|
|
|
'Silverstripe\\Test\\InterfaceA' => 'module/interfaces/InterfaceA.php',
|
|
|
|
'silverstripe\\test\\interfacea' => 'module/interfaces/InterfaceA.php'
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
foreach ($expect as $name => $path) {
|
|
|
|
$this->assertEquals("{$this->base}/$path", $this->manifest->getItemPath($name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetClasses()
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
$expect = [
|
2017-09-19 06:55:39 +02:00
|
|
|
'silverstripe\\test\\classa' => "{$this->base}/module/classes/ClassA.php",
|
|
|
|
'silverstripe\\test\\classb' => "{$this->base}/module/classes/ClassB.php",
|
|
|
|
'silverstripe\\test\\classc' => "{$this->base}/module/classes/ClassC.php",
|
|
|
|
'silverstripe\\test\\classd' => "{$this->base}/module/classes/ClassD.php",
|
|
|
|
'silverstripe\\test\\classe' => "{$this->base}/module/classes/ClassE.php",
|
|
|
|
'silverstripe\\test\\classf' => "{$this->base}/module/classes/ClassF.php",
|
|
|
|
'silverstripe\\test\\classg' => "{$this->base}/module/classes/ClassG.php",
|
|
|
|
'silverstripe\\test\\classh' => "{$this->base}/module/classes/ClassH.php",
|
|
|
|
'silverstripe\\framework\\tests\\classi' => "{$this->base}/module/classes/ClassI.php",
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$this->assertEquals($expect, $this->manifest->getClasses());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetClassNames()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
2017-09-19 06:55:39 +02:00
|
|
|
[
|
|
|
|
'silverstripe\\test\\classa' => 'silverstripe\\test\\ClassA',
|
|
|
|
'silverstripe\\test\\classb' => 'silverstripe\\test\\ClassB',
|
|
|
|
'silverstripe\\test\\classc' => 'silverstripe\\test\\ClassC',
|
|
|
|
'silverstripe\\test\\classd' => 'silverstripe\\test\\ClassD',
|
|
|
|
'silverstripe\\test\\classe' => 'silverstripe\\test\\ClassE',
|
|
|
|
'silverstripe\\test\\classf' => 'silverstripe\\test\\ClassF',
|
|
|
|
'silverstripe\\test\\classg' => 'silverstripe\\test\\ClassG',
|
|
|
|
'silverstripe\\test\\classh' => 'silverstripe\\test\\ClassH',
|
|
|
|
'silverstripe\\framework\\tests\\classi' => 'SilverStripe\\Framework\\Tests\\ClassI',
|
|
|
|
],
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->manifest->getClassNames()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDescendants()
|
|
|
|
{
|
2017-09-19 06:55:39 +02:00
|
|
|
$expect = [
|
|
|
|
'silverstripe\\test\\classa' => [
|
|
|
|
'silverstripe\\test\\classb' => 'silverstripe\test\ClassB',
|
|
|
|
'silverstripe\\test\\classh' => 'silverstripe\test\ClassH',
|
|
|
|
],
|
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$this->assertEquals($expect, $this->manifest->getDescendants());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDescendantsOf()
|
|
|
|
{
|
2017-09-19 06:55:39 +02:00
|
|
|
$expect = [
|
|
|
|
'SILVERSTRIPE\\TEST\\CLASSA' => [
|
|
|
|
'silverstripe\\test\\classb' => 'silverstripe\test\ClassB',
|
|
|
|
'silverstripe\\test\\classh' => 'silverstripe\test\ClassH',
|
|
|
|
],
|
|
|
|
'silverstripe\\test\\classa' => [
|
|
|
|
'silverstripe\\test\\classb' => 'silverstripe\test\ClassB',
|
|
|
|
'silverstripe\\test\\classh' => 'silverstripe\test\ClassH',
|
|
|
|
],
|
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
foreach ($expect as $class => $desc) {
|
|
|
|
$this->assertEquals($desc, $this->manifest->getDescendantsOf($class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInterfaces()
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
$expect = [
|
2017-09-19 06:55:39 +02:00
|
|
|
'silverstripe\\test\\interfacea' => "{$this->base}/module/interfaces/InterfaceA.php",
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals($expect, $this->manifest->getInterfaces());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetImplementors()
|
|
|
|
{
|
2017-09-19 06:55:39 +02:00
|
|
|
$expect = [
|
|
|
|
'silverstripe\\test\\interfacea' => [
|
|
|
|
'silverstripe\\test\\classe' => 'silverstripe\\test\\ClassE',
|
|
|
|
],
|
|
|
|
'interfacea' => [
|
|
|
|
'silverstripe\\test\\classf' => 'silverstripe\\test\\ClassF',
|
|
|
|
],
|
|
|
|
'silverstripe\\test\\subtest\\interfacea' => [
|
|
|
|
'silverstripe\\test\\classg' => 'silverstripe\\test\\ClassG',
|
|
|
|
],
|
|
|
|
'silverstripe\\security\\permissionprovider' => [
|
|
|
|
'silverstripe\\framework\\tests\\classi' => 'SilverStripe\\Framework\\Tests\\ClassI',
|
|
|
|
],
|
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals($expect, $this->manifest->getImplementors());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetImplementorsOf()
|
|
|
|
{
|
2017-09-19 06:55:39 +02:00
|
|
|
$expect = [
|
|
|
|
'SILVERSTRIPE\\TEST\\INTERFACEA' => [
|
|
|
|
'silverstripe\\test\\classe' => 'silverstripe\\test\\ClassE',
|
|
|
|
],
|
|
|
|
'silverstripe\\test\\interfacea' => [
|
|
|
|
'silverstripe\\test\\classe' => 'silverstripe\\test\\ClassE',
|
|
|
|
],
|
|
|
|
'INTERFACEA' => [
|
|
|
|
'silverstripe\\test\\classf' => 'silverstripe\\test\\ClassF',
|
|
|
|
],
|
|
|
|
'interfacea' => [
|
|
|
|
'silverstripe\\test\\classf' => 'silverstripe\\test\\ClassF',
|
|
|
|
],
|
|
|
|
'SILVERSTRIPE\\TEST\\SUBTEST\\INTERFACEA' => [
|
|
|
|
'silverstripe\\test\\classg' => 'silverstripe\\test\\ClassG',
|
|
|
|
],
|
|
|
|
'silverstripe\\test\\subtest\\interfacea' => [
|
|
|
|
'silverstripe\\test\\classg' => 'silverstripe\\test\\ClassG',
|
|
|
|
],
|
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
foreach ($expect as $interface => $impl) {
|
|
|
|
$this->assertEquals($impl, $this->manifest->getImplementorsOf($interface));
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 04:38:57 +01:00
|
|
|
}
|