fef6c85ec4cbf223c275a420485cc30713ba1147
[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', 'getRepository'));
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\\FileRepository', array('findBySha1Hash'));
55 $repositoryMock->expects($this->any())->method('findBySha1Hash')->will($this->returnValue(array()));
56 $fixture->expects($this->any())->method('getRepository')->will($this->returnValue($repositoryMock));
57
58 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
59 $GLOBALS['TYPO3_DB']->expects($this->atLeastOnce())->method('sql_insert_id')->will($this->returnValue($fileInfo['uid']));
60
61 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
62 $mockedFile->expects($this->once())->method('updateProperties')->with($this->equalTo($fileInfo));
63
64 $fixture->indexFile($mockedFile);
65 }
66
67 /**
68 * @test
69 */
70 public function indexFileSetsCreationdateAndTimestampPropertiesOfRecordToCurrentExecutionTime() {
71 $fileInfo = array();
72 /** @var $fixture \TYPO3\CMS\Core\Resource\Service\IndexerService|\PHPUnit_Framework_MockObject_MockObject */
73 $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array('gatherFileInformation', 'getRepository'));
74
75 $fixture->expects($this->any())->method('gatherFileInformation')->will($this->returnValue($fileInfo));
76
77 $repositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository', array('findBySha1Hash'));
78 $repositoryMock->expects($this->any())->method('findBySha1Hash')->will($this->returnValue(array()));
79 $fixture->expects($this->any())->method('getRepository')->will($this->returnValue($repositoryMock));
80
81 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
82
83 $arrayConstraint = $this->logicalAnd(
84 $this->arrayHasKey('crdate'),
85 $this->arrayHasKey('tstamp'),
86 $this->contains($GLOBALS['EXEC_TIME'])
87 );
88
89 $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_INSERTquery')->with($this->anything(), $arrayConstraint);
90
91 $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
92
93 $fixture->indexFile($mockedFile);
94 }
95
96 }