TYPO3 CMS  TYPO3_8-7
ClassSchemaTest.php
Go to the documentation of this file.
1 <?php
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 
20 class ClassSchemaTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  public function classSchemaForModelIsSetAggregateRootIfRepositoryClassIsFoundForNamespacedClasses()
26  {
27  $className = $this->getUniqueId('BazFixture');
28  eval('
29  namespace Foo\\Bar\\Domain\\Model;
30  class ' . $className . ' extends \\' . \TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class . ' {}
31  ');
32  eval('
33  namespace Foo\\Bar\\Domain\\Repository;
34  class ' . $className . 'Repository {}
35  ');
36 
38  $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
39  $mockClassSchema = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Reflection\ClassSchema::class, ['dummy'], ['Foo\\Bar\\Domain\\Model\\' . $className]);
40  $objectManager->expects($this->once())->method('get')->will($this->returnValue($mockClassSchema));
41 
43  $service = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class, ['dummy']);
44  $service->_set('objectManager', $objectManager);
45  $classSchema = $service->getClassSchema('Foo\\Bar\\Domain\\Model\\' . $className);
46  $this->assertTrue($classSchema->isAggregateRoot());
47  }
48 
52  public function classSchemaForModelIsSetAggregateRootIfRepositoryClassIsFoundForNotNamespacedClasses()
53  {
54  $className = $this->getUniqueId('BazFixture');
55  eval('
56  class Foo_Bar_Domain_Model_' . $className . ' extends \\' . \TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class . ' {}
57  ');
58  eval('
59  class Foo_Bar_Domain_Repository_' . $className . 'Repository {}
60  ');
61 
63  $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
64  $mockClassSchema = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Reflection\ClassSchema::class, ['dummy'], ['Foo_Bar_Domain_Model_' . $className]);
65  $objectManager->expects($this->once())->method('get')->will($this->returnValue($mockClassSchema));
66 
67  $service = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class, ['dummy']);
68  $service->_set('objectManager', $objectManager);
69  $classSchema = $service->getClassSchema('Foo_Bar_Domain_Model_' . $className);
70  $this->assertTrue($classSchema->isAggregateRoot());
71  }
72 }