[BUGFIX] Tests: Incomplete mocking of $GLOBALS['TCA'] in ext:core
[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 * Test case
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 protected $subject;
41
42 protected $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->subject = $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->subject->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->subject->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 $GLOBALS['TCA'] = array(
78 'sys_file_storage' => array(
79 'ctrl' => array(
80 'delete' => 'deleted',
81 ),
82 ),
83 );
84 /** @var \TYPO3\CMS\Core\Resource\StorageRepository|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $storageRepositoryMock */
85 $storageRepositoryMock = $this->getAccessibleMock(
86 'TYPO3\\CMS\\Core\\Resource\\StorageRepository',
87 array('dummy'),
88 array(),
89 '',
90 FALSE
91 );
92 $result = $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
93 $this->assertContains('sys_file_storage.deleted=0', $result);
94 }
95
96 /**
97 * test runs on a concrete implementation of AbstractRepository
98 * to ease the pain of testing a protected method. Feel free to improve.
99 *
100 * @test
101 */
102 public function getWhereClauseForEnabledFieldsCallsSysPageForDeletedFlagInFrontend() {
103 $GLOBALS['TSFE'] = new \stdClass();
104 $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
105 $GLOBALS['TSFE']->sys_page = $sysPageMock;
106 $sysPageMock
107 ->expects($this->once())
108 ->method('deleteClause')
109 ->with('sys_file_storage');
110 $storageRepositoryMock = $this->getAccessibleMock(
111 'TYPO3\\CMS\\Core\\Resource\\StorageRepository',
112 array('getEnvironmentMode'),
113 array(),
114 '',
115 FALSE
116 );
117 $storageRepositoryMock->expects($this->any())->method('getEnvironmentMode')->will($this->returnValue('FE'));
118 $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
119 }
120
121 }