‪TYPO3CMS  ‪main
DatabaseParentPageRowTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
21 use PHPUnit\Framework\MockObject\MockObject;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪DatabaseParentPageRowTest extends UnitTestCase
26 {
27  protected ‪DatabaseParentPageRow&MockObject ‪$subject;
28 
29  protected function ‪setUp(): void
30  {
31  parent::setUp();
32  $this->subject = $this->getMockBuilder(DatabaseParentPageRow::class)
33  ->onlyMethods(['getDatabaseRow'])
34  ->getMock();
35  }
36 
37  #[Test]
39  {
40  $input = [
41  'tableName' => 'tt_content',
42  'command' => 'new',
43  'vanillaUid' => -10,
44  ];
45  $parentPageRow = [
46  'uid' => 123,
47  'pid' => 321,
48  ];
49 
50  $series = [
51  [['tableName' => $input['tableName'], 'uid' => 10], ['pid' => 123]],
52  [['tableName' => 'pages', 'uid' => 123], $parentPageRow],
53  ];
54  $this->subject->expects(self::exactly(2))->method('getDatabaseRow')->willReturnCallback(function (string $tableName, int ‪$uid) use (&$series): array {
55  [$expectedArgs, $return] = array_shift($series);
56  self::assertSame($expectedArgs['tableName'], $tableName);
57  self::assertSame($expectedArgs['uid'], ‪$uid);
58  return $return;
59  });
60 
61  $result = $this->subject->addData($input);
62 
63  self::assertSame($parentPageRow, $result['parentPageRow']);
64  }
65 
66  #[Test]
68  {
69  $input = [
70  'tableName' => 'tt_content',
71  'command' => 'new',
72  'vanillaUid' => -10,
73  ];
74  $neighborRow = [
75  'uid' => 10,
76  'pid' => 321,
77  ];
78  $parentPageRow = [
79  'uid' => 123,
80  'pid' => 321,
81  ];
82 
83  $series = [
84  [['tableName' => $input['tableName'], 'uid' => 10], $neighborRow],
85  [['tableName' => 'pages', 'uid' => 321], $parentPageRow],
86  ];
87  $this->subject->expects(self::exactly(2))->method('getDatabaseRow')->willReturnCallback(function (string $tableName, int ‪$uid) use (&$series): array {
88  [$expectedArgs, $return] = array_shift($series);
89  self::assertSame($expectedArgs['tableName'], $tableName);
90  self::assertSame($expectedArgs['uid'], ‪$uid);
91  return $return;
92  });
93 
94  $result = $this->subject->addData($input);
95 
96  self::assertSame($neighborRow, $result['neighborRow']);
97  }
98 
99  #[Test]
101  {
102  $input = [
103  'tableName' => 'tt_content',
104  'command' => 'new',
105  'vanillaUid' => -10,
106  ];
107 
108  $this->subject->expects(self::once())
109  ->method('getDatabaseRow')
110  ->with($input['tableName'], 10)
111  ->willReturn(['pid' => 0]);
112 
113  $result = $this->subject->addData($input);
114 
115  self::assertNull($result['parentPageRow']);
116  }
117 
118  #[Test]
120  {
121  $input = [
122  'tableName' => 'tt_content',
123  'command' => 'new',
124  'vanillaUid' => 123,
125  ];
126  $parentPageRow = [
127  'uid' => 123,
128  'pid' => 321,
129  ];
130 
131  $this->subject->expects(self::once())
132  ->method('getDatabaseRow')
133  ->with('pages', 123)
134  ->willReturn($parentPageRow);
135 
136  $result = $this->subject->addData($input);
137 
138  self::assertSame($parentPageRow, $result['parentPageRow']);
139  }
140 
141  #[Test]
143  {
144  $input = [
145  'tableName' => 'tt_content',
146  'command' => 'edit',
147  'vanillaUid' => 123,
148  'databaseRow' => [
149  'uid' => 123,
150  'pid' => 321,
151  ],
152  ];
153  $parentPageRow = [
154  'uid' => 321,
155  'pid' => 456,
156  ];
157  $this->subject->expects(self::once())
158  ->method('getDatabaseRow')
159  ->with('pages', 321)
160  ->willReturn($parentPageRow);
161 
162  $result = $this->subject->addData($input);
163 
164  self::assertSame($parentPageRow, $result['parentPageRow']);
165  }
166 
167  #[Test]
169  {
170  $input = [
171  'tableName' => 'tt_content',
172  'command' => 'new',
173  'vanillaUid' => 'NEW123',
174  'databaseRow' => [],
175  ];
176 
177  $this->subject->expects(self::never())->method('getDatabaseRow');
178 
179  $result = $this->subject->addData($input);
180 
181  self::assertNull($result['parentPageRow']);
182  }
183 
184  #[Test]
186  {
187  $input = [
188  'tableName' => 'tt_content',
189  'command' => 'new',
190  'vanillaUid' => 0,
191  'databaseRow' => [],
192  ];
193 
194  $this->subject->expects(self::never())->method('getDatabaseRow');
195 
196  $result = $this->subject->addData($input);
197 
198  self::assertNull($result['parentPageRow']);
199  }
200 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageRowOnParentIfCommandIsEdit
‪addDataSetsParentPageRowOnParentIfCommandIsEdit()
Definition: DatabaseParentPageRowTest.php:142
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageToGivenPageIdIfCommandIsNew
‪addDataSetsParentPageToGivenPageIdIfCommandIsNew()
Definition: DatabaseParentPageRowTest.php:119
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataFetchesParentPageRowOfRecordIfNeighbourGiven
‪addDataFetchesParentPageRowOfRecordIfNeighbourGiven()
Definition: DatabaseParentPageRowTest.php:38
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\$subject
‪DatabaseParentPageRow &MockObject $subject
Definition: DatabaseParentPageRowTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsNeighborRowIfNegativeUidGiven
‪addDataSetsNeighborRowIfNegativeUidGiven()
Definition: DatabaseParentPageRowTest.php:67
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageRowOnNullWithZero
‪addDataSetsParentPageRowOnNullWithZero()
Definition: DatabaseParentPageRowTest.php:185
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageRowToNullIfParentIsRoot
‪addDataSetsParentPageRowToNullIfParentIsRoot()
Definition: DatabaseParentPageRowTest.php:100
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\setUp
‪setUp()
Definition: DatabaseParentPageRowTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest
Definition: DatabaseParentPageRowTest.php:26
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseParentPageRowTest\addDataSetsParentPageRowOnNullWithNew
‪addDataSetsParentPageRowOnNullWithNew()
Definition: DatabaseParentPageRowTest.php:168
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseParentPageRow
Definition: DatabaseParentPageRow.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18