2011-11-27 10:49:42 +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-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;
|
|
|
|
|
2011-11-27 10:49:42 +01:00
|
|
|
/**
|
2016-09-09 08:43:05 +02:00
|
|
|
* Tests for the {@link ClassManifest} class.
|
2011-11-27 10:49:42 +01:00
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
class ClassLoaderTest extends SapphireTest
|
|
|
|
{
|
2011-11-27 10:49:42 +01:00
|
|
|
|
2017-03-14 03:20:51 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $baseManifest1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $baseManifest2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ClassManifest
|
|
|
|
*/
|
|
|
|
protected $testManifest1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ClassManifest
|
|
|
|
*/
|
|
|
|
protected $testManifest2;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
protected function setUp(): void
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
$this->baseManifest1 = __DIR__ . '/fixtures/classmanifest';
|
|
|
|
$this->baseManifest2 = __DIR__ . '/fixtures/classmanifest_other';
|
|
|
|
$this->testManifest1 = new ClassManifest($this->baseManifest1);
|
|
|
|
$this->testManifest2 = new ClassManifest($this->baseManifest2);
|
|
|
|
$this->testManifest1->init();
|
|
|
|
$this->testManifest2->init();
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2011-11-27 10:49:42 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testExclusive()
|
|
|
|
{
|
|
|
|
$loader = new ClassLoader();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$loader->pushManifest($this->testManifest1);
|
|
|
|
$this->assertTrue((bool)$loader->getItemPath('ClassA'));
|
|
|
|
$this->assertFalse((bool)$loader->getItemPath('OtherClassA'));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$loader->pushManifest($this->testManifest2);
|
|
|
|
$this->assertFalse((bool)$loader->getItemPath('ClassA'));
|
|
|
|
$this->assertTrue((bool)$loader->getItemPath('OtherClassA'));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$loader->popManifest();
|
|
|
|
$loader->pushManifest($this->testManifest2, false);
|
|
|
|
$this->assertTrue((bool)$loader->getItemPath('ClassA'));
|
|
|
|
$this->assertTrue((bool)$loader->getItemPath('OtherClassA'));
|
|
|
|
}
|
2011-11-27 10:49:42 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testGetItemPath()
|
|
|
|
{
|
|
|
|
$loader = new ClassLoader();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$loader->pushManifest($this->testManifest1);
|
|
|
|
$this->assertEquals(
|
|
|
|
realpath($this->baseManifest1 . '/module/classes/ClassA.php'),
|
|
|
|
realpath($loader->getItemPath('ClassA'))
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
false,
|
|
|
|
$loader->getItemPath('UnknownClass')
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
false,
|
|
|
|
$loader->getItemPath('OtherClassA')
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$loader->pushManifest($this->testManifest2);
|
|
|
|
$this->assertEquals(
|
|
|
|
false,
|
|
|
|
$loader->getItemPath('ClassA')
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
false,
|
|
|
|
$loader->getItemPath('UnknownClass')
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
realpath($this->baseManifest2 . '/module/classes/OtherClassA.php'),
|
|
|
|
realpath($loader->getItemPath('OtherClassA'))
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|