Blame view

framework/tests/core/manifest/NamespacedClassManifestTest.php 4.36 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  <?php
  /**
   * Tests for the {@link SS_ClassManifest} class.
   *
   * @package framework
   * @subpackage tests
   */
  class NamespacedClassManifestTest extends SapphireTest {
  
  	protected $base;
  	protected $manifest;
  
  	public function setUp() {
  		parent::setUp();
  
  		$this->base = dirname(__FILE__) . '/fixtures/namespaced_classmanifest';
  		$this->manifest      = new SS_ClassManifest($this->base, false, true, false);
  	}
  
  	public function testGetItemPath() {
  		$expect = array(
  			'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'
  		);
  
  		foreach ($expect as $name => $path) {
  			$this->assertEquals("{$this->base}/$path", $this->manifest->getItemPath($name));
  		}
  	}
  
  	public function testGetClasses() {
  		$expect = array(
  			'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",
  			'sstemplateparser'         => FRAMEWORK_PATH."/view/SSTemplateParser.php",
  			'sstemplateparseexception' => FRAMEWORK_PATH."/view/SSTemplateParser.php"
  		);
  
  		$this->assertEquals($expect, $this->manifest->getClasses());
  	}
  
  	public function testGetClassNames() {
  		$this->assertEquals(
  			array('sstemplateparser', 'sstemplateparseexception', 'silverstripe\test\classa',
  				'silverstripe\test\classb', 'silverstripe\test\classc', 'silverstripe\test\classd',
  				'silverstripe\test\classe', 'silverstripe\test\classf', 'silverstripe\test\classg',
  				'silverstripe\test\classh'),
  			$this->manifest->getClassNames());
  	}
  
  	public function testGetDescendants() {
  		$expect = array(
  			'silverstripe\test\classa' => array('silverstripe\test\ClassB', 'silverstripe\test\ClassH'),
  		);
  
  		$this->assertEquals($expect, $this->manifest->getDescendants());
  	}
  
  	public function testGetDescendantsOf() {
  		$expect = array(
  			'SILVERSTRIPE\TEST\CLASSA' => array('silverstripe\test\ClassB', 'silverstripe\test\ClassH'),
  			'silverstripe\test\classa' => array('silverstripe\test\ClassB', 'silverstripe\test\ClassH'),
  		);
  
  		foreach ($expect as $class => $desc) {
  			$this->assertEquals($desc, $this->manifest->getDescendantsOf($class));
  		}
  	}
  
  	public function testGetInterfaces() {
  		$expect = array(
  			'silverstripe\test\interfacea' => "{$this->base}/module/interfaces/InterfaceA.php",
  		);
  		$this->assertEquals($expect, $this->manifest->getInterfaces());
  	}
  
  	public function testGetImplementors() {
  		$expect = array(
  			'silverstripe\test\interfacea' => array('silverstripe\test\ClassE'),
  			'interfacea' => array('silverstripe\test\ClassF'),
  			'silverstripe\test\subtest\interfacea' => array('silverstripe\test\ClassG')
  		);
  		$this->assertEquals($expect, $this->manifest->getImplementors());
  	}
  
  	public function testGetImplementorsOf() {
  		$expect = array(
  			'SILVERSTRIPE\TEST\INTERFACEA' => array('silverstripe\test\ClassE'),
  			'silverstripe\test\interfacea' => array('silverstripe\test\ClassE'),
  			'INTERFACEA' => array('silverstripe\test\ClassF'),
  			'interfacea' => array('silverstripe\test\ClassF'),
  			'SILVERSTRIPE\TEST\SUBTEST\INTERFACEA' => array('silverstripe\test\ClassG'),
  			'silverstripe\test\subtest\interfacea' => array('silverstripe\test\ClassG'),
  		);
  
  		foreach ($expect as $interface => $impl) {
  			$this->assertEquals($impl, $this->manifest->getImplementorsOf($interface));
  		}
  	}
  
  	public function testGetConfigs() {
  		$expect = array("{$this->base}/module/_config.php");
  		$this->assertEquals($expect, $this->manifest->getConfigs());
  	}
  
  	public function testGetModules() {
  		$expect = array(
  			"module" => "{$this->base}/module",
  			"moduleb" => "{$this->base}/moduleb"
  		);
  		$this->assertEquals($expect, $this->manifest->getModules());
  	}
  }