‪TYPO3CMS  11.5
DatabaseEditRowTest.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\MockObject\MockObject;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪DatabaseEditRowTest extends UnitTestCase
30 {
34  protected MockObject ‪$subject;
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39  $this->subject = $this->getMockBuilder(DatabaseEditRow::class)
40  ->onlyMethods(['getDatabaseRow'])
41  ->getMock();
42  }
43 
48  {
49  $input = [
50  'tableName' => 'tt_content',
51  'command' => 'edit',
52  'vanillaUid' => 10,
53  ];
54  $resultRow = [
55  'uid' => 10,
56  'pid' => 123,
57  ];
58  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn($resultRow);
59 
60  $result = $this->subject->addData($input);
61 
62  self::assertSame($resultRow, $result['databaseRow']);
63  }
64 
69  {
70  $input = [
71  'tableName' => 'tt_content',
72  'command' => 'edit',
73  'vanillaUid' => 10,
74  ];
75  $resultRow = [
76  'uid' => 10,
77  ];
78  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn($resultRow);
79 
80  $this->expectException(\UnexpectedValueException::class);
81  $this->expectExceptionCode(1437663061);
82 
83  $this->subject->addData($input);
84  }
85 
90  {
91  $input = [
92  'tableName' => 'tt_content',
93  'command' => 'edit',
94  'vanillaUid' => -10,
95  ];
96 
97  $this->expectException(\InvalidArgumentException::class);
98  $this->expectExceptionCode(1437656456);
99 
100  $this->subject->addData($input);
101  }
102 
107  {
108  $input = [
109  'tableName' => 'tt_content',
110  'command' => 'edit',
111  'vanillaUid' => 10,
112  ];
113  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn([]);
114 
115  $this->expectException(DatabaseRecordException::class);
116  $this->expectExceptionCode(1437656081);
117 
118  $this->subject->addData($input);
119  }
120 
125  {
126  $input = [
127  'tableName' => 'tt_content',
128  'command' => 'edit',
129  'vanillaUid' => 10,
130  ];
131  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn([]);
132 
133  try {
134  $this->subject->addData($input);
135  } catch (‪DatabaseRecordException $e) {
136  self::assertSame('tt_content', $e->‪getTableName());
137  self::assertSame(10, $e->‪getUid());
138  }
139  }
140 
145  {
146  $this->expectException(DatabaseRecordWorkspaceDeletePlaceholderException::class);
147  $this->expectExceptionCode(1608658396);
148  ‪$GLOBALS['TCA']['tt_content']['ctrl']['versioningWS'] = 1;
149  $input = [
150  'tableName' => 'tt_content',
151  'command' => 'edit',
152  'vanillaUid' => 10,
153  ];
154  $resultRow = [
155  'uid' => 10,
156  'pid' => 123,
157  't3ver_state' => 2,
158  ];
159  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn($resultRow);
160  $this->subject->addData($input);
161  }
162 
167  {
168  $virtualRow = [
169  'uid' => 10,
170  'pid' => 123,
171  'title' => 'Title of the virtual record',
172  ];
173  $input = [
174  'tableName' => 'virtual_table',
175  'command' => 'edit',
176  'vanillaUid' => 10,
177  'databaseRow' => $virtualRow,
178  ];
179  $resultRow = $virtualRow;
180  $this->subject->expects(self::never())->method('getDatabaseRow');
181 
182  $result = $this->subject->addData($input);
183 
184  self::assertSame($resultRow, $result['databaseRow']);
185  }
186 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseEditRow
Definition: DatabaseEditRow.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionIfRetrievedRowHasNoPid
‪addDataThrowsExceptionIfRetrievedRowHasNoPid()
Definition: DatabaseEditRowTest.php:68
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataSkipsDatabaseLookupIfDatabaseRowIsPopulated
‪addDataSkipsDatabaseLookupIfDatabaseRowIsPopulated()
Definition: DatabaseEditRowTest.php:166
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\setUp
‪setUp()
Definition: DatabaseEditRowTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionIfDatabaseFetchingReturnsNoRow
‪addDataThrowsExceptionIfDatabaseFetchingReturnsNoRow()
Definition: DatabaseEditRowTest.php:106
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException\getUid
‪int getUid()
Definition: DatabaseRecordException.php:64
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\$subject
‪MockObject $subject
Definition: DatabaseEditRowTest.php:34
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordWorkspaceDeletePlaceholderException
Definition: DatabaseRecordWorkspaceDeletePlaceholderException.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsWorkspaceDeletePlaceholderExceptionWithDeletePlaceholderRecord
‪addDataThrowsWorkspaceDeletePlaceholderExceptionWithDeletePlaceholderRecord()
Definition: DatabaseEditRowTest.php:144
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException\getTableName
‪string getTableName()
Definition: DatabaseRecordException.php:54
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionIfGivenUidIsNotPositive
‪addDataThrowsExceptionIfGivenUidIsNotPositive()
Definition: DatabaseEditRowTest.php:89
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionDatabaseRecordExceptionWithAdditionalInformationSet
‪addDataThrowsExceptionDatabaseRecordExceptionWithAdditionalInformationSet()
Definition: DatabaseEditRowTest.php:124
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException
Definition: DatabaseRecordException.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataRetrievesRecordInformationFromDatabase
‪addDataRetrievesRecordInformationFromDatabase()
Definition: DatabaseEditRowTest.php:47
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest
Definition: DatabaseEditRowTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18