TYPO3 CMS  TYPO3_7-6
DatabaseEditRowTest.php
Go to the documentation of this file.
1 <?php
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 
23 
28 {
32  protected $subject;
33 
37  protected $dbProphecy;
38 
39  protected function setUp()
40  {
41  $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
42  $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
43 
44  $this->subject = new DatabaseEditRow();
45  }
46 
51  {
52  $input = [
53  'tableName' => 'tt_content',
54  'command' => 'edit',
55  'vanillaUid' => 10,
56  ];
57  $resultRow = [
58  'uid' => 10,
59  'pid' => 123
60  ];
61  $this->dbProphecy->quoteStr($input['tableName'], $input['tableName'])->willReturn($input['tableName']);
62  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $input['vanillaUid'])->willReturn($resultRow);
63  $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn([]);
64 
65  $result = $this->subject->addData($input);
66 
67  $this->assertSame($resultRow, $result['databaseRow']);
68  }
69 
74  {
75  $input = [
76  'tableName' => 'tt_content',
77  'command' => 'edit',
78  'vanillaUid' => 10,
79  ];
80  $resultRow = [
81  'uid' => 10,
82  ];
83  $this->dbProphecy->quoteStr($input['tableName'], $input['tableName'])->willReturn($input['tableName']);
84  $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $input['vanillaUid'])->willReturn($resultRow);
85 
86  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1437663061);
87 
88  $this->subject->addData($input);
89  }
90 
95  {
96  $input = [
97  'tableName' => 'tt_content',
98  'command' => 'edit',
99  'vanillaUid' => -10,
100  ];
101 
102  $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437656456);
103 
104  $this->subject->addData($input);
105  }
106 
111  {
112  $input = [
113  'tableName' => 'tt_content',
114  'command' => 'edit',
115  'vanillaUid' => 10,
116  ];
117 
118  $this->setExpectedException(\RuntimeException::class, $this->anything(), 1437655862);
119 
120  $this->subject->addData($input);
121  }
122 
127  {
128  $input = [
129  'tableName' => 'tt_content',
130  'command' => 'edit',
131  'vanillaUid' => 10,
132  ];
133  $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
134  $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn(false);
135 
136  $this->setExpectedException(DatabaseRecordException::class, $this->anything(), 1437656081);
137 
138  $this->subject->addData($input);
139  }
140 
145  {
146  $input = [
147  'tableName' => 'tt_content',
148  'command' => 'edit',
149  'vanillaUid' => 10,
150  ];
151  $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
152  $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn(false);
153 
154  try {
155  $this->subject->addData($input);
156  } catch (DatabaseRecordException $e) {
157  $this->assertSame('tt_content', $e->getTableName());
158  $this->assertSame(10, $e->getUid());
159  }
160  }
161 
166  {
167  $input = [
168  'tableName' => 'tt_content',
169  'command' => 'edit',
170  'vanillaUid' => 10,
171  ];
172  $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
173  $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn('invalid result data');
174 
175  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1437656323);
176 
177  $this->subject->addData($input);
178  }
179 
184  {
185  $virtualRow = [
186  'uid' => 10,
187  'pid' => 123,
188  'title' => 'Title of the virtual record'
189  ];
190  $input = [
191  'tableName' => 'virtual_table',
192  'command' => 'edit',
193  'vanillaUid' => 10,
194  'databaseRow' => $virtualRow
195  ];
196  $resultRow = $virtualRow;
197  $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->shouldNotBeCalled();
198 
199  $result = $this->subject->addData($input);
200 
201  $this->assertSame($resultRow, $result['databaseRow']);
202  }
203 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']