Skip to content

Commit

Permalink
Merge pull request #687 from NamelessCoder/coverage
Browse files Browse the repository at this point in the history
[TASK] Increase coverage
  • Loading branch information
cedricziel committed Oct 4, 2014
2 parents 618cd1d + 8257bd7 commit 5a87da2
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 19 deletions.
5 changes: 2 additions & 3 deletions Classes/ViewHelpers/System/DateTimeViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\System;

/***************************************************************
* Copyright notice
*
Expand All @@ -25,6 +24,8 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
* ### System: DateTime
*
Expand All @@ -34,8 +35,6 @@
* @package Vhs
* @subpackage ViewHelpers\System
*/
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

class DateTimeViewHelper extends AbstractViewHelper {

/**
Expand Down
5 changes: 2 additions & 3 deletions Classes/ViewHelpers/System/TimestampViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\System;

/***************************************************************
* Copyright notice
*
Expand All @@ -25,6 +24,8 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
* ### System: UNIX Timestamp
*
Expand All @@ -38,8 +39,6 @@
* @package Vhs
* @subpackage ViewHelpers\System
*/
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

class TimestampViewHelper extends AbstractViewHelper {

/**
Expand Down
5 changes: 2 additions & 3 deletions Classes/ViewHelpers/System/UniqIdViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\System;

/***************************************************************
* Copyright notice
*
Expand All @@ -25,6 +24,8 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
* ### System: Unique ID
*
Expand All @@ -37,8 +38,6 @@
* @package Vhs
* @subpackage ViewHelpers\System
*/
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

class UniqIdViewHelper extends AbstractViewHelper {

/**
Expand Down
31 changes: 31 additions & 0 deletions Tests/Unit/ViewHelpers/Format/CaseViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,35 @@
*/
class CaseViewHelperTest extends AbstractViewHelperTest {

/**
* @test
* @dataProvider getInputsAndExpectedOutputs
* @param string $input
* @param string $case
* @param string $expectedOutput
*/
public function convertsToExpectedFormat($input, $case, $expectedOutput) {
$result1 = $this->executeViewHelper(array('string' => $input, 'case' => $case));
$result2 = $this->executeViewHelperUsingTagContent('Text', $input, array('case' => $case));
$this->assertEquals($expectedOutput, $result1);
$this->assertEquals($expectedOutput, $result2);
}

/**
* @return array
*/
public function getInputsAndExpectedOutputs() {
return array(
array('lowerstring', CaseViewHelper::CASE_UPPER, 'LOWERSTRING'),
array('UPPERSTRING', CaseViewHelper::CASE_LOWER, 'upperstring'),
array('lots of words', CaseViewHelper::CASE_UCWORDS, 'Lots Of Words'),
array('lowerstring', CaseViewHelper::CASE_UCFIRST, 'Lowerstring'),
array('UPPERSTRING', CaseViewHelper::CASE_LCFIRST, 'uPPERSTRING'),
array('lowercase_underscored', CaseViewHelper::CASE_CAMELCASE, 'LowercaseUnderscored'),
array('lowercase_underscored', CaseViewHelper::CASE_LOWERCAMELCASE, 'lowercaseUnderscored'),
array('CamelCase', CaseViewHelper::CASE_UNDERSCORED, 'camel_case'),
array('unknown format MIXED WITH All Cases', 'unsupported', 'unknown format MIXED WITH All Cases')
);
}

}
11 changes: 11 additions & 0 deletions Tests/Unit/ViewHelpers/Format/Url/DecodeViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@
*/
class DecodeViewHelperTest extends AbstractViewHelperTest {

/**
* @test
*/
public function decodesUrlEncodedStrings() {
$encoded = 'Url%20Encoded';
$result1 = $this->executeViewHelper(array('content' => $encoded));
$result2 = $this->executeViewHelperUsingTagContent('Text', $encoded);
$this->assertEquals(rawurldecode($encoded), $result1);
$this->assertEquals($result1, $result2);
}

}
11 changes: 11 additions & 0 deletions Tests/Unit/ViewHelpers/Format/Url/EncodeViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@
*/
class EncodeViewHelperTest extends AbstractViewHelperTest {

/**
* @test
*/
public function encodesUrlDecodedStrings() {
$decoded = 'Url Decoded';
$result1 = $this->executeViewHelper(array('content' => $decoded));
$result2 = $this->executeViewHelperUsingTagContent('Text', $decoded);
$this->assertEquals(rawurlencode($decoded), $result1);
$this->assertEquals($result1, $result2);
}

}
25 changes: 25 additions & 0 deletions Tests/Unit/ViewHelpers/Format/Url/SanitizeStringViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,29 @@
*/
class SanitizeStringViewHelperTest extends AbstractViewHelperTest {

/**
* @test
* @dataProvider getInputsAndExpectedOutputs
* @param string $input
* @param string $expectedOutput
*/
public function sanitizesString($input, $expectedOutput) {
$result1 = $this->executeViewHelper(array('string' => $input));
$result2 = $this->executeViewHelperUsingTagContent('Text', $input);
$this->assertEquals($expectedOutput, $result1);
$this->assertEquals($result1, $result2);
}

/**
* @return array
*/
public function getInputsAndExpectedOutputs() {
return array(
array('this string needs dashes', 'this-string-needs-dashes'),
array('THIS SHOULD BE LOWERCASE', 'this-should-be-lowercase'),
array('THESE øæå chars are not allowed', 'these-chars-are-not-allowed'),
array('many spaces become one dash', 'many-spaces-become-one-dash')
);
}

}
2 changes: 1 addition & 1 deletion Tests/Unit/ViewHelpers/Random/StringViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\Random;

/***************************************************************
* Copyright notice
*
Expand All @@ -24,6 +23,7 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use FluidTYPO3\Vhs\ViewHelpers\AbstractViewHelperTest;

/**
Expand Down
12 changes: 10 additions & 2 deletions Tests/Unit/ViewHelpers/System/DateTimeViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\System;

/***************************************************************
* Copyright notice
*
Expand All @@ -24,13 +23,22 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use FluidTYPO3\Vhs\ViewHelpers\AbstractViewHelperTest;

/**
* @protection off
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class DateTimeViewHelperTest extends AbstractViewHelperTest {

/**
* @test
*/
public function returnsDateTimeInstance() {
$result = $this->executeViewHelper();
$this->assertInstanceOf('DateTime', $result);
}

}
13 changes: 11 additions & 2 deletions Tests/Unit/ViewHelpers/System/TimestampViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\System;

/***************************************************************
* Copyright notice
*
Expand All @@ -24,13 +23,23 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use FluidTYPO3\Vhs\ViewHelpers\AbstractViewHelperTest;

/**
* @protection off
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class TimestampViewHelperTest extends AbstractViewHelperTest {

/**
* @test
*/
public function returnsIntegerAtOrAboveNowAsMeasuredInTest() {
$now = time();
$result = $this->executeViewHelper();
$this->assertGreaterThanOrEqual($now, $result);
}

}
12 changes: 11 additions & 1 deletion Tests/Unit/ViewHelpers/System/UniqIdViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@
use FluidTYPO3\Vhs\ViewHelpers\AbstractViewHelperTest;

/**
* @protection off
* @protection on
* @author Cedric Ziel <cedric@cedric-ziel.com>
* @package Vhs
*/
class UniqIdViewHelperTest extends AbstractViewHelperTest {

/**
* @test
*/
public function returnsUniqueIds() {
$arguments = array('prefix' => '', 'moreEntropy' => FALSE);
$result1 = $this->executeViewHelper($arguments);
$result2 = $this->executeViewHelper($arguments);
$this->assertNotEquals($result1, $result2);
}

}
11 changes: 11 additions & 0 deletions Tests/Unit/ViewHelpers/Uri/ImageViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@
*/
class ImageViewHelperTest extends AbstractViewHelperTest {

/**
* @test
*/
public function callsExpectedMethodSequence() {
$mock = $this->getMock($this->getViewHelperClassName(), array('preprocessImage', 'preprocessSourceUri'));
$mock->expects($this->at(0))->method('preprocessImage');
$mock->expects($this->at(1))->method('preprocessSourceUri')->will($this->returnValue('foobar'));
$result = $this->callInaccessibleMethod($mock, 'render');
$this->assertEquals('foobar', $result);
}

}
22 changes: 18 additions & 4 deletions Tests/Unit/ViewHelpers/Uri/TypolinkViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\Uri;

/***************************************************************
* Copyright notice
*
* (c) 2014
* (c) 2014 Claus Due <claus@namelesscoder.net>
*
* All rights reserved
*
Expand All @@ -24,13 +23,28 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use FluidTYPO3\Vhs\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* @protection off
* @author
* @protection on
* @package Vhs
*/
class TypolinkViewHelperTest extends AbstractViewHelperTest {

/**
* @test
*/
public function renderCallsTypoLinkFunctionOnContentObject() {
$class = $this->getViewHelperClassName();
$mock = new $class();
$mock->setArguments(array('configuration' => array('foo' => 'bar')));
$GLOBALS['TSFE'] = new TypoScriptFrontendController(array(), 1, 0);
$GLOBALS['TSFE']->cObj = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array('typoLink_URL'));
$GLOBALS['TSFE']->cObj->expects($this->once())->method('typoLink_URL')->with(array('foo' => 'bar'))->will($this->returnValue('foobar'));
$result = $this->callInaccessibleMethod($mock, 'render');
$this->assertEquals('foobar', $result);
}

}

0 comments on commit 5a87da2

Please sign in to comment.