[FEATURE] Support 'has*' for properties in ObjectAccess
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Reflection / ClassSchemaTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Test case
19 */
20 class ClassSchemaTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @test
24 */
25 public function classSchemaForModelIsSetAggregateRootIfRepositoryClassIsFoundForNamespacedClasses() {
26 $className = uniqid('BazFixture');
27 eval ('
28 namespace Foo\\Bar\\Domain\\Model;
29 class ' . $className . ' extends \\' . \TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class . ' {}
30 ');
31 eval ('
32 namespace Foo\\Bar\\Domain\\Repository;
33 class ' . $className . 'Repository {}
34 ');
35
36 /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
37 $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
38 $mockClassSchema = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Reflection\ClassSchema::class, array('dummy'), array('Foo\\Bar\\Domain\\Model\\' . $className));
39 $objectManager->expects($this->once())->method('get')->will($this->returnValue($mockClassSchema));
40
41 /** @var \TYPO3\CMS\Extbase\Reflection\ReflectionService $service */
42 $service = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class, array('dummy'));
43 $service->_set('objectManager', $objectManager);
44 $classSchema = $service->getClassSchema('Foo\\Bar\\Domain\\Model\\' . $className);
45 $this->assertTrue($classSchema->isAggregateRoot());
46 }
47
48 /**
49 * @test
50 */
51 public function classSchemaForModelIsSetAggregateRootIfRepositoryClassIsFoundForNotNamespacedClasses() {
52 $className = uniqid('BazFixture');
53 eval ('
54 class Foo_Bar_Domain_Model_' . $className . ' extends \\' . \TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class . ' {}
55 ');
56 eval ('
57 class Foo_Bar_Domain_Repository_' . $className . 'Repository {}
58 ');
59
60 /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
61 $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
62 $mockClassSchema = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Reflection\ClassSchema::class, array('dummy'), array('Foo_Bar_Domain_Model_' . $className));
63 $objectManager->expects($this->once())->method('get')->will($this->returnValue($mockClassSchema));
64
65 $service = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class, array('dummy'));
66 $service->_set('objectManager', $objectManager);
67 $classSchema = $service->getClassSchema('Foo_Bar_Domain_Model_' . $className);
68 $this->assertTrue($classSchema->isAggregateRoot());
69 }
70
71 }