[TASK] Re-work/simplify copyright header in PHP files - Part 4
[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 * 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
17 /**
18 * Test case
19 *
20 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
21 */
22 class AbstractRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Core\Resource\AbstractRepository
26 */
27 protected $subject;
28
29 protected $mockedDb;
30
31 protected function createDatabaseMock() {
32 $this->mockedDb = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
33 $GLOBALS['TYPO3_DB'] = $this->mockedDb;
34 }
35
36 public function setUp() {
37 $this->subject = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\AbstractRepository', array(), '', FALSE);
38 }
39
40 /**
41 * @test
42 */
43 public function findByUidFailsIfUidIsString() {
44 $this->setExpectedException('InvalidArgumentException', '', 1316779798);
45 $this->subject->findByUid('asdf');
46 }
47
48 /**
49 * @test
50 */
51 public function findByUidAcceptsNumericUidInString() {
52 $this->createDatabaseMock();
53 $this->mockedDb->expects($this->once())->method('exec_SELECTgetSingleRow')->with($this->anything(), $this->anything(), $this->stringContains('uid=' . 123))->will($this->returnValue(array('uid' => 123)));
54 $this->subject->findByUid('123');
55 }
56
57 /**
58 * test runs on a concrete implementation of AbstractRepository
59 * to ease the pain of testing a protected method. Feel free to improve.
60 *
61 * @test
62 */
63 public function getWhereClauseForEnabledFieldsIncludesDeletedCheckInBackend() {
64 $GLOBALS['TCA'] = array(
65 'sys_file_storage' => array(
66 'ctrl' => array(
67 'delete' => 'deleted',
68 ),
69 ),
70 );
71 /** @var \TYPO3\CMS\Core\Resource\StorageRepository|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $storageRepositoryMock */
72 $storageRepositoryMock = $this->getAccessibleMock(
73 'TYPO3\\CMS\\Core\\Resource\\StorageRepository',
74 array('dummy'),
75 array(),
76 '',
77 FALSE
78 );
79 $result = $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
80 $this->assertContains('sys_file_storage.deleted=0', $result);
81 }
82
83 /**
84 * test runs on a concrete implementation of AbstractRepository
85 * to ease the pain of testing a protected method. Feel free to improve.
86 *
87 * @test
88 */
89 public function getWhereClauseForEnabledFieldsCallsSysPageForDeletedFlagInFrontend() {
90 $GLOBALS['TSFE'] = new \stdClass();
91 $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
92 $GLOBALS['TSFE']->sys_page = $sysPageMock;
93 $sysPageMock
94 ->expects($this->once())
95 ->method('deleteClause')
96 ->with('sys_file_storage');
97 $storageRepositoryMock = $this->getAccessibleMock(
98 'TYPO3\\CMS\\Core\\Resource\\StorageRepository',
99 array('getEnvironmentMode'),
100 array(),
101 '',
102 FALSE
103 );
104 $storageRepositoryMock->expects($this->any())->method('getEnvironmentMode')->will($this->returnValue('FE'));
105 $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
106 }
107
108 }