[BUGFIX] Tests: Incomplete mock in IndexerServiceTest
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / Service / IndexerServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource\Service;
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 */
34 class IndexerServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
35
36 /**
37 * @test
38 */
39 public function indexFileUpdatesFileProperties() {
40 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
41
42 /** @var $subject \TYPO3\CMS\Core\Resource\Service\IndexerService|\PHPUnit_Framework_MockObject_MockObject */
43 $subject = $this->getMock(
44 'TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService',
45 array('gatherFileInformation', 'getFileIndexRepository', 'emitPreFileIndexSignal', 'emitPostFileIndexSignal')
46 );
47
48 $fileInfo = array(
49 'mount' => 1,
50 'identifier' => '/some/filepath/filename.jpg',
51 'size' => 1234,
52 'uid' => rand(1, 100),
53 'sha1' => '123',
54 );
55
56 $subject->expects($this->any())->method('gatherFileInformation')->will($this->returnValue($fileInfo));
57
58 $repositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
59 $repositoryMock->expects($this->any())->method('findByContentHash')->will($this->returnValue(array()));
60 $subject->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($repositoryMock));
61
62 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
63 $mockedFile->expects($this->once())->method('updateProperties');
64
65 $subject->indexFile($mockedFile);
66 }
67
68 /**
69 * @test
70 */
71 public function indexFileSetsCreationdateAndTimestampPropertiesOfRecordToCurrentExecutionTime() {
72 $fileInfo = array();
73 /** @var $subject \TYPO3\CMS\Core\Resource\Service\IndexerService|\PHPUnit_Framework_MockObject_MockObject */
74 $subject = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array('gatherFileInformation', 'getFileIndexRepository'));
75
76 $subject->expects($this->any())->method('gatherFileInformation')->will($this->returnValue($fileInfo));
77
78 $repositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
79 $repositoryMock->expects($this->any())->method('findByContentHash')->will($this->returnValue(array()));
80 $repositoryMock->expects($this->once())->method('add');
81 $subject->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($repositoryMock));
82
83 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
84
85 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
86
87 $subject->indexFile($mockedFile);
88 }
89 }