[TASK] Use BE_USER->isAdmin()
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Object / Container / ClassInfoFactoryTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Object\Container;
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 use TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException;
17
18 /**
19 * Test case
20 */
21 class ClassInfoFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
22 {
23 /**
24 * @var \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory
25 */
26 protected $classInfoFactory;
27
28 /**
29 * Set up
30 */
31 protected function setUp()
32 {
33 $this->classInfoFactory = new \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory();
34 }
35
36 /**
37 * @test
38 */
39 public function buildClassInfoFromClassNameThrowsExceptionIfGivenClassNameCantBeReflected()
40 {
41 $this->expectException(UnknownObjectException::class);
42 $this->expectExceptionCode(1289386765);
43 $this->classInfoFactory->buildClassInfoFromClassName('SomeNonExistingClass');
44 }
45
46 /**
47 * @test
48 */
49 public function buildClassInfoDoesNotIncludeInjectSettingsMethodInListOfInjectMethods()
50 {
51 $classInfo = $this->classInfoFactory->buildClassInfoFromClassName('t3lib_object_tests_class_with_injectsettings');
52 $this->assertEquals(['injectFoo' => 't3lib_object_tests_resolveablecyclic1'], $classInfo->getInjectMethods());
53 }
54
55 /**
56 * @test
57 */
58 public function buildClassInfoDetectsPropertiesToInjectByAnnotation()
59 {
60 $classInfo = $this->classInfoFactory->buildClassInfoFromClassName(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithInjectProperties::class);
61 $this->assertEquals(['secondDummyClass' => \TYPO3\CMS\Extbase\Tests\Fixture\SecondDummyClass::class], $classInfo->getInjectProperties());
62 }
63
64 /**
65 * @test
66 */
67 public function buildClassInfoReturnsCustomClassInfoForDateTime()
68 {
69 /** @var \PHPUnit_Framework_MockObject_MockObject | \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory $classInfoFactory */
70 $classInfoFactory = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory::class)
71 ->setMethods(['getConstructorArguments'])
72 ->getMock();
73 $classInfoFactory->expects($this->never())->method('getConstructorArguments');
74
75 $classInfo = $classInfoFactory->buildClassInfoFromClassName('DateTime');
76 $this->assertEquals(
77 new \TYPO3\CMS\Extbase\Object\Container\ClassInfo('DateTime', [], [], false, false, []),
78 $classInfo
79 );
80 }
81 }