[BUGFIX] Show correct label for IRRE records
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseParentPageRowTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
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 Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseParentPageRow;
20 use TYPO3\CMS\Core\Database\DatabaseConnection;
21 use TYPO3\CMS\Core\Tests\UnitTestCase;
22
23 /**
24 * Test case
25 */
26 class DatabaseParentPageRowTest extends UnitTestCase
27 {
28 /**
29 * @var DatabaseParentPageRow
30 */
31 protected $subject;
32
33 /**
34 * @var DatabaseConnection | ObjectProphecy
35 */
36 protected $dbProphecy;
37
38 protected function setUp()
39 {
40 $this->subject = new DatabaseParentPageRow();
41
42 $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
43 $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
44 }
45
46 /**
47 * @test
48 */
49 public function addDataFetchesParentPageRowOfRecordIfNeighbourGiven()
50 {
51 $input = [
52 'tableName' => 'tt_content',
53 'command' => 'new',
54 'vanillaUid' => -10,
55 ];
56 $parentPageRow = [
57 'uid' => 123,
58 'pid' => 321
59 ];
60 $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
61 $this->dbProphecy->exec_SELECTgetSingleRow('*', $input['tableName'], 'uid=10')->willReturn(['pid' => 123]);
62 $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=123')->willReturn($parentPageRow);
63
64 $result = $this->subject->addData($input);
65
66 $this->assertSame($parentPageRow, $result['parentPageRow']);
67 }
68
69 /**
70 * @test
71 */
72 public function addDataSetsNeigborRowIfNegativeUidGiven()
73 {
74 $input = [
75 'tableName' => 'tt_content',
76 'command' => 'new',
77 'vanillaUid' => -10,
78 ];
79 $neigborRow = [
80 'uid' => 10,
81 'pid' => 321
82 ];
83 $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
84 $this->dbProphecy->exec_SELECTgetSingleRow('*', $input['tableName'], 'uid=10')->willReturn($neigborRow);
85 $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=321')->willReturn(array());
86
87 $result = $this->subject->addData($input);
88
89 $this->assertSame($neigborRow, $result['neighborRow']);
90 }
91
92 /**
93 * @test
94 */
95 public function addDataSetsParentPageRowToNullIfParentIsRoot()
96 {
97 $input = [
98 'tableName' => 'tt_content',
99 'command' => 'new',
100 'vanillaUid' => -10,
101 ];
102 $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
103 $this->dbProphecy->exec_SELECTgetSingleRow('*', $input['tableName'], 'uid=10')->willReturn(['pid' => 0]);
104
105 $result = $this->subject->addData($input);
106
107 $this->assertNull($result['parentPageRow']);
108 }
109
110 /**
111 * @test
112 */
113 public function addDataSetsParentPageToGivenPageIdIfCommandIsNew()
114 {
115 $input = [
116 'tableName' => 'tt_content',
117 'command' => 'new',
118 'vanillaUid' => 123,
119 ];
120 $parentPageRow = [
121 'uid' => 123,
122 'pid' => 321
123 ];
124 $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
125 $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=123')->willReturn($parentPageRow);
126
127 $result = $this->subject->addData($input);
128
129 $this->assertSame($parentPageRow, $result['parentPageRow']);
130 }
131
132 /**
133 * @test
134 */
135 public function addDataSetsParentPageRowOnParentIfCommandIsEdit()
136 {
137 $input = [
138 'tableName' => 'tt_content',
139 'command' => 'edit',
140 'vanillaUid' => 123,
141 'databaseRow' => [
142 'uid' => 123,
143 'pid' => 321
144 ],
145 ];
146 $parentPageRow = [
147 'uid' => 321,
148 'pid' => 456
149 ];
150 $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
151 $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=321')->willReturn($parentPageRow);
152
153 $result = $this->subject->addData($input);
154
155 $this->assertSame($parentPageRow, $result['parentPageRow']);
156 }
157 }