TYPO3 API  SVNRelease
CropViewHelperTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script belongs to the FLOW3 package "Fluid".                      *
00005  *                                                                        *
00006  * It is free software; you can redistribute it and/or modify it under    *
00007  * the terms of the GNU General Public License as published by the Free   *
00008  * Software Foundation, either version 3 of the License, or (at your      *
00009  * option) any later version.                                             *
00010  *                                                                        *
00011  * This script is distributed in the hope that it will be useful, but     *
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00013  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
00014  * Public License for more details.                                       *
00015  *                                                                        *
00016  * You should have received a copy of the GNU General Public License      *
00017  * along with the script.                                                 *
00018  * If not, see http://www.gnu.org/licenses/gpl.html                       *
00019  *                                                                        *
00020  * The TYPO3 project - inspiring people to share!                         *
00021  *                                                                        */
00022 
00023 /**
00024  */
00025 class Tx_Fluid_Tests_Unit_ViewHelpers_Format_CropViewHelperTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
00026 
00027     /**
00028      * var Tx_Fluid_ViewHelpers_Format_CropViewHelper
00029      */
00030     protected $viewHelper;
00031 
00032     /**
00033      * @var tslib_cObj
00034      */
00035     protected $mockContentObject;
00036 
00037     /**
00038      * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
00039      */
00040     protected $mockConfigurationManager;
00041 
00042     public function setUp() {
00043         parent::setUp();
00044 
00045         $this->mockContentObject = $this->getMock('tslib_cObj', array(), array(), '', FALSE);
00046         $this->mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00047         $this->mockConfigurationManager->expects($this->any())->method('getContentObject')->will($this->returnValue($this->mockContentObject));
00048         $this->viewHelper = $this->getMock('Tx_Fluid_ViewHelpers_Format_CropViewHelper', array('renderChildren'));
00049         $this->viewHelper->injectConfigurationManager($this->mockConfigurationManager);
00050         $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Some Content'));
00051     }
00052 
00053     /**
00054      * @test
00055      * @author Bastian Waidelich <bastian@typo3.org>
00056      */
00057     public function viewHelperCallsCropHtmlByDefault() {
00058         $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content'));
00059         $actualResult = $this->viewHelper->render(123);
00060         $this->assertEquals('Cropped Content', $actualResult);
00061     }
00062 
00063     /**
00064      * @test
00065      * @author Bastian Waidelich <bastian@typo3.org>
00066      */
00067     public function viewHelperCallsCropHtmlByDefault2() {
00068         $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '-321|custom suffix|1')->will($this->returnValue('Cropped Content'));
00069         $actualResult = $this->viewHelper->render(-321, 'custom suffix');
00070         $this->assertEquals('Cropped Content', $actualResult);
00071     }
00072 
00073     /**
00074      * @test
00075      * @author Bastian Waidelich <bastian@typo3.org>
00076      */
00077     public function respectWordBoundariesCanBeDisabled() {
00078         $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|...|')->will($this->returnValue('Cropped Content'));
00079         $actualResult = $this->viewHelper->render(123, '...', FALSE);
00080         $this->assertEquals('Cropped Content', $actualResult);
00081     }
00082 
00083     /**
00084      * @test
00085      * @author Bastian Waidelich <bastian@typo3.org>
00086      */
00087     public function respectHtmlCanBeDisabled() {
00088         $this->mockContentObject->expects($this->once())->method('crop')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content'));
00089         $actualResult = $this->viewHelper->render(123, '...', TRUE, FALSE);
00090         $this->assertEquals('Cropped Content', $actualResult);
00091     }
00092 }
00093 ?>