TYPO3 CMS  TYPO3_6-2
LocalPreviewHelperTest.php
Go to the documentation of this file.
1 <?php
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 
18 
23 
28  $file = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\File')
29  ->disableOriginalConstructor()
30  ->getMock();
31  // Use size slightly larger than default size to ensure processing
32  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap(array(
33  array('width', 65),
34  array('height', 65),
35  )));
36 
37  $task = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Processing\\TaskInterface');
38  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
39  $task->expects($this->once())->method('getConfiguration')->willReturn(array());
40 
41  $localPreviewHelper = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\Processing\\LocalPreviewHelper')
42  ->disableOriginalConstructor()
43  ->setMethods(array('getTemporaryFilePath', 'generatePreviewFromFile'))
44  ->getMock();
45  $localPreviewHelper->expects($this->once())->method('getTemporaryFilePath')->willReturn('test/file');
46  // Assert that by default 64x64 is used as preview size
47  $localPreviewHelper->expects($this->once())->method('generatePreviewFromFile')
48  ->with($file, array('width' => 64, 'height' => 64), 'test/file');
49 
50  $localPreviewHelper->process($task);
51  }
52 
56  public function processDoesNotScaleUpImages() {
57  $file = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\File')
58  ->disableOriginalConstructor()
59  ->getMock();
60  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap(array(
61  array('width', 20),
62  array('height', 20),
63  )));
64 
65  $localPreviewHelper = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\Processing\\LocalPreviewHelper')
66  ->disableOriginalConstructor()
67  ->setMethods(array('dummy'))
68  ->getMock();
69 
70  $task = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Processing\\TaskInterface');
71  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
72  $task->expects($this->once())->method('getConfiguration')->willReturn(array('width' => 30, 'height' => 30));
73 
74  $this->assertNull($localPreviewHelper->process($task));
75  }
76 
81  $file = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\File')
82  ->disableOriginalConstructor()
83  ->getMock();
84  $file->expects($this->any())->method('getProperty')->will($this->returnValueMap(array(
85  array('width', 0),
86  array('height', 0),
87  )));
88 
89  $task = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Processing\\TaskInterface');
90  $task->expects($this->once())->method('getSourceFile')->willReturn($file);
91  $task->expects($this->once())->method('getConfiguration')->willReturn(array());
92 
93  $localPreviewHelper = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\Processing\\LocalPreviewHelper')
94  ->disableOriginalConstructor()
95  ->setMethods(array('getTemporaryFilePath', 'generatePreviewFromFile'))
96  ->getMock();
97  $expectedResult = array('width' => 20, 'height' => 20, 'filePath' => 'test/file');
98  $localPreviewHelper->expects($this->once())->method('generatePreviewFromFile')->willReturn($expectedResult);
99 
100  $this->assertEquals($expectedResult, $localPreviewHelper->process($task));
101  }
102 }