‪TYPO3CMS  10.4
DatabaseEditRowTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪DatabaseEditRowTest extends UnitTestCase
27 {
31  protected ‪$subject;
32 
33  protected function ‪setUp(): void
34  {
35  $this->subject = $this->getMockBuilder(DatabaseEditRow::class)
36  ->setMethods(['getDatabaseRow'])
37  ->getMock();
38  }
39 
44  {
45  $input = [
46  'tableName' => 'tt_content',
47  'command' => 'edit',
48  'vanillaUid' => 10,
49  ];
50  $resultRow = [
51  'uid' => 10,
52  'pid' => 123
53  ];
54  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn($resultRow);
55 
56  $result = $this->subject->addData($input);
57 
58  self::assertSame($resultRow, $result['databaseRow']);
59  }
60 
65  {
66  $input = [
67  'tableName' => 'tt_content',
68  'command' => 'edit',
69  'vanillaUid' => 10,
70  ];
71  $resultRow = [
72  'uid' => 10,
73  ];
74  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn($resultRow);
75 
76  $this->expectException(\UnexpectedValueException::class);
77  $this->expectExceptionCode(1437663061);
78 
79  $this->subject->addData($input);
80  }
81 
86  {
87  $input = [
88  'tableName' => 'tt_content',
89  'command' => 'edit',
90  'vanillaUid' => -10,
91  ];
92 
93  $this->expectException(\InvalidArgumentException::class);
94  $this->expectExceptionCode(1437656456);
95 
96  $this->subject->addData($input);
97  }
98 
103  {
104  $input = [
105  'tableName' => 'tt_content',
106  'command' => 'edit',
107  'vanillaUid' => 10,
108  ];
109  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn([]);
110 
111  $this->expectException(DatabaseRecordException::class);
112  $this->expectExceptionCode(1437656081);
113 
114  $this->subject->addData($input);
115  }
116 
121  {
122  $input = [
123  'tableName' => 'tt_content',
124  'command' => 'edit',
125  'vanillaUid' => 10,
126  ];
127  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn([]);
128 
129  try {
130  $this->subject->addData($input);
131  } catch (DatabaseRecordException $e) {
132  self::assertSame('tt_content', $e->getTableName());
133  self::assertSame(10, $e->getUid());
134  }
135  }
136 
141  {
142  $this->expectException(DatabaseRecordWorkspaceDeletePlaceholderException::class);
143  $this->expectExceptionCode(1608658396);
144  ‪$GLOBALS['TCA']['tt_content']['ctrl']['versioningWS'] = 1;
145  $input = [
146  'tableName' => 'tt_content',
147  'command' => 'edit',
148  'vanillaUid' => 10,
149  ];
150  $resultRow = [
151  'uid' => 10,
152  'pid' => 123,
153  't3ver_state' => 2,
154  ];
155  $this->subject->expects(self::once())->method('getDatabaseRow')->willReturn($resultRow);
156  $this->subject->addData($input);
157  }
158 
163  {
164  $virtualRow = [
165  'uid' => 10,
166  'pid' => 123,
167  'title' => 'Title of the virtual record'
168  ];
169  $input = [
170  'tableName' => 'virtual_table',
171  'command' => 'edit',
172  'vanillaUid' => 10,
173  'databaseRow' => $virtualRow
174  ];
175  $resultRow = $virtualRow;
176  $this->subject->expects(self::never())->method('getDatabaseRow');
177 
178  $result = $this->subject->addData($input);
179 
180  self::assertSame($resultRow, $result['databaseRow']);
181  }
182 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseEditRow
Definition: DatabaseEditRow.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionIfRetrievedRowHasNoPid
‪addDataThrowsExceptionIfRetrievedRowHasNoPid()
Definition: DatabaseEditRowTest.php:63
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataSkipsDatabaseLookupIfDatabaseRowIsPopulated
‪addDataSkipsDatabaseLookupIfDatabaseRowIsPopulated()
Definition: DatabaseEditRowTest.php:161
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\setUp
‪setUp()
Definition: DatabaseEditRowTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionIfDatabaseFetchingReturnsNoRow
‪addDataThrowsExceptionIfDatabaseFetchingReturnsNoRow()
Definition: DatabaseEditRowTest.php:101
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException\getUid
‪int getUid()
Definition: DatabaseRecordException.php:64
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordWorkspaceDeletePlaceholderException
Definition: DatabaseRecordWorkspaceDeletePlaceholderException.php:26
‪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:84
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsExceptionDatabaseRecordExceptionWithAdditionalInformationSet
‪addDataThrowsExceptionDatabaseRecordExceptionWithAdditionalInformationSet()
Definition: DatabaseEditRowTest.php:119
‪TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException
Definition: DatabaseRecordException.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataRetrievesRecordInformationFromDatabase
‪addDataRetrievesRecordInformationFromDatabase()
Definition: DatabaseEditRowTest.php:42
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest
Definition: DatabaseEditRowTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\$subject
‪DatabaseEditRow PHPUnit Framework MockObject MockObject $subject
Definition: DatabaseEditRowTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseEditRowTest\addDataThrowsWorkspaceDeletePlaceholderExeptionWithDeletePlaceholderRecord
‪addDataThrowsWorkspaceDeletePlaceholderExeptionWithDeletePlaceholderRecord()
Definition: DatabaseEditRowTest.php:139
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18