[TASK] Tests: Remove backup of TYPO3_DB
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / Repository / AbstractRepositoryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource\Repository;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Andreas Wolf <andreas.wolf@ikt-werk.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Testcase for the abstract repository base class
32 *
33 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
34 */
35 class AbstractRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
36
37 /**
38 * @var \TYPO3\CMS\Core\Resource\AbstractRepository
39 */
40 private $fixture;
41
42 private $mockedDb;
43
44 protected function createDatabaseMock() {
45 $this->mockedDb = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
46 $GLOBALS['TYPO3_DB'] = $this->mockedDb;
47 }
48
49 public function setUp() {
50 $this->fixture = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\AbstractRepository', array(), '', FALSE);
51 }
52
53 /**
54 * @test
55 */
56 public function findByUidFailsIfUidIsString() {
57 $this->setExpectedException('InvalidArgumentException', '', 1316779798);
58 $this->fixture->findByUid('asdf');
59 }
60
61 /**
62 * @test
63 */
64 public function findByUidAcceptsNumericUidInString() {
65 $this->createDatabaseMock();
66 $this->mockedDb->expects($this->once())->method('exec_SELECTgetSingleRow')->with($this->anything(), $this->anything(), $this->stringContains('uid=' . 123))->will($this->returnValue(array('uid' => 123)));
67 $this->fixture->findByUid('123');
68 }
69
70 /**
71 * test runs on a concrete implementation of AbstractRepository
72 * to ease the pain of testing a protected method. Feel free to improve.
73 *
74 * @test
75 */
76 public function getWhereClauseForEnabledFieldsIncludesDeletedCheckInBackend() {
77 unset($GLOBALS['TSFE']);
78 $storageRepositoryMock = $this->getAccessibleMock(
79 'TYPO3\\CMS\\Core\\Resource\\StorageRepository',
80 array('dummy'),
81 array(),
82 '',
83 FALSE
84 );
85 $result = $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
86 $this->assertContains('sys_file_storage.deleted=0', $result);
87 }
88
89 /**
90 * test runs on a concrete implementation of AbstractRepository
91 * to ease the pain of testing a protected method. Feel free to improve.
92 *
93 * @test
94 */
95 public function getWhereClauseForEnabledFieldsCallsSysPageForDeletedFlagInFrontend() {
96 $GLOBALS['TSFE'] = new \stdClass();
97 $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
98 $GLOBALS['TSFE']->sys_page = $sysPageMock;
99 $sysPageMock
100 ->expects($this->once())
101 ->method('deleteClause')
102 ->with('sys_file_storage');
103 $storageRepositoryMock = $this->getAccessibleMock(
104 'TYPO3\\CMS\\Core\\Resource\\StorageRepository',
105 array('getEnvironmentMode'),
106 array(),
107 '',
108 FALSE
109 );
110 $storageRepositoryMock->expects($this->any())->method('getEnvironmentMode')->will($this->returnValue('FE'));
111 $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
112 }
113
114 }