silverstripe-framework/tests/core/manifest/ClassLoaderTest.php

76 lines
2.0 KiB
PHP
Raw Normal View History

<?php
2016-09-09 08:43:05 +02:00
use SilverStripe\Core\Manifest\ClassManifest;
use SilverStripe\Core\Manifest\ClassLoader;
use SilverStripe\Dev\SapphireTest;
/**
2016-09-09 08:43:05 +02:00
* Tests for the {@link ClassManifest} class.
*
* @package framework
* @subpackage tests
*/
class ClassLoaderTest extends SapphireTest {
protected $base;
protected $manifest;
2014-08-15 08:53:05 +02:00
public function setUp() {
parent::setUp();
2014-08-15 08:53:05 +02:00
$this->baseManifest1 = dirname(__FILE__) . '/fixtures/classmanifest';
$this->baseManifest2 = dirname(__FILE__) . '/fixtures/classmanifest_other';
2016-09-09 08:43:05 +02:00
$this->testManifest1 = new ClassManifest($this->baseManifest1, false, true, false);
$this->testManifest2 = new ClassManifest($this->baseManifest2, false, true, false);
}
public function testExclusive() {
2016-09-09 08:43:05 +02:00
$loader = new ClassLoader();
2014-08-15 08:53:05 +02: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
$loader->pushManifest($this->testManifest2);
$this->assertFalse((bool)$loader->getItemPath('ClassA'));
$this->assertTrue((bool)$loader->getItemPath('OtherClassA'));
2014-08-15 08:53:05 +02:00
$loader->popManifest();
$loader->pushManifest($this->testManifest2, false);
$this->assertTrue((bool)$loader->getItemPath('ClassA'));
$this->assertTrue((bool)$loader->getItemPath('OtherClassA'));
}
public function testGetItemPath() {
2016-09-09 08:43:05 +02:00
$loader = new ClassLoader();
2014-08-15 08:53:05 +02: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
$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
}