d3cd6d163e89152118a35669acdf564222bc8209
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Reflection / ReflectionServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Some functional tests for the backport of the reflection service
28 */
29 class ReflectionServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
30
31 /**
32 * @param array $foo The foo parameter
33 * @return void
34 */
35 public function fixtureMethodForMethodTagsValues(array $foo) {
36 }
37
38 /**
39 * @test
40 */
41 public function hasMethod() {
42 $service = new \TYPO3\CMS\Extbase\Reflection\ReflectionService();
43 $this->assertTrue($service->hasMethod(get_class($this), 'fixtureMethodForMethodTagsValues'));
44 $this->assertFalse($service->hasMethod(get_class($this), 'notExistentMethod'));
45 }
46
47 /**
48 * @test
49 */
50 public function getMethodTagsValues() {
51 $service = new \TYPO3\CMS\Extbase\Reflection\ReflectionService();
52 $tagsValues = $service->getMethodTagsValues(get_class($this), 'fixtureMethodForMethodTagsValues');
53 $this->assertEquals(array(
54 'param' => array('array $foo The foo parameter'),
55 'return' => array('void')
56 ), $tagsValues);
57 }
58
59 /**
60 * @test
61 */
62 public function getMethodParameters() {
63 $service = new \TYPO3\CMS\Extbase\Reflection\ReflectionService();
64 $parameters = $service->getMethodParameters(get_class($this), 'fixtureMethodForMethodTagsValues');
65 $this->assertEquals(array(
66 'foo' => array(
67 'position' => 0,
68 'byReference' => FALSE,
69 'array' => TRUE,
70 'optional' => FALSE,
71 'allowsNull' => FALSE,
72 'class' => NULL,
73 'type' => 'array'
74 )
75 ), $parameters);
76 }
77
78 /**
79 * @test
80 */
81 public function classSchemaForModelIsSetAggregateRootIfRepositoryClassIsFoundForNamespacedClasses() {
82 $className = uniqid('BazFixture');
83 eval ('
84 namespace Foo\\Bar\\Domain\\Model;
85 class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
86 ');
87 eval ('
88 namespace Foo\\Bar\\Domain\\Repository;
89 class ' . $className . 'Repository {}
90 ');
91
92 $service = new \TYPO3\CMS\Extbase\Reflection\ReflectionService();
93 $service->injectObjectManager($this->objectManager);
94 $classSchema = $service->getClassSchema('Foo\\Bar\\Domain\\Model\\' . $className);
95 $this->assertTrue($classSchema->isAggregateRoot());
96 }
97
98 /**
99 * @test
100 */
101 public function classSchemaForModelIsSetAggregateRootIfRepositoryClassIsFoundForNotNamespacedClasses() {
102 $className = uniqid('BazFixture');
103 eval ('
104 class Foo_Bar_Domain_Model_' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
105 ');
106 eval ('
107 class Foo_Bar_Domain_Repository_' . $className . 'Repository {}
108 ');
109
110 $service = new \TYPO3\CMS\Extbase\Reflection\ReflectionService();
111 $service->injectObjectManager($this->objectManager);
112 $classSchema = $service->getClassSchema('Foo_Bar_Domain_Model_' . $className);
113 $this->assertTrue($classSchema->isAggregateRoot());
114 }
115 }
116
117 ?>