Index: tests/typo3/sysext/cms/tslib/tslib_content_testcase.php =================================================================== --- tests/typo3/sysext/cms/tslib/tslib_content_testcase.php (revision 7453) +++ tests/typo3/sysext/cms/tslib/tslib_content_testcase.php (working copy) @@ -23,14 +23,13 @@ ***************************************************************/ /** - * Testcase for the "tslib_cObj" in the TYPO3 Core. + * Testcase for the "tslib_cObj" class in the TYPO3 Core. * * @package TYPO3 * @subpackage tslib * * @author Oliver Hader * @author Oliver Klee - * */ class tslib_content_testcase extends tx_phpunit_testcase { /** @@ -63,6 +62,7 @@ '_GET' => $_GET, '_POST' => $_POST, '_SERVER' => $_SERVER, + 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'], ); $this->template = $this->getMock( @@ -72,6 +72,8 @@ $this->tsfe->tmpl = $this->template; $this->tsfe->config = array(); $GLOBALS['TSFE'] = $this->tsfe; + $GLOBALS['TSFE']->csConvObj = new t3lib_cs(); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring'; $className = 'tslib_cObj_' . uniqid('test'); eval(' @@ -96,15 +98,36 @@ $GLOBALS['TSFE'] = null; - unset($this->cObj, $this->tsfe, $this->template,$this->typoScriptImage); + unset($this->cObj, $this->tsfe, $this->template, $this->typoScriptImage); } + + //////////////////////// + // Utitility functions + //////////////////////// + /** - * Tests whether the getImgResource hook is called correctly. + * Converts the subject and the expected result into the target charset. * + * @param string $charset the target charset + * @param string $subject the subject, will be modified + * @param string $expected the expected result, will be modified + */ + protected function handleCharset($charset, &$subject, &$expected) { + $GLOBALS['TSFE']->renderCharset = $charset; + $subject = $GLOBALS['TSFE']->csConvObj->conv($subject, 'iso-8859-1', $charset); + $expected = $GLOBALS['TSFE']->csConvObj->conv($expected, 'iso-8859-1', $charset); + } + + + ///////////////////////////////////////////// + // Tests concerning the getImgResource hook + ///////////////////////////////////////////// + + /** * @test */ - public function isGetImgResourceHookCalled() { + public function getImgResourceHookGetsCalled() { $this->template->expects($this->atLeastOnce())->method('getFileName') ->with('typo3/clear.gif')->will($this->returnValue('typo3/clear.gif')); @@ -127,6 +150,8 @@ * Handles the arguments that have been sent to the getImgResource hook. * * @return array + * + * @see getImgResourceHookGetsCalled */ public function isGetImgResourceHookCalledCallback() { list($file, $fileArray, $imageResource, $parent) = func_get_args(); @@ -174,14 +199,15 @@ ); } - ////////////////////////// + + ///////////////////////////////////////// // Tests concerning getQueryArguments() - ////////////////////////// + ///////////////////////////////////////// /** * @test */ - public function doesGetQueryArgumentsCorrectlyExcludeParameters() { + public function getQueryArgumentsExcludesParameters() { $_SERVER['QUERY_STRING'] = 'key1=value1' . '&key2=value2' . @@ -204,7 +230,7 @@ /** * @test */ - public function doesGetQueryArgumentsCorrectlyExcludeGETParameters() { + public function getQueryArgumentsExcludesGetParameters() { $_GET = array( 'key1' => 'value1', 'key2' => 'value2', @@ -233,7 +259,7 @@ /** * @test */ - public function doesGetQueryArgumentsCorrectlyOverruleSingleParameter() { + public function getQueryArgumentsOverrulesSingleParameter() { $_SERVER['QUERY_STRING'] = 'key1=value1'; $getQueryArgumentsConfiguration = array(); @@ -253,7 +279,7 @@ /** * @test */ - public function doesGetQueryArgumentsCorrectlyOverruleMultiDimensionalParameters() { + public function getQueryArgumentsOverrulesMultiDimensionalParameters() { $_POST = array( 'key1' => 'value1', 'key2' => 'value2', @@ -297,7 +323,7 @@ /** * @test */ - public function doesGetQueryArgumentsCorrectlyOverruleMultiDimensionalForcedParameters() { + public function getQueryArgumentsOverrulesMultiDimensionalForcedParameters() { $_SERVER['QUERY_STRING'] = 'key1=value1' . '&key2=value2' . @@ -346,5 +372,263 @@ $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE); $this->assertEquals($expectedResult, $actualResult); } + + + ////////////////////////////// + // Tests concerning cropHTML + ////////////////////////////// + + /** + * This is the data provider for the tests of crop and cropHTML below. It provides all combinations + * of charset, text type, and configuration options to be tested. + * + * @return array two-dimensional array with the second level like this: + * 0 => the settings for the crop function, for example "-58|..." + * 1 => the string to crop + * 2 => the expected cropped result + * 3 => the charset that will be set as renderCharset + * + * @see cropHtmlWithDataProvider + */ + public function cropHtmlDataProvider() { + $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) . + 'j implemented the original version of the crop function.'; + $textWithMarkup = 'Kasper Sk' . + chr(229) . 'rh' . chr(248) . 'j' . + ' implemented the original version of the crop function.'; + $textWithEntities = 'Kasper Skårhøj implemented the; original ' . + 'version of the crop function.'; + + $charsets = array('iso-8859-1', 'utf-8', 'ascii', 'big5'); + + $data = array(); + foreach ($charsets as $charset) { + $data = array_merge($data, array( + $charset . ' plain text; 11|...' => array( + '11|...', $plainText, 'Kasper Sk' . chr(229) . 'r...', $charset + ), + $charset . ' plain text; -58|...' => array( + '-58|...', $plainText, '...h' . chr(248) . 'j implemented the original version of the crop function.', $charset + ), + $charset . ' plain text; 20|...|1' => array( + '20|...|1', $plainText, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset + ), + $charset . ' plain text; -49|...|1' => array( + '-49|...|1', $plainText, '...the original version of the crop function.', $charset + ), + $charset . ' text with markup; 11|...' => array( + '11|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'r...', $charset + ), + $charset . ' text with markup; 13|...' => array( + '13|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . '...', $charset + ), + $charset . ' text with markup; 14|...' => array( + '14|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset + ), + $charset . ' text with markup; 15|...' => array( + '15|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j ...', $charset + ), + $charset . ' text with markup; 29|...' => array( + '29|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented th...', $charset + ), + $charset . ' text with markup; -58|...' => array( + '-58|...', $textWithMarkup, '...h' . chr(248) . 'j implemented the original version of the crop function.', $charset + ), + $charset . ' text with markup; 11|...|1' => array( + '11|...|1', $textWithMarkup, 'Kasper...', $charset + ), + $charset . ' text with markup; 13|...|1' => array( + '13|...|1', $textWithMarkup, 'Kasper...', $charset + ), + $charset . ' text with markup; 14|...|1' => array( + '14|...|1', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset + ), + $charset . ' text with markup; 15|...|1' => array( + '15|...|1', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset + ), + $charset . ' text with markup; 29|...|1' => array( + '29|...|1', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented...', $charset + ), + $charset . ' text with markup; -66|...|1' => array( + '-66|...|1', $textWithMarkup, '...Sk' . chr(229) . 'rh' . chr(248) . 'j implemented the original version of the crop function.', $charset + ), + $charset . ' text with entities 9|...' => array( + '9|...', $textWithEntities, 'Kasper Sk...', $charset + ), + $charset . ' text with entities 10|...' => array( + '10|...', $textWithEntities, 'Kasper Skå...', $charset + ), + $charset . ' text with entities 11|...' => array( + '11|...', $textWithEntities, 'Kasper Skår...', $charset + ), + $charset . ' text with entities 13|...' => array( + '13|...', $textWithEntities, 'Kasper Skårhø...', $charset + ), + $charset . ' text with entities 14|...' => array( + '14|...', $textWithEntities, 'Kasper Skårhøj...', $charset + ), + $charset . ' text with entities 15|...' => array( + '15|...', $textWithEntities, 'Kasper Skårhøj ...', $charset + ), + $charset . ' text with entities 16|...' => array( + '16|...', $textWithEntities, 'Kasper Skårhøj i...', $charset + ), + $charset . ' text with entities -57|...' => array( + '-57|...', $textWithEntities, '...j implemented the; original version of the crop function.', $charset + ), + $charset . ' text with entities -58|...' => array( + '-58|...', $textWithEntities, '...øj implemented the; original version of the crop function.', $charset + ), + $charset . ' text with entities -59|...' => array( + '-59|...', $textWithEntities, '...høj implemented the; original version of the crop function.', $charset + ), + $charset . ' text with entities 9|...|1' => array( + '9|...|1', $textWithEntities, 'Kasper...', $charset + ), + $charset . ' text with entities 10|...|1' => array( + '10|...|1', $textWithEntities, 'Kasper...', $charset + ), + $charset . ' text with entities 11|...|1' => array( + '11|...|1', $textWithEntities, 'Kasper...', $charset + ), + $charset . ' text with entities 13|...|1' => array( + '13|...|1', $textWithEntities, 'Kasper...', $charset + ), + $charset . ' text with entities 14|...|1' => array( + '14|...|1', $textWithEntities, 'Kasper Skårhøj...', $charset + ), + $charset . ' text with entities 15|...|1' => array( + '15|...|1', $textWithEntities, 'Kasper Skårhøj...', $charset + ), + $charset . ' text with entities 16|...|1' => array( + '16|...|1', $textWithEntities, 'Kasper Skårhøj...', $charset + ), + $charset . ' text with entities -57|...|1' => array( + '-57|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset + ), + $charset . ' text with entities -58|...|1' => array( + '-58|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset + ), + $charset . ' text with entities -59|...|1' => array( + '-59|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset + ), + )); + } + return $data; + } + + /** + * Checks if stdWrap.cropHTML works with plain text cropping from left + * + * @test + * + * @dataProvider cropHtmlDataProvider + * + * @param string $settings + * the settings for the crop function, for example "-58|..." + * @param string $subject the string to crop + * @param string $expected the expected cropped result + * @param string $charset the charset that will be set as renderCharset + */ + public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset) { + $this->handleCharset($charset, $subject, $expected); + + $this->assertEquals( + $expected, + $this->cObj->cropHTML($subject, $settings), + 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"' + ); + } + + /** + * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML + * counts multiple invisible characters not as one (as the browser will output the content). + * + * @test + */ + public function cropHtmlWorksWithComplexContent() { + $GLOBALS['TSFE']->renderCharset = 'iso-8859-1'; + $subject = ' +

Blog Example

+
+
+

Welcome to Blog #1

+
+

+ A blog about TYPO3 extension development. In order to start blogging, read the Help section. If you have any further questions, feel free to contact the administrator John Doe (john.doe@example.com). +

+
+

+ Below are the most recent posts: +

+
    +
  • +

    + The Post #1 +

    +

    + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut... +

    + +

    + Tags: [MVC] [Domain Driven Design] 
    + read more >>
    + Edit Delete +

    +
  • +
+

+ Create a new Post +

+
+
+

+ ? TYPO3 Association +

+'; + + $result = $this->cObj->cropHTML($subject, '300'); + $expected = ' +

Blog Example

+
+
+

Welcome to Blog #1

+
+

+ A blog about TYPO3 extension development. In order to start blogging, read the Help section. If you have any further questions, feel free to contact the administrator John Doe (john.doe@example.com). +

+
+

+ Below are the most recent posts: +

+
'; + $this->assertEquals($expected, $result); + + $result = $this->cObj->cropHTML($subject, '-100'); + $expected = '
+

+ Create a new Post +

+
+
+

+ ? TYPO3 Association +

+'; + $this->assertEquals( + $expected, + $result + ); + } } ?> \ No newline at end of file Index: typo3/sysext/cms/tests/tslib/tslib_cObj_testcase.php =================================================================== --- typo3/sysext/cms/tests/tslib/tslib_cObj_testcase.php (revision 7453) +++ typo3/sysext/cms/tests/tslib/tslib_cObj_testcase.php (working copy) @@ -1,238 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - -/** - * Testcase for class tslib_cObj - * - * @package TYPO3 - * @subpackage cms - */ -class tslib_cObj_testcase extends tx_phpunit_testcase { - - /** - * Holds the backed up $GLOBASL array() - * - * @var array - **/ - protected $backedUpGlobals; - - /** - * The content object - * - * @var tslib_cObj - **/ - protected $cObj; - /** - * Sets up this test case - */ - public function setUp() { - $this->backedUpGlobals = $GLOBALS; - $this->cObj = new tslib_cObj(); - $GLOBALS['TSFE']->csConvObj = new t3lib_cs(); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring'; - } - - /** - * Tears down this test case - */ - public function tearDown() { - $GLOBALS = $this->backedUpGlobals; - } - - /** - * This is the data provider for the tests of crop and cropHTML below. It provides all combinations - * of charset, text type, and configuration options to be tested. - * - * @return void - */ - public function providerForCrop() { - $plainText = 'Kasper Sk�rh�j implemented the original version of the crop function.'; - $textWithMarkup = 'Kasper Sk�rh�j implemented the original version of the crop function.'; - $textWithEntities = 'Kasper Skårhøj implemented the; original version of the crop function.'; - - $charsets = array(); - $charsets[] = 'iso-8859-1'; - $charsets[] = 'utf-8'; - // Enable more charsets if necessary. This will slow down overall test execution time! - // $charsets[] = 'ascii'; - // $charsets[] = 'big5'; - - $data = array(); - foreach ($charsets as $charset) { - $data = array_merge($data, array( - $charset . ' plain text; 11|...' => array('11|...', $plainText, 'Kasper Sk�r...', $charset), - $charset . ' plain text; -58|...' => array('-58|...', $plainText, '...h�j implemented the original version of the crop function.', $charset), - $charset . ' plain text; 20|...|1' => array('20|...|1', $plainText, 'Kasper Sk�rh�j...', $charset), - $charset . ' plain text; -49|...|1' => array('-49|...|1', $plainText, '...the original version of the crop function.', $charset), - $charset . ' text with markup; 11|...' => array('11|...', $textWithMarkup, 'Kasper Sk�r...', $charset), - $charset . ' text with markup; 13|...' => array('13|...', $textWithMarkup, 'Kasper Sk�rh�...', $charset), - $charset . ' text with markup; 14|...' => array('14|...', $textWithMarkup, 'Kasper Sk�rh�j...', $charset), - $charset . ' text with markup; 15|...' => array('15|...', $textWithMarkup, 'Kasper Sk�rh�j ...', $charset), - $charset . ' text with markup; 29|...' => array('29|...', $textWithMarkup, 'Kasper Sk�rh�j implemented th...', $charset), - $charset . ' text with markup; -58|...' => array('-58|...', $textWithMarkup, '...h�j implemented the original version of the crop function.', $charset), - $charset . ' text with markup; 11|...|1' => array('11|...|1', $textWithMarkup, 'Kasper...', $charset), - $charset . ' text with markup; 13|...|1' => array('13|...|1', $textWithMarkup, 'Kasper...', $charset), - $charset . ' text with markup; 14|...|1' => array('14|...|1', $textWithMarkup, 'Kasper Sk�rh�j...', $charset), - $charset . ' text with markup; 15|...|1' => array('15|...|1', $textWithMarkup, 'Kasper Sk�rh�j...', $charset), - $charset . ' text with markup; 29|...|1' => array('29|...|1', $textWithMarkup, 'Kasper Sk�rh�j implemented...', $charset), - $charset . ' text with markup; -66|...|1' => array('-66|...|1', $textWithMarkup, '...Sk�rh�j implemented the original version of the crop function.', $charset), - $charset . ' text with entities 9|...' => array('9|...', $textWithEntities, 'Kasper Sk...', $charset), - $charset . ' text with entities 10|...' => array('10|...', $textWithEntities, 'Kasper Skå...', $charset), - $charset . ' text with entities 11|...' => array('11|...', $textWithEntities, 'Kasper Skår...', $charset), - $charset . ' text with entities 13|...' => array('13|...', $textWithEntities, 'Kasper Skårhø...', $charset), - $charset . ' text with entities 14|...' => array('14|...', $textWithEntities, 'Kasper Skårhøj...', $charset), - $charset . ' text with entities 15|...' => array('15|...', $textWithEntities, 'Kasper Skårhøj ...', $charset), - $charset . ' text with entities 16|...' => array('16|...', $textWithEntities, 'Kasper Skårhøj i...', $charset), - $charset . ' text with entities -57|...' => array('-57|...', $textWithEntities, '...j implemented the; original version of the crop function.', $charset), - $charset . ' text with entities -58|...' => array('-58|...', $textWithEntities, '...øj implemented the; original version of the crop function.', $charset), - $charset . ' text with entities -59|...' => array('-59|...', $textWithEntities, '...høj implemented the; original version of the crop function.', $charset), - $charset . ' text with entities 9|...|1' => array('9|...|1', $textWithEntities, 'Kasper...', $charset), - $charset . ' text with entities 10|...|1' => array('10|...|1', $textWithEntities, 'Kasper...', $charset), - $charset . ' text with entities 11|...|1' => array('11|...|1', $textWithEntities, 'Kasper...', $charset), - $charset . ' text with entities 13|...|1' => array('13|...|1', $textWithEntities, 'Kasper...', $charset), - $charset . ' text with entities 14|...|1' => array('14|...|1', $textWithEntities, 'Kasper Skårhøj...', $charset), - $charset . ' text with entities 15|...|1' => array('15|...|1', $textWithEntities, 'Kasper Skårhøj...', $charset), - $charset . ' text with entities 16|...|1' => array('16|...|1', $textWithEntities, 'Kasper Skårhøj...', $charset), - $charset . ' text with entities -57|...|1' => array('-57|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset), - $charset . ' text with entities -58|...|1' => array('-58|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset), - $charset . ' text with entities -59|...|1' => array('-59|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset) - )); - } - return $data; - } - - /** - * Checks if stdWrap.cropHTML works with plain text cropping from left - * - * @test - * @dataProvider providerForCrop - */ - public function cropHtmlWorks($settings, $subject, $expected, $charset) { - $this->handleCharset($charset, $subject, $expected); - $this->assertEquals($expected, $this->cObj->cropHTML($subject, $settings), 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"'); - } - - /** - * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML - * counts multiple invisible characters not as one (as the browser will output the content). - * - * @test - */ - public function cropHtmlWorksWithComplexContent() { - $GLOBALS['TSFE']->renderCharset = 'iso-8859-1'; - $subject = ' -

Blog Example

-
-
-

Welcome to Blog #1

-
-

- A blog about TYPO3 extension development. In order to start blogging, read the Help section. If you have any further questions, feel free to contact the administrator John Doe (john.doe@example.com). -

-
-

- Below are the most recent posts: -

-
    -
  • -

    - The Post #1 -

    -

    - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut... -

    - -

    - Tags: [MVC] [Domain Driven Design] 
    - read more >>
    - Edit Delete -

    -
  • -
-

- Create a new Post -

-
-
-

- � TYPO3 Association -

-'; - - $result = $this->cObj->cropHTML($subject, '300'); - $expected = ' -

Blog Example

-
-
-

Welcome to Blog #1

-
-

- A blog about TYPO3 extension development. In order to start blogging, read the Help section. If you have any further questions, feel free to contact the administrator John Doe (john.doe@example.com). -

-
-

- Below are the most recent posts: -

-
'; - $this->assertEquals($expected, $result); - - $result = $this->cObj->cropHTML($subject, '-100'); - $expected = '
-

- Create a new Post -

-
-
-

- � TYPO3 Association -

-'; - $this->assertEquals($expected, $result); - } - - /** - * Converts the subject and the expected result into the target charset. - * - * @param string $charset The target charset - * @param string $subject The subject - * @param string $expected The expected result - * @return void - */ - protected function handleCharset($charset, &$subject, &$expected) { - $GLOBALS['TSFE']->renderCharset = $charset; - $subject = $GLOBALS['TSFE']->csConvObj->conv($subject, 'iso-8859-1', $charset); - $expected = $GLOBALS['TSFE']->csConvObj->conv($expected, 'iso-8859-1', $charset); - } -} -?> \ No newline at end of file