[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / ViewHelper / ViewHelperResolverTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\ViewHelper;
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\ObjectManager;
17 use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver;
18 use TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper;
19 use TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesViewHelper;
20 use TYPO3Fluid\Fluid\ViewHelpers\RenderViewHelper;
21
22 /**
23 * Test case
24 */
25 class ViewHelperResolverTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
26 {
27 /**
28 * @test
29 */
30 public function createViewHelperInstanceCreatesViewHelperInstanceUsingObjectManager()
31 {
32 $objectManager = $this->getMockBuilder(ObjectManager::class)
33 ->setMethods(['get'])
34 ->disableOriginalConstructor()
35 ->getMock();
36 $objectManager->expects($this->once())->method('get')->with('x')->willReturn('y');
37 $resolver = $this->getMockBuilder(ViewHelperResolver::class)
38 ->setMethods(['getObjectManager'])
39 ->getMock();
40 $resolver->expects($this->once())->method('getObjectManager')->willReturn($objectManager);
41 $this->assertEquals('y', $resolver->createViewHelperInstanceFromClassName('x'));
42 }
43
44 /**
45 * @test
46 * @dataProvider getResolveViewHelperNameTestValues
47 * @param string $namespace
48 * @param string $method
49 * @param string $expected
50 */
51 public function resolveViewHelperClassNameResolvesExpectedViewHelperClassName($namespace, $method, $expected)
52 {
53 $viewHelperResolver = new ViewHelperResolver();
54 $this->assertEquals($expected, $viewHelperResolver->resolveViewHelperClassName($namespace, $method));
55 }
56
57 /**
58 * @return array
59 */
60 public function getResolveViewHelperNameTestValues()
61 {
62 return [
63 ['f', 'cObject', CObjectViewHelper::class],
64 ['f', 'format.htmlentities', HtmlentitiesViewHelper::class],
65 ['f', 'render', RenderViewHelper::class]
66 ];
67 }
68 }