[TASK] Fix typo in copyright notice
[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 private $Typo3DbBackup;
45
46 protected function createDatabaseMock() {
47 $this->mockedDb = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
48 $this->Typo3DbBackup = $GLOBALS['TYPO3_DB'];
49 $GLOBALS['TYPO3_DB'] = $this->mockedDb;
50 }
51
52 public function setUp() {
53 $this->fixture = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\AbstractRepository', array(), '', FALSE);
54 }
55
56 public function tearDown() {
57 if ($this->mockedDb) {
58 $GLOBALS['TYPO3_DB'] = $this->Typo3DbBackup;
59 }
60 }
61
62 /**
63 * @test
64 */
65 public function findByUidFailsIfUidIsString() {
66 $this->setExpectedException('InvalidArgumentException', '', 1316779798);
67 $this->fixture->findByUid('asdf');
68 }
69
70 /**
71 * @test
72 */
73 public function findByUidAcceptsNumericUidInString() {
74 $this->createDatabaseMock();
75 $this->mockedDb->expects($this->once())->method('exec_SELECTgetSingleRow')->with($this->anything(), $this->anything(), $this->stringContains('uid=' . 123))->will($this->returnValue(array('uid' => 123)));
76 $this->fixture->findByUid('123');
77 }
78
79 /**
80 * test runs on a concrete implementation of AbstractRepository
81 * to ease the pain of testing a protected method. Feel free to improve.
82 *
83 * @test
84 */
85 public function getWhereClauseForEnabledFieldsIncludesDeletedCheckInBackend() {
86 unset($GLOBALS['TSFE']);
87 $storageRepositoryMock = $this->getAccessibleMock(
88 'TYPO3\\CMS\\Core\\Resource\\StorageRepository',
89 array('dummy'),
90 array(),
91 '',
92 FALSE
93 );
94 $result = $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
95 $this->assertContains('sys_file_storage.deleted=0', $result);
96 }
97
98 /**
99 * test runs on a concrete implementation of AbstractRepository
100 * to ease the pain of testing a protected method. Feel free to improve.
101 *
102 * @test
103 */
104 public function getWhereClauseForEnabledFieldsCallsSysPageForDeletedFlagInFrontend() {
105 $GLOBALS['TSFE'] = new \stdClass();
106 $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
107 $GLOBALS['TSFE']->sys_page = $sysPageMock;
108 $sysPageMock
109 ->expects($this->once())
110 ->method('deleteClause')
111 ->with('sys_file_storage');
112 $storageRepositoryMock = $this->getAccessibleMock(
113 'TYPO3\\CMS\\Core\\Resource\\StorageRepository',
114 array('getEnvironmentMode'),
115 array(),
116 '',
117 FALSE
118 );
119 $storageRepositoryMock->expects($this->any())->method('getEnvironmentMode')->will($this->returnValue('FE'));
120 $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
121 }
122
123 }