[BUGFIX] Adapt IndexerService to new table structures
[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 textfile 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 file indexing service
32 *
33 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
34 */
35 class IndexerServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
36
37 /**
38 * @test
39 */
40 public function indexFileUpdatesFileProperties() {
41 /** @var $fixture \TYPO3\CMS\Core\Resource\Service\IndexerService|\PHPUnit_Framework_MockObject_MockObject */
42 $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array('gatherFileInformation', 'getFileIndexRepository'));
43
44 $fileInfo = array(
45 'mount' => 1,
46 'identifier' => '/some/filepath/filename.jpg',
47 'size' => 1234,
48 'uid' => rand(1, 100),
49 'sha1' => '123',
50 );
51
52 $fixture->expects($this->any())->method('gatherFileInformation')->will($this->returnValue($fileInfo));
53
54 $repositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
55 $repositoryMock->expects($this->any())->method('findByContentHash')->will($this->returnValue(array()));
56 $fixture->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($repositoryMock));
57
58 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
59 $mockedFile->expects($this->once())->method('updateProperties');
60
61 $fixture->indexFile($mockedFile);
62 }
63
64 /**
65 * @test
66 */
67 public function indexFileSetsCreationdateAndTimestampPropertiesOfRecordToCurrentExecutionTime() {
68 $fileInfo = array();
69 /** @var $fixture \TYPO3\CMS\Core\Resource\Service\IndexerService|\PHPUnit_Framework_MockObject_MockObject */
70 $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array('gatherFileInformation', 'getFileIndexRepository'));
71
72 $fixture->expects($this->any())->method('gatherFileInformation')->will($this->returnValue($fileInfo));
73
74 $repositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
75 $repositoryMock->expects($this->any())->method('findByContentHash')->will($this->returnValue(array()));
76 $repositoryMock->expects($this->once())->method('add');
77 $fixture->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($repositoryMock));
78
79 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
80
81 $arrayConstraint = $this->logicalAnd(
82 $this->arrayHasKey('crdate'),
83 $this->arrayHasKey('tstamp'),
84 $this->contains($GLOBALS['EXEC_TIME'])
85 );
86
87 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
88
89 $fixture->indexFile($mockedFile);
90 }
91
92 }