[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Tests / Unit / RecordList / AbstractDatabaseRecordListTest.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\Tests\Unit\RecordList;
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\Recordlist\RecordList\AbstractDatabaseRecordList;
18
19 /**
20 * Test case
21 */
22 class AbstractDatabaseRecordListTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
23 {
24 /**
25 * @test
26 * @dataProvider setTableDisplayOrderConvertsStringsDataProvider
27 * @param array $input
28 * @param array $expected
29 */
30 public function setTableDisplayOrderConvertsStringInput(array $input, array $expected)
31 {
32 /** @var AbstractDatabaseRecordList|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Components\TestingFramework\Core\AccessibleObjectInterface $subject */
33 $subject = $this->getAccessibleMock(AbstractDatabaseRecordList::class, ['dummy']);
34 $subject->setTableDisplayOrder($input);
35 $this->assertSame($expected, $subject->_get('tableDisplayOrder'));
36 }
37
38 /**
39 * @return array
40 */
41 public function setTableDisplayOrderConvertsStringsDataProvider()
42 {
43 return [
44 'no information at all' => [
45 [],
46 []
47 ],
48 'string in before' => [
49 [
50 'tableA' => [
51 'before' => 'tableB, tableC'
52 ]
53 ],
54 [
55 'tableA' => [
56 'before' => ['tableB', 'tableC']
57 ]
58 ]
59 ],
60 'array is preserved in before' => [
61 [
62 'tableA' => [
63 'before' => ['tableB', 'tableC']
64 ]
65 ],
66 [
67 'tableA' => [
68 'before' => ['tableB', 'tableC']
69 ]
70 ]
71 ],
72 'array is preserved in before, after is modified' => [
73 [
74 'tableA' => [
75 'before' => ['tableB', 'tableC'],
76 'after' => 'tableD'
77 ]
78 ],
79 [
80 'tableA' => [
81 'before' => ['tableB', 'tableC'],
82 'after' => ['tableD']
83 ]
84 ]
85 ],
86 ];
87 }
88
89 /**
90 * @test
91 */
92 public function setTableDisplayOrderThrowsExceptionOnInvalidAfter()
93 {
94 $this->expectException(\UnexpectedValueException::class);
95 $this->expectExceptionCode(1436195934);
96 $test = [
97 'table' => [ 'after' => new \stdClass ]
98 ];
99 $subject = new AbstractDatabaseRecordList();
100 $subject->setTableDisplayOrder($test);
101 }
102
103 /**
104 * @test
105 */
106 public function setTableDisplayOrderThrowsExceptionOnInvalidBefore()
107 {
108 $this->expectException(\UnexpectedValueException::class);
109 $this->expectExceptionCode(1436195933);
110 $test = [
111 'table' => [ 'before' => new \stdClass ]
112 ];
113 $subject = new AbstractDatabaseRecordList();
114 $subject->setTableDisplayOrder($test);
115 }
116 }