[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / View / TemplatePathsTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\View;
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 use TYPO3\CMS\Fluid\View\TemplatePaths;
18
19 /**
20 * Test case
21 */
22 class TemplatePathsTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
23 {
24 /**
25 * @return array
26 */
27 public function getPathSetterMethodTestValues()
28 {
29 $generator = function ($method, $indexType = 'numeric') {
30 switch ($indexType) {
31 default:
32 case 'numeric':
33 $set = [
34 20 => 'bar',
35 0 => 'baz',
36 100 => 'boz',
37 10 => 'foo',
38 ];
39 $expected = [
40 0 => 'baz',
41 10 => 'foo',
42 20 => 'bar',
43 100 => 'boz',
44 ];
45 break;
46 case 'alpha':
47 $set = [
48 'bcd' => 'bar',
49 'abc' => 'foo',
50 ];
51 $expected = [
52 'bcd' => 'bar',
53 'abc' => 'foo',
54 ];
55 break;
56 case 'alphanumeric':
57 $set = [
58 0 => 'baz',
59 'bcd' => 'bar',
60 15 => 'boz',
61 'abc' => 'foo',
62 ];
63 $expected = [
64 0 => 'baz',
65 'bcd' => 'bar',
66 15 => 'boz',
67 'abc' => 'foo',
68 ];
69 break;
70 }
71 return [$method, $set, $expected];
72 };
73 return [
74 'simple numeric index, template' => $generator(TemplatePaths::CONFIG_TEMPLATEROOTPATHS, 'numeric'),
75 'alpha index, template' => $generator(TemplatePaths::CONFIG_TEMPLATEROOTPATHS, 'alpha'),
76 'alpha-numeric index, template' => $generator(TemplatePaths::CONFIG_TEMPLATEROOTPATHS, 'alphanumeric'),
77 'simple numeric index, partial' => $generator(TemplatePaths::CONFIG_PARTIALROOTPATHS, 'numeric'),
78 'alpha index, partial' => $generator(TemplatePaths::CONFIG_PARTIALROOTPATHS, 'alpha'),
79 'alpha-numeric index, partial' => $generator(TemplatePaths::CONFIG_PARTIALROOTPATHS, 'alphanumeric'),
80 'simple numeric index, layout' => $generator(TemplatePaths::CONFIG_LAYOUTROOTPATHS, 'numeric'),
81 'alpha index, layout' => $generator(TemplatePaths::CONFIG_LAYOUTROOTPATHS, 'alpha'),
82 'alpha-numeric index, layout' => $generator(TemplatePaths::CONFIG_LAYOUTROOTPATHS, 'alphanumeric'),
83 ];
84 }
85
86 /**
87 * @test
88 * @dataProvider getPathSetterMethodTestValues
89 * @param string $method
90 * @param array $paths
91 * @param array $expected
92 */
93 public function pathSetterMethodSortsPathsByKeyDescending($method, array $paths, array $expected)
94 {
95 $setter = 'set' . ucfirst($method);
96 $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['sanitizePath'])->getMock();
97 $subject->expects($this->any())->method('sanitizePath')->willReturnArgument(0);
98 $subject->$setter($paths);
99 $this->assertAttributeSame($expected, $method, $subject);
100 }
101 }