5b678734c1573b69eb291266d475d12908ff8220
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseEffectivePidTest.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 TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseEffectivePid;
18
19 /**
20 * Test case
21 */
22 class DatabaseEffectivePidTest extends \TYPO3\Components\TestingFramework\Core\UnitTestCase
23 {
24 /**
25 * @var DatabaseEffectivePid
26 */
27 protected $subject;
28
29 protected function setUp()
30 {
31 $this->subject = new DatabaseEffectivePid();
32 }
33
34 /**
35 * @test
36 */
37 public function addDataSetsUidOfRecordIsPageIsEdited()
38 {
39 $input = [
40 'command' => 'edit',
41 'tableName' => 'pages',
42 'databaseRow' => [
43 'uid' => 123,
44 ],
45 ];
46 $expected = $input;
47 $expected['effectivePid'] = 123;
48 $this->assertSame($expected, $this->subject->addData($input));
49 }
50
51 /**
52 * @test
53 */
54 public function addDataSetsPidOfRecordIfNoPageIsEdited()
55 {
56 $input = [
57 'command' => 'edit',
58 'tableName' => 'tt_content',
59 'databaseRow' => [
60 'pid' => 123,
61 ],
62 ];
63 $expected = $input;
64 $expected['effectivePid'] = 123;
65 $this->assertSame($expected, $this->subject->addData($input));
66 }
67
68 /**
69 * @test
70 */
71 public function addDataSetsUidOfParentPageRowIfParentPageRowExistsAndCommandIsNew()
72 {
73 $input = [
74 'command' => 'new',
75 'tableName' => 'tt_content',
76 'parentPageRow' => [
77 'uid' => 123
78 ],
79 ];
80 $expected = $input;
81 $expected['effectivePid'] = 123;
82 $this->assertSame($expected, $this->subject->addData($input));
83 }
84
85 /**
86 * @test
87 */
88 public function addDataSetsZeroWithMissingParentPageRowAndCommandIsNew()
89 {
90 $input = [
91 'command' => 'new',
92 'tableName' => 'pages',
93 'parentPageRow' => null,
94 ];
95 $expected = $input;
96 $expected['effectivePid'] = 0;
97 $this->assertSame($expected, $this->subject->addData($input));
98 }
99 }