Project

General

Profile

Bug #18535 » CropTest.php

Administrator Admin, 2008-04-10 12:21

 
<?php
declare(ENCODING = 'utf-8');

/* *
* This script is part of the TYPO3 project - inspiring people to share! *
* *
* TYPO3 is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License version 2 as published by *
* the Free Software Foundation. *
* *
* This script is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
* Public License for more details. *
* */

require_once 'PHPUnit/Framework.php';
define('PATH_t3lib', '/Applications/MAMP/htdocs/t3dev/t3lib/');

/**
* Testcase for class tslib_content
*/
class CropTest extends PHPUnit_Framework_TestCase {
/**
* Sets up this test case
*/
public function setUp() {
require_once '/Applications/MAMP/htdocs/t3dev/typo3/sysext/cms/tslib/class.tslib_content.php';
$this->cObj = new tslib_cObj();
require_once '/Applications/MAMP/htdocs/t3dev/t3lib/class.t3lib_cs.php';
$GLOBALS['TSFE']->csConvObj = new t3lib_cs();
$GLOBALS['TSFE']->renderCharset = 'utf-8';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring';
}
/**
* Checks if stdWrap.crop works with plain text cropping from left
*
* @test
*/
public function cropWorksWithPlainTextCroppingFromLeft() {
$subject = 'Kasper Skårhøj implemented the original version of the crop function.';
$result = $this->cObj->crop($subject, '11|...');
$expected = 'Kasper Skår...';
$this->assertEquals($expected, $result);
}
/**
* Checks if stdWrap.crop works with plain text cropping from right
*
* @test
*/
public function cropWorksWithPlainTextCroppingFromRight() {
$subject = 'Kasper Skårhøj implemented the original version of the crop function.';
$result = $this->cObj->crop($subject, '-58|...');
$expected = '...høj implemented the original version of the crop function.';
$this->assertEquals($expected, $result);
}
/**
* Checks if stdWrap.crop works with html-markup cropping from left
*
* @test
*/
public function cropWorksWithHtmlMarkupCroppingFromLeft() {
$subject = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a> implemented</strong> the original version of the crop function.';

$result = $this->cObj->crop($subject, '11|...');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper Skår...</a></strong>';
$this->assertEquals($expected, $result, 'chars to crop: 11');

$result = $this->cObj->crop($subject, '14|...');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a>...</strong>';
$this->assertEquals($expected, $result, 'chars to crop: 14');

$result = $this->cObj->crop($subject, '13|...');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhø...</a></strong>';
$this->assertEquals($expected, $result, 'chars to crop: 13');

$result = $this->cObj->crop($subject, '15|...');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a> ...</strong>';
$this->assertEquals($expected, $result, 'chars to crop: 15');

$result = $this->cObj->crop($subject, '29|...');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a> implemented</strong> th...';
$this->assertEquals($expected, $result, 'chars to crop: 29');
}
/**
* Checks if stdWrap.crop works with html-markup cropping from right
*
* @test
*/
public function cropWorksWithHtmlMarkupCroppingFromRight() {
$subject = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a> implemented</strong> the original version of the crop function.';
$result = $this->cObj->crop($subject, '-58|...');
$expected = '<strong><a href="mailto:kasper@typo3.org">...høj</a> implemented</strong> the original version of the crop function.';
$this->assertEquals($expected, $result);
}
/**
* Checks if stdWrap.crop works with html-enities cropping from left
*
* @test
*/
public function cropWorksWithHtmlEntitiesCroppingFromLeft() {
$subject = 'Kasper Sk&aring;rh&oslash;j implemented the original version of the crop function.';

$result = $this->cObj->crop($subject, '9|...');
$expected = 'Kasper Sk...';
$this->assertEquals($expected, $result, 'chars to crop: 9');

$result = $this->cObj->crop($subject, '10|...');
$expected = 'Kasper Sk&aring;...';
$this->assertEquals($expected, $result, 'chars to crop: 10');

$result = $this->cObj->crop($subject, '11|...');
$expected = 'Kasper Sk&aring;r...';
$this->assertEquals($expected, $result, 'chars to crop: 11');

$subject = '&gt;&gt;&gt;&gt;';

$result = $this->cObj->crop($subject, '2|...');
$expected = '&gt;&gt;...';
$this->assertEquals($expected, $result, 'chars to crop: 2');

$subject = '&gt;&gt;3&gt;2; 4&gt;3;&gt;&gt;&gt;&gt;&gt;';

$result = $this->cObj->crop($subject, '3|...');
$expected = '&gt;&gt;3...';
$this->assertEquals($expected, $result, 'chars to crop: 3');

$result = $this->cObj->crop($subject, '4|...');
$expected = '&gt;&gt;3&gt;...';
$this->assertEquals($expected, $result, 'chars to crop: 4');

$result = $this->cObj->crop($subject, '5|...');
$expected = '&gt;&gt;3&gt;2...';
$this->assertEquals($expected, $result, 'chars to crop: 5');

$result = $this->cObj->crop($subject, '6|...');
$expected = '&gt;&gt;3&gt;2;...';
$this->assertEquals($expected, $result, 'chars to crop: 6');
}
/**
* Checks if stdWrap.crop works with html-enities cropping from right
*
* @test
*/
public function cropWorksWithHtmlEntitiesCroppingFromRight() {
$subject = 'Kasper Sk&aring;rh&oslash;j implemented the original version of the crop function.';

$result = $this->cObj->crop($subject, '-56|...');
$expected = '...j implemented the original version of the crop function.';
$this->assertEquals($expected, $result, 'chars to crop: 56');

$result = $this->cObj->crop($subject, '-57|...');
$expected = '...&oslash;j implemented the original version of the crop function.';
$this->assertEquals($expected, $result, 'chars to crop: 57');

$result = $this->cObj->crop($subject, '-58|...');
$expected = '...h&oslash;j implemented the original version of the crop function.';
$this->assertEquals($expected, $result, 'chars to crop: 58');
}

/**
* Checks if stdWrap.crop works with plain text cropping to space from left
*
* @test
*/
public function cropWorksWithPlainTextCroppingToSpaceFromLeft() {
$subject = 'Kasper Skårhøj implemented the original version of the crop function.';
$result = $this->cObj->crop($subject, '20|...|1');
$expected = 'Kasper Skårhøj...';
$this->assertEquals($expected, $result);
}
/**
* Checks if stdWrap.crop works with plain text cropping to space from right
*
* @test
*/
public function cropWorksWithPlainTextCroppingToSpaceFromRight() {
$subject = 'Kasper Skårhøj implemented the original version of the crop function.';
$result = $this->cObj->crop($subject, '-49|...|1');
$expected = '...the original version of the crop function.';
$this->assertEquals($expected, $result);
}
/**
* Checks if stdWrap.crop works with html-markup cropping to space from left
*
* @test
*/
public function cropWorksWithHtmlMarkupCroppingToSpaceFromLeft() {
$subject = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a> implemented</strong> the original version of the crop function.';

$result = $this->cObj->crop($subject, '11|...|1');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>';
$this->assertEquals($expected, $result, 'chars to crop: 11');

$result = $this->cObj->crop($subject, '14|...|1');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a>...</strong>';
$this->assertEquals($expected, $result, 'chars to crop: 14');

$result = $this->cObj->crop($subject, '13|...|1');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>';
$this->assertEquals($expected, $result, 'chars to crop: 13');

$result = $this->cObj->crop($subject, '15|...|1');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a>...</strong>';
$this->assertEquals($expected, $result, 'chars to crop: 15');

$result = $this->cObj->crop($subject, '29|...|1');
$expected = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a> implemented</strong>...';
$this->assertEquals($expected, $result, 'chars to crop: 29');
}
/**
* Checks if stdWrap.crop works with html-markup cropping to space from right
*
* @test
*/
public function cropWorksWithHtmlMarkupCroppingToSpaceFromRight() {
$subject = '<strong><a href="mailto:kasper@typo3.org">Kasper Skårhøj</a> implemented</strong> the original version of the crop function.';

$result = $this->cObj->crop($subject, '-66|...|1');
$expected = '<strong><a href="mailto:kasper@typo3.org">...Skårhøj</a> implemented</strong> the original version of the crop function.';
$this->assertEquals($expected, $result, 'chars to crop: 66');

// $result = $this->cObj->crop($subject, '-58|...|1');
// $expected = '<strong>...implemented</strong> the original version of the crop function.';
// $this->assertEquals($expected, $result, 'chars to crop: 58');
}
/**
* Checks if stdWrap.crop works with html-enities cropping to space from left
*
* @test
*/
public function cropWorksWithHtmlEntitiesCroppingToSpaceFromLeft() {
$subject = 'Kasper Sk&aring;rh&oslash;j implemented the original version of the crop function.';

$result = $this->cObj->crop($subject, '9|...|1');
$expected = 'Kasper...';
$this->assertEquals($expected, $result, 'chars to crop: 9');

$result = $this->cObj->crop($subject, '10|...|1');
$expected = 'Kasper...';
$this->assertEquals($expected, $result, 'chars to crop: 10');

$result = $this->cObj->crop($subject, '11|...|1');
$expected = 'Kasper...';
$this->assertEquals($expected, $result, 'chars to crop: 11');
}
/**
* Checks if stdWrap.crop works with html-enities cropping to space from right
*
* @test
*/
public function cropWorksWithHtmlEntitiesCroppingToSpaceFromRight() {
$subject = 'Kasper Sk&aring;rh&oslash;j implemented the original version of the crop function.';

$result = $this->cObj->crop($subject, '-56|...|1');
$expected = '...implemented the original version of the crop function.';
$this->assertEquals($expected, $result, 'chars to crop: 56');

$result = $this->cObj->crop($subject, '-57|...|1');
$expected = '...implemented the original version of the crop function.';
$this->assertEquals($expected, $result, 'chars to crop: 57');

$result = $this->cObj->crop($subject, '-58|...|1');
$expected = '...implemented the original version of the crop function.';
$this->assertEquals($expected, $result, 'chars to crop: 58');
}
}
?>
(6-6/8)