TYPO3 CMS  TYPO3_7-6
AbstractRepositoryTest.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 
21 {
25  protected $subject;
26 
27  protected $mockedDb;
28 
29  protected function createDatabaseMock()
30  {
31  $this->mockedDb = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
32  $GLOBALS['TYPO3_DB'] = $this->mockedDb;
33  }
34 
35  protected function setUp()
36  {
37  $this->subject = $this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\AbstractRepository::class, [], '', false);
38  }
39 
43  public function findByUidFailsIfUidIsString()
44  {
45  $this->setExpectedException('InvalidArgumentException', '', 1316779798);
46  $this->subject->findByUid('asdf');
47  }
48 
53  {
54  $this->createDatabaseMock();
55  $this->mockedDb->expects($this->once())->method('exec_SELECTgetSingleRow')->with($this->anything(), $this->anything(), $this->stringContains('uid=' . 123))->will($this->returnValue(['uid' => 123]));
56  $this->subject->findByUid('123');
57  }
58 
65  public function getWhereClauseForEnabledFieldsIncludesDeletedCheckInBackend()
66  {
67  $GLOBALS['TCA'] = [
68  'sys_file_storage' => [
69  'ctrl' => [
70  'delete' => 'deleted',
71  ],
72  ],
73  ];
75  $storageRepositoryMock = $this->getAccessibleMock(
76  \TYPO3\CMS\Core\Resource\StorageRepository::class,
77  ['dummy'],
78  [],
79  '',
80  false
81  );
82  $result = $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
83  $this->assertContains('sys_file_storage.deleted=0', $result);
84  }
85 
93  {
94  $GLOBALS['TSFE'] = new \stdClass();
95  $sysPageMock = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepository::class);
96  $GLOBALS['TSFE']->sys_page = $sysPageMock;
97  $sysPageMock
98  ->expects($this->once())
99  ->method('deleteClause')
100  ->with('sys_file_storage');
101  $storageRepositoryMock = $this->getAccessibleMock(
102  \TYPO3\CMS\Core\Resource\StorageRepository::class,
103  ['getEnvironmentMode'],
104  [],
105  '',
106  false
107  );
108  $storageRepositoryMock->expects($this->any())->method('getEnvironmentMode')->will($this->returnValue('FE'));
109  $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
110  }
111 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']