Initial commit

This commit is contained in:
2018-04-02 08:07:38 +02:00
commit 7330c1ed3e
2054 changed files with 405203 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
* @package Vhs
*/
class Bar extends AbstractEntity {
/**
* @var string
*/
protected $name;
/**
* @var \FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Foo
*/
protected $foo;
/**
* @var ObjectStorage<\FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Bar>
*/
protected $bars = array();
/**
* Constructor
*/
public function __construct() {
$this->bars = new ObjectStorage();
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @param string $name
* @return void
*/
public function setName($name) {
$this->name = $name;
}
/**
* @return Foo
*/
public function getFoo() {
return $this->foo;
}
/**
* @param Foo $foo
* @return void
*/
public function setFoo(Foo $foo) {
$this->foo = $foo;
}
/**
* @return ObjectStorage<Bar>
*/
public function getBars() {
return $this->bars;
}
/**
* @param ObjectStorage<Bar> $bars
*/
public function setbars($bars) {
$this->bars = $bars;
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
* @package Vhs
*/
class Foo extends AbstractEntity {
/**
* @var string
*/
protected $name;
/**
* @var string
* @validate NotEmpty
*/
protected $bar;
/**
* @var Foo
*/
protected $foo;
/**
* @var ObjectStorage<Foo>
*/
protected $children;
public function __construct() {
$this->bar = 'baz';
$this->children = new ObjectStorage();
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @param string $name
* @return void
*/
public function setName($name) {
$this->name = $name;
}
/**
* @return string
*/
public function getBar() {
return $this->bar;
}
/**
* @param Foo $foo
*/
public function setFoo($foo) {
$this->foo = $foo;
}
/**
* @return Foo
*/
public function getFoo() {
return $this->foo;
}
/**
* @return ObjectStorage<Foo>
*/
public function getChildren() {
return $this->children;
}
/**
* @param Foo $child
* @return Foo
*/
public function addChild(Foo $child) {
$this->children->attach($child);
return $this;
}
}

View File

@@ -0,0 +1 @@
foo;bar;baz
1 foo bar baz

View File

@@ -0,0 +1 @@
alert('Hello world');

View File

@@ -0,0 +1,5 @@
Foo
Foo
Foo

View File

@@ -0,0 +1 @@
no extension

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

@@ -0,0 +1,265 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Asset;
use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
/**
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class AssetTest extends UnitTestCase {
/**
* @return void
*/
public function setUp() {
$GLOBALS['VhsAssets'] = array();
}
/**
* @test
*/
public function setsMovableFalseWhenSettingTypeCss() {
$asset = Asset::getInstance();
$asset->setMovable(TRUE);
$asset->setType('css');
$this->assertFalse($asset->getMovable());
}
/**
* @test
*/
public function canCreateAssetInstanceFromStaticFactory() {
$asset = Asset::getInstance();
$this->assertInstanceOf('FluidTYPO3\Vhs\Asset', $asset);
}
/**
* @test
*/
public function canCreateAssetInstanceFromStaticFileFactoryWithRelativeFileAndTranslatesRelativeToAbsolutePath() {
$file = 'Tests/Fixtures/Files/dummy.js';
$expected = $this->getAbsoluteAssetFixturePath();
$asset = Asset::createFromFile($file);
$this->assertInstanceOf('FluidTYPO3\Vhs\Asset', $asset);
$this->assertStringEndsWith($file, $asset->getPath());
$this->assertNotEquals($file, $asset->getPath());
}
/**
* @test
*/
public function canCreateAssetInstanceFromStaticFileFactoryWithAbsoluteFile() {
$file = $this->getAbsoluteAssetFixturePath();
$asset = Asset::createFromFile($file);
$this->assertInstanceOf('FluidTYPO3\Vhs\Asset', $asset);
$this->assertEquals($file, $asset->getPath());
}
/**
* @test
*/
public function canCreateAssetInstanceFromStaticFileFactoryWithUrl() {
$url = 'http://localhost';
$asset = Asset::createFromUrl($url);
$this->assertInstanceOf('FluidTYPO3\Vhs\Asset', $asset);
$this->assertEquals($url, $asset->getPath());
$this->assertSame(TRUE, $asset->getStandalone());
$this->assertSame(TRUE, $asset->getExternal());
}
/**
* @test
*/
public function canCreateAssetInstanceFromStaticSettingsFactory() {
$file = $this->getAbsoluteAssetFixturePath();
$settings = array(
'file' => $file
);
$asset = Asset::createFromSettings($settings);
$this->assertInstanceOf('FluidTYPO3\Vhs\Asset', $asset);
}
/**
* @test
*/
public function createAssetInstanceFromStaticSettingsFactoryRemapsDeprecatedProperties() {
$file = $this->getAbsoluteAssetFixturePath();
$settings = array(
'file' => $file,
'arguments' => array('foo' => 'bar'),
'allowMoveToFooter' => FALSE
);
$asset = Asset::createFromSettings($settings);
$this->assertAttributeEquals($settings['arguments'], 'variables', $asset);
$this->assertAttributeEquals($settings['allowMoveToFooter'], 'movable', $asset);
}
/**
* @test
*/
public function supportsChainingInAllSettersWithFakeNullArgument() {
$asset = Asset::getInstance();
$settableProperties = ObjectAccess::getSettablePropertyNames($asset);
foreach ($settableProperties as $propertyName) {
$setter = 'set' . ucfirst($propertyName);
$asset = $asset->$setter(NULL);
$this->assertInstanceOf('FluidTYPO3\Vhs\Asset', $asset, 'The ' . $setter . ' method does not support chaining');
}
}
/**
* @test
*/
public function assetsCanBeAdded() {
$file = $this->getAbsoluteAssetFixturePath();
$asset = Asset::createFromFile($file);
$name = $asset->getName();
$this->assertSame($asset, $GLOBALS['VhsAssets'][$name]);
}
/**
* @test
*/
public function assetCanBeRemoved() {
$file = $this->getAbsoluteAssetFixturePath();
$asset = Asset::createFromFile($file);
$asset->remove();
$this->assertSame(TRUE, $asset->getRemoved());
$this->assertSame(TRUE, $asset->assertHasBeenRemoved());
$constraint = new \PHPUnit_Framework_Constraint_IsType('array');
$this->assertThat($asset->getSettings(), $constraint);
}
/**
* @test
*/
public function assetsAddedByFilenameUsesFileBasenameAsAssetName() {
$file = $this->getAbsoluteAssetFixturePath();
$expectedName = pathinfo($file, PATHINFO_FILENAME);
$asset = Asset::createFromFile($file);
$this->assertSame($asset, $GLOBALS['VhsAssets'][$expectedName]);
$this->assertEquals(
$expectedName, $asset->getName(),
'Getter for name property does not return the expected name after creation from file path'
);
}
/**
* @test
*/
public function assetBuildMethodReturnsExpectedContentComparedByTrimmedContent() {
$file = $this->getAbsoluteAssetFixturePath();
$asset = Asset::createFromFile($file);
$expectedTrimmedContent = trim(file_get_contents($file));
$this->assertEquals($expectedTrimmedContent, trim($asset->build()));
$asset->setContent(file_get_contents($file));
$asset->setPath(NULL);
$this->assertEquals($expectedTrimmedContent, trim($asset->build()));
}
/**
* @test
*/
public function assetGetContentMethodReturnsExpectedContentComparedByTrimmedContent() {
$file = $this->getAbsoluteAssetFixturePath();
$asset = Asset::createFromFile($file);
$expectedTrimmedContent = trim(file_get_contents($file));
$this->assertEquals($expectedTrimmedContent, trim($asset->getContent()));
}
/**
* @test
*/
public function specialGettersAndAssertionsReturnBooleans() {
$file = $this->getAbsoluteAssetFixturePath();
$asset = Asset::createFromFile($file);
$constraint = new \PHPUnit_Framework_Constraint_IsType('boolean');
$this->assertThat($asset->getRemoved(), $constraint);
$this->assertThat($asset->assertAddNameCommentWithChunk(), $constraint);
$this->assertThat($asset->assertAllowedInFooter(), $constraint);
$this->assertThat($asset->assertDebugEnabled(), $constraint);
$this->assertThat($asset->assertFluidEnabled(), $constraint);
$this->assertThat($asset->assertHasBeenRemoved(), $constraint);
}
/**
* @test
*/
public function specialSupportGettersReturnExpectedTypes() {
$file = $this->getAbsoluteAssetFixturePath();
$asset = Asset::createFromFile($file);
$gettableProperties = ObjectAccess::getGettablePropertyNames($asset);
$objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
foreach ($gettableProperties as $propertyName) {
if (FALSE === property_exists('FluidTYPO3\Vhs\Asset', $propertyName)) {
continue;
}
$propertyValue = ObjectAccess::getProperty($asset, $propertyName);
/** @var \TYPO3\CMS\Extbase\Reflection\PropertyReflection $propertyReflection */
$propertyReflection = $objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\PropertyReflection', 'FluidTYPO3\\Vhs\\Asset', $propertyName);
$expectedDataType = array_pop($propertyReflection->getTagValues('var'));
$constraint = new \PHPUnit_Framework_Constraint_IsType($expectedDataType);
$this->assertThat($propertyValue, $constraint);
}
$constraint = new \PHPUnit_Framework_Constraint_IsType('array');
$this->assertThat($asset->getDebugInformation(), $constraint);
$this->assertThat($asset->getAssetSettings(), $constraint);
$this->assertGreaterThan(0, count($asset->getAssetSettings()));
$this->assertThat($asset->getSettings(), $constraint);
$this->assertGreaterThan(0, count($asset->getSettings()));
$this->assertNotNull($asset->getContent());
}
/**
* @test
*/
public function buildMethodsReturnExpectedValues() {
$file = $this->getAbsoluteAssetFixturePath();
$asset = Asset::createFromFile($file);
$constraint = new \PHPUnit_Framework_Constraint_IsType('string');
$this->assertThat($asset->render(), $constraint);
$this->assertNotEmpty($asset->render());
$this->assertThat($asset->build(), $constraint);
$this->assertNotEmpty($asset->build());
$this->assertSame($asset, $asset->finalize());
}
/**
* @test
*/
public function assertSupportsRawContent() {
$file = $this->getAbsoluteAssetFixturePath();
$content = file_get_contents($file);
$asset = Asset::createFromContent($content);
$this->assertSame($content, $asset->getContent());
}
/**
* @return string
*/
protected function getRelativeAssetFixturePath() {
$file = ExtensionManagementUtility::siteRelPath('vhs') . 'Tests/Fixtures/Files/dummy.js';
return $file;
}
/**
* @return string
*/
protected function getAbsoluteAssetFixturePath() {
$file = ExtensionManagementUtility::extPath('vhs', 'Tests/Fixtures/Files/dummy.js');
return $file;
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\Service;
use FluidTYPO3\Vhs\Asset;
use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class AssetServiceTest
*/
class AssetServiceTest extends UnitTestCase {
/**
* @dataProvider getBuildAllTestValues
* @param array $assets
* @param boolean $cached
* @param integer $expectedFiles
*/
public function testBuildAll(array $assets, $cached, $expectedFiles) {
$GLOBALS['VhsAssets'] = $assets;
$GLOBALS['TSFE'] = (object) array('content' => 'content');
$instance = $this->getMock('FluidTYPO3\\Vhs\\Service\\AssetService', array('writeFile'));
$instance->expects($this->exactly($expectedFiles))->method('writeFile')->with($this->anything(), $this->anything());
if (TRUE === $cached) {
$instance->buildAll(array(), $this, $cached);
} else {
$instance->buildAllUncached(array(), $this);
}
unset($GLOBALS['VhsAssets']);
}
/**
* @return array
*/
public function getBuildAllTestValues() {
/** @var Asset $asset1 */
$asset1 = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('FluidTYPO3\\Vhs\\Asset');
$asset1->setContent('asset');
$asset1->setName('asset1');
$asset1->setType('js');
$asset2 = clone $asset1;
$asset2->setName('asset2');
$asset2->setType('css');
$asset3 = clone $asset1;
$asset3->setName('asset3');
$asset3->setType('css');
$asset3standalone = clone $asset3;
$asset3standalone->setName('asset3standalone');
$asset3standalone->setStandalone(TRUE);
$fluidAsset = clone $asset1;
$fluidAsset->setName('fluid');
$fluidAsset->setFluid(TRUE);
return array(
array(array(), TRUE, 0, array()),
array(array(), FALSE, 0, array()),
array(array('asset1' => $asset1), TRUE, 1),
array(array('asset1' => $asset1, 'asset2' => $asset2), TRUE, 2),
array(array('asset1' => $asset1, 'asset2' => $asset2, 'asset3' => $asset3), TRUE, 2),
array(array('asset1' => $asset1, 'asset2' => $asset2, 'asset3standalone' => $asset3standalone), TRUE, 2),
array(array('fluid' => $fluidAsset), TRUE, 1)
);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace FluidTYPO3\Vhs\Utility;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Core\Tests\UnitTestCase;
/**
* @protection on
* @package Vhs
*/
class ResourceUtilityTest extends UnitTestCase {
/**
* @test
*/
public function canGetFileInformationArrayFromFileObject() {
$propertiesFromFile = array('foo' => 123, 'bar' => 321);
$propertiesFromStorage = array('foo' => 'abc', 'baz' => 123);
$expectation = array_merge($propertiesFromFile, $propertiesFromStorage);
$mockStorage = $this->getMock('TYPO3\CMS\Core\Resource\Storage', array('getFileInfo'));
$mockFile = $this->getMock('TYPO3\CMS\Core\Resource\File', array('getProperties', 'getStorage', 'toArray'), array(), '', FALSE);
$mockFile->expects($this->once())->method('getProperties')->will($this->returnValue($propertiesFromFile));
$mockFile->expects($this->once())->method('getStorage')->will($this->returnValue($mockStorage));
$mockStorage->expects($this->once())->method('getFileInfo')->will($this->returnValue($propertiesFromStorage));
$result = ResourceUtility::getFileArray($mockFile);
$this->assertEquals($expectation, $result);
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\View;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
/**
* Class UncacheTemplateViewTest
*/
class UncacheTemplateViewTest extends UnitTestCase {
/**
* @test
*/
public function callUserFunctionReturnsEarlyIfPartialEmpty() {
$mock = $this->getMock($this->getClassName(), array('prepareContextsForUncachedRendering'));
$configuration = array('partial' => '');
$mock->expects($this->never())->method('prepareContextsForUncachedRendering');
$mock->callUserFunction('', $configuration, '');
}
/**
* @test
*/
public function callUserFunctionReturnsCallsExpectedMethodSequence() {
$mock = $this->getMock($this->getClassName(), array('prepareContextsForUncachedRendering', 'renderPartialUncached'));
$context = new ControllerContext();
$configuration = array('partial' => 'dummy', 'section' => 'dummy', 'controllerContext' => $context);
$mock->expects($this->once())->method('prepareContextsForUncachedRendering');
$mock->expects($this->once())->method('renderPartialUncached');
$mock->callUserFunction('', $configuration, '');
}
/**
* @test
*/
public function prepareContextsForUncachedRenderingCallsExpectedMethodSequence() {
$controllerContext = new ControllerContext();
$renderingContext = $this->getMock('TYPO3\CMS\Fluid\Core\Rendering\RenderingContext', array('setControllerContext'));
$renderingContext->expects($this->once())->method('setControllerContext')->with($controllerContext);
$mock = $this->getMock($this->getClassName(), array('setRenderingContext'));
$mock->expects($this->once())->method('setRenderingContext')->with($renderingContext);
$this->callInaccessibleMethod($mock, 'prepareContextsForUncachedRendering', $renderingContext, $controllerContext);
}
/**
* @test
*/
public function renderPartialUncachedDelegatesToRenderPartial() {
$renderingContext = new RenderingContext();
$mock = $this->getMock($this->getClassName(), array('renderPartial'));
$mock->expects($this->once())->method('renderPartial')->will($this->returnValue('test'));
$result = $this->callInaccessibleMethod($mock, 'renderPartialUncached', $renderingContext, 'dummy');
$this->assertEquals('test', $result);
}
/**
* @return mixed|string
*/
protected function getClassName() {
$class = substr(get_class($this), 0, -4);
$class = str_replace('Tests\\Unit\\', '', $class);
return $class;
}
}

View File

@@ -0,0 +1,232 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Extbase\Mvc\Web\Request;
use TYPO3\CMS\Extbase\Mvc\Web\Response;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
use TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface;
use TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface;
use TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer;
use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
use TYPO3\CMS\Fluid\Core\Widget\WidgetContext;
/**
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers
*/
abstract class AbstractViewHelperTest extends UnitTestCase {
/**
* @var ObjectManagerInterface
*/
protected $objectManager;
/**
* Setup global
*/
public function setUp() {
parent::setUp();
$this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
}
/**
* @test
*/
public function canCreateViewHelperInstance() {
$instance = $this->createInstance();
$this->assertInstanceOf($this->getViewHelperClassName(), $instance);
}
/**
* @test
*/
public function canPrepareArguments() {
$instance = $this->createInstance();
$arguments = $instance->prepareArguments();
$this->assertThat($arguments, new \PHPUnit_Framework_Constraint_IsType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY));
}
/**
* @return string
*/
protected function getViewHelperClassName() {
$class = get_class($this);
$class = substr($class, 0, -4);
$class = str_replace('Tests\\Unit\\', '', $class);
return $class;
}
/**
* @param string $type
* @param mixed $value
* @return NodeInterface
*/
protected function createNode($type, $value) {
if ('Boolean' === $type) {
$value = $this->createNode('Text', strval($value));
}
/** @var NodeInterface $node */
$className = 'TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\' . $type . 'Node';
$node = new $className($value);
return $node;
}
/**
* @return AbstractViewHelper
*/
protected function createInstance() {
$className = $this->getViewHelperClassName();
/** @var AbstractViewHelper $instance */
$instance = $this->objectManager->get($className);
$instance->initialize();
return $instance;
}
/**
* @param array $arguments
* @param array $variables
* @param NodeInterface $childNode
* @param string $extensionName
* @param string $pluginName
* @return AbstractViewHelper
*/
protected function buildViewHelperInstance($arguments = array(), $variables = array(), $childNode = NULL, $extensionName = NULL, $pluginName = NULL) {
$instance = $this->createInstance();
$node = new ViewHelperNode($instance, $arguments);
/** @var RenderingContext $this->renderingContext */
$this->renderingContext = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext');
/** @var TemplateVariableContainer $container */
$container = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer');
if (0 < count($variables)) {
ObjectAccess::setProperty($container, 'variables', $variables, TRUE);
}
ObjectAccess::setProperty($this->renderingContext, 'templateVariableContainer', $container, TRUE);
if (NULL !== $extensionName || NULL !== $pluginName) {
/** @var ViewHelperVariableContainer $viewHelperContainer */
$viewHelperContainer = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\ViewHelperVariableContainer');
/** @var UriBuilder $uriBuilder */
$uriBuilder = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
/** @var Request $request */
$request = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request');
if (NULL !== $extensionName) {
$request->setControllerExtensionName($extensionName);
}
if (NULL !== $pluginName) {
$request->setPluginName($pluginName);
}
/** @var Response $response */
$response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response');
/** @var ControllerContext $controllerContext */
$controllerContext = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext');
$controllerContext->setRequest($request);
$controllerContext->setResponse($response);
$controllerContext->setUriBuilder($uriBuilder);
ObjectAccess::setProperty($this->renderingContext, 'viewHelperVariableContainer', $viewHelperContainer, TRUE);
$this->renderingContext->setControllerContext($controllerContext);
}
if (TRUE === $instance instanceof \Tx_Fluidwidget_Core_Widget_AbstractWidgetViewHelper) {
/** @var WidgetContext $widgetContext */
$widgetContext = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext');
ObjectAccess::setProperty($instance, 'widgetContext', $widgetContext, TRUE);
}
if (NULL !== $childNode) {
$node->addChildNode($childNode);
if ($instance instanceof ChildNodeAccessInterface) {
$instance->setChildNodes(array($childNode));
}
}
$instance->setArguments($arguments);
$instance->setRenderingContext($this->renderingContext);
$instance->setViewHelperNode($node);
return $instance;
}
/**
* @param array $arguments
* @param array $variables
* @param NodeInterface $childNode
* @param string $extensionName
* @param string $pluginName
* @return mixed
*/
protected function executeViewHelper($arguments = array(), $variables = array(), $childNode = NULL, $extensionName = NULL, $pluginName = NULL) {
$instance = $this->buildViewHelperInstance($arguments, $variables, $childNode, $extensionName, $pluginName);
$output = $instance->initializeArgumentsAndRender();
return $output;
}
/**
* @param array $arguments
* @param array $variables
* @param NodeInterface $childNode
* @param string $extensionName
* @param string $pluginName
* @return mixed
*/
protected function executeViewHelperStatic($arguments = array(), $variables = array(), $childNode = NULL, $extensionName = NULL, $pluginName = NULL) {
$instance = $this->buildViewHelperInstance($arguments, $variables, $childNode, $extensionName, $pluginName);
if ($childNode !== NULL) {
$childClosure = function() use ($childNode) {
return $childNode->evaluate($this->renderingContext);
};
} else {
$childClosure = function() {};
}
$viewHelperClassName = $this->getViewHelperClassName();
return $viewHelperClassName::renderStatic($arguments, $childClosure, $this->renderingContext);
}
/**
* @param string $nodeType
* @param mixed $nodeValue
* @param array $arguments
* @param array $variables
* @param string $extensionName
* @param string $pluginName
* @return mixed
*/
protected function executeViewHelperUsingTagContent($nodeType, $nodeValue, $arguments = array(), $variables = array(), $extensionName = NULL, $pluginName = NULL) {
$childNode = $this->createNode($nodeType, $nodeValue);
$instance = $this->buildViewHelperInstance($arguments, $variables, $childNode, $extensionName, $pluginName);
$output = $instance->initializeArgumentsAndRender();
return $output;
}
/**
* @param string $nodeType
* @param mixed $nodeValue
* @param array $arguments
* @param array $variables
* @param string $extensionName
* @param string $pluginName
* @return mixed
*/
protected function executeViewHelperUsingTagContentStatic($nodeType, $nodeValue, $arguments = array(), $variables = array(), $extensionName = NULL, $pluginName = NULL) {
$childNode = $this->createNode($nodeType, $nodeValue);
$instance = $this->buildViewHelperInstance($arguments, $variables, $childNode, $extensionName, $pluginName);
$childClosure = function() use ($childNode) {
return $childNode->evaluate($this->renderingContext);
};
$viewHelperClassName = $this->getViewHelperClassName();
return $viewHelperClassName::renderStatic($arguments, $childClosure, $this->renderingContext);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Asset;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Cedric Ziel <cedric@cedric-ziel.com>
* @package Vhs
* @subpackage ViewHelpers\Asset
*/
class PrefetchViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function buildReturnsMetaTag() {
$instance = $this->buildViewHelperInstance(array('domains' => 'test.com,test2.com', 'force' => TRUE));
$instance->render();
$result = $instance->build();
$this->assertStringStartsWith('<meta', $result);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Asset;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Cedric Ziel <cedric@cedric-ziel.com>
* @package Vhs
* @subpackage ViewHelpers\Asset
*/
class ScriptViewHelperTest extends AbstractViewHelperTest {
}

View File

@@ -0,0 +1,21 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Asset;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Cedric Ziel <cedric@cedric-ziel.com>
* @package Vhs
* @subpackage ViewHelpers\Asset
*/
class StyleViewHelperTest extends AbstractViewHelperTest {
}

View File

@@ -0,0 +1,19 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers
*/
class AssetViewHelperTest extends AbstractViewHelperTest {
}

View File

@@ -0,0 +1,53 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class CallViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function throwsRuntimeExceptionIfObjectNotFound() {
$this->setExpectedException('RuntimeException', NULL, 1356849652);
$this->executeViewHelper(array('method' => 'method', 'arguments' => array()));
}
/**
* @test
*/
public function throwsRuntimeExceptionIfMethodNotFound() {
$object = new \ArrayIterator(array('foo', 'bar'));
$this->setExpectedException('RuntimeException', NULL, 1356834755);
$this->executeViewHelper(array('method' => 'notfound', 'object' => $object, 'arguments' => array()));
}
/**
* @test
*/
public function executesMethodOnObjectFromArgument() {
$object = new \ArrayIterator(array('foo', 'bar'));
$result = $this->executeViewHelper(array('method' => 'count', 'object' => $object, 'arguments' => array()));
$this->assertEquals(2, $result);
}
/**
* @test
*/
public function executesMethodOnObjectFromChildContent() {
$object = new \ArrayIterator(array('foo', 'bar'));
$result = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'v', array('method' => 'count', 'arguments' => array()), array('v' => $object));
$this->assertEquals(2, $result);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class CaseViewHelperTest extends AbstractViewHelperTest {
}

View File

@@ -0,0 +1,41 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Context;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsBackendViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function testIsBackendContext() {
$instance = $this->createInstance();
$result = $this->callInaccessibleMethod($instance, 'evaluateCondition');
$this->assertThat($result, new \PHPUnit_Framework_Constraint_IsType(\PHPUnit_Framework_Constraint_IsType::TYPE_BOOL));
}
/**
* @test
*/
public function testRender() {
$arguments = array('then' => TRUE, 'else' => FALSE);
$result = $this->executeViewHelper($arguments);
$this->assertEquals(TRUE, $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Context;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsCliViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function testIsCliContext() {
$instance = $this->createInstance();
$result = $this->callInaccessibleMethod($instance, 'evaluateCondition');
$this->assertThat($result, new \PHPUnit_Framework_Constraint_IsType(\PHPUnit_Framework_Constraint_IsType::TYPE_BOOL));
}
/**
* @test
*/
public function testRender() {
$arguments = array('then' => TRUE, 'else' => FALSE);
$result = $this->executeViewHelper($arguments);
$this->assertEquals(FALSE, $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Context;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsDevelopmentViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$arguments = array('then' => 'then', 'else' => 'else');
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Context;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsFrontendViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function testIsFrontendContext() {
$instance = $this->createInstance();
$result = $this->callInaccessibleMethod($instance, 'evaluateCondition');
$this->assertThat($result, new \PHPUnit_Framework_Constraint_IsType(\PHPUnit_Framework_Constraint_IsType::TYPE_BOOL));
}
/**
* @test
*/
public function testRender() {
$arguments = array('then' => TRUE, 'else' => FALSE);
$result = $this->executeViewHelper($arguments);
$this->assertEquals(FALSE, $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Context;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsProductionViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$arguments = array('then' => 'then', 'else' => 'else');
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Context;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsTestingViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$arguments = array('then' => 'then', 'else' => 'else');
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,111 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Form;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Bar;
use FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Foo;
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class HasValidatorViewHelperTest extends AbstractViewHelperTest {
public function testRenderThenWithSingleProperty() {
$domainObject = new Foo();
$arguments = array(
'validatorName' => 'NotEmpty',
'property' => 'bar',
'object' => $domainObject,
'then' => 'then'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderElseWithSingleProperty() {
$domainObject = new Foo();
$arguments = array(
'validatorName' => 'NotEmpty',
'property' => 'foo',
'object' => $domainObject,
'else' => 'else'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderThenWithNestedSingleProperty() {
$domainObject = new Bar();
$arguments = array(
'validatorName' => 'NotEmpty',
'property' => 'foo.bar',
'object' => $domainObject,
'then' => 'then'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderElseWithNestedSingleProperty() {
$domainObject = new Bar();
$arguments = array(
'validatorName' => 'NotEmpty',
'property' => 'foo.foo',
'object' => $domainObject,
'else' => 'else'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderThenWithNestedMultiProperty() {
$domainObject = new Bar();
$arguments = array(
'validatorName' => 'NotEmpty',
'property' => 'bars.bar.foo.bar',
'object' => $domainObject,
'then' => 'then'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderElseWithNestedMultiProperty() {
$domainObject = new Bar();
$arguments = array(
'validatorName' => 'NotEmpty',
'property' => 'bars.foo.foo',
'object' => $domainObject,
'else' => 'else'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Form;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Bar;
use FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Foo;
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsRequiredViewHelperTest extends AbstractViewHelperTest {
public function testRenderThenWithSingleProperty() {
$domainObject = new Foo();
$arguments = array(
'property' => 'bar',
'object' => $domainObject,
'then' => 'then'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderElseWithSingleProperty() {
$domainObject = new Foo();
$arguments = array(
'property' => 'foo',
'object' => $domainObject,
'else' => 'else'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderThenWithNestedSingleProperty() {
$domainObject = new Bar();
$arguments = array(
'property' => 'foo.bar',
'object' => $domainObject,
'then' => 'then'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderElseWithNestedSingleProperty() {
$domainObject = new Bar();
$arguments = array(
'property' => 'foo.foo',
'object' => $domainObject,
'else' => 'else'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderThenWithNestedMultiProperty() {
$domainObject = new Bar();
$arguments = array(
'property' => 'bars.bar.foo.bar',
'object' => $domainObject,
'then' => 'then'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderElseWithNestedMultiProperty() {
$domainObject = new Bar();
$arguments = array(
'property' => 'bars.foo.foo',
'object' => $domainObject,
'else' => 'else'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Bar;
use FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Foo;
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class ContainsViewHelperTest extends AbstractViewHelperTest {
/**
* @dataProvider getPositiveTestValues
* @param mixed $haystack
* @param mixed $needle
*/
public function testRendersThen($haystack, $needle) {
$arguments = array(
'haystack' => $haystack,
'needle' => $needle,
'then' => 'then'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @return array
*/
public function getPositiveTestValues() {
$bar = new Bar();
ObjectAccess::setProperty($bar, 'uid', 1, TRUE);
$foo = new Foo();
ObjectAccess::setProperty($foo, 'uid', 2, TRUE);
$objectStorage = new ObjectStorage();
$objectStorage->attach($bar);
/** @var LazyObjectStorage $lazyObjectStorage */
$lazyObjectStorage = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')
->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyObjectStorage', $bar, 'foo', 0);
ObjectAccess::setProperty($lazyObjectStorage, 'isInitialized', TRUE, TRUE);
$lazyObjectStorage->attach($foo);
return array(
array(array('foo'), 'foo'),
array('foo,bar', 'foo'),
array(array($foo), $foo),
array($objectStorage, $bar),
array($lazyObjectStorage, $foo)
);
}
/**
* @dataProvider getNegativeTestValues
* @param mixed $haystack
* @param mixed $needle
*/
public function testRendersElse($haystack, $needle) {
$arguments = array(
'haystack' => $haystack,
'needle' => $needle,
'else' => 'else'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @return array
*/
public function getNegativeTestValues() {
$bar = new Bar();
ObjectAccess::setProperty($bar, 'uid', 1, TRUE);
$foo = new Foo();
ObjectAccess::setProperty($foo, 'uid', 2, TRUE);
$objectStorage = new ObjectStorage();
$objectStorage->attach($bar);
/** @var LazyObjectStorage $lazyObjectStorage */
$lazyObjectStorage = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')
->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyObjectStorage', $bar, 'foo', 0);
ObjectAccess::setProperty($lazyObjectStorage, 'isInitialized', TRUE, TRUE);
$lazyObjectStorage->attach($foo);
return array(
array(array('foo'), 'bar'),
array('foo,baz', 'bar'),
array($objectStorage, $foo),
array($lazyObjectStorage, $bar)
);
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Page;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class HasSubpagesViewHelperTest extends AbstractViewHelperTest {
public function testRenderWithAPageThatHasSubpages() {
$pageSelect = $this->getMock('FluidTYPO3\Vhs\Service\PageSelectService', array('getMenu'), array(), '', FALSE);
$pageSelect->expects($this->any())->method('getMenu')->will($this->returnValue(array('childpage')));
$arguments = array(
'then' => 'then',
'else' => 'else',
'pageUid' => 1
);
$instance = $this->buildViewHelperInstance($arguments);
$instance::setPageSelectService($pageSelect);
$result = $instance->initializeArgumentsAndRender();
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
public function testRenderWithAPageWithoutSubpages() {
$pageSelect = $this->getMock('FluidTYPO3\Vhs\Service\PageSelectService', array('getMenu'), array(), '', FALSE);
$pageSelect->expects($this->any())->method('getMenu')->will($this->returnValue(array()));
$arguments = array(
'then' => 'then',
'else' => 'else',
'pageUid' => 1
);
$instance = $this->buildViewHelperInstance($arguments);
$instance::setPageSelectService($pageSelect);
$result = $instance->initializeArgumentsAndRender();
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Page;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsChildPageViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_SELECTquery'), array(), '', FALSE);
$GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnValue(FALSE));
$arguments = array(
'then' => 'then',
'else' => 'else',
'pageUid' => 0
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Page;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsLanguageViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_SELECTgetSingleRow'), array(), '', FALSE);
$GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue(FALSE));
$arguments = array(
'then' => 'then',
'else' => 'else',
'language' => 0
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\String;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class ContainsViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'haystack' => 'foobar',
'needle' => 'bar'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'haystack' => 'foobar',
'needle' => 'baz'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\String;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsLowercaseViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfFirstCharacterIsLowercase() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'foobar',
'fullString' => FALSE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersThenChildIfAllCharactersAreLowercase() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'foobar',
'fullString' => TRUE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfFirstCharacterIsNotLowercase() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'FooBar',
'fullString' => FALSE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfAllCharactersAreNotLowercase() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'fooBar',
'fullString' => TRUE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\String;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsNumericViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => '123'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 'z123'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\String;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsUppercaseViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfFirstCharacterIsUppercase() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'Foobar',
'fullString' => FALSE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersThenChildIfAllCharactersAreUppercase() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'FOOBAR',
'fullString' => TRUE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfFirstCharacterIsNotUppercase() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'fooBar',
'fullString' => FALSE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfAllCharactersAreNotUppercase() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'FooBar',
'fullString' => TRUE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\String;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class PregViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'foo123bar',
'pattern' => '/([0-9]+)/i'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'foobar',
'pattern' => '/[0-9]+/i'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersThenChildIfConditionMatchedAndGlobalEnabled() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'foo123bar',
'pattern' => '/([0-9]+)/i'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatchedAndGlobalEnabled() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'string' => 'foobar',
'pattern' => '/[0-9]+/i',
'global' => TRUE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersTagContentWhenConditionMatchedAndAsArgumentUsed() {
$arguments = array(
'string' => 'foo123bar',
'pattern' => '/[0-9]+/',
'global' => TRUE, 'as' => 'dummy'
);
$variables = array('dummy' => 'test');
$result = $this->executeViewHelperUsingTagContent('Text', 'test', $arguments, $variables);
$this->assertEquals('test', $result);
$staticResult = $this->executeViewHelperUsingTagContentStatic('Text', 'test', $arguments, $variables);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsArrayViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => array()
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => new \stdClass()
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @package Vhs
*/
class IsBooleanViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => TRUE
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => new \stdClass()
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsDomainObjectViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => new FrontendUser()
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => new \stdClass()
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsFloatViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 0.5
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 1
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsInstanceOfViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$dateTime = new \DateTime('now');
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => $dateTime,
'class' => 'DateTime'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 1,
'class' => 'DateTime'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsIntegerViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 1
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 0.5
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsObjectViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => new \DateTime('now')
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 1
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsQueryResultViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult',
array('toArray', 'initialize', 'rewind', 'valid', 'count'), array(), '', FALSE);
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => $queryResult
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 1
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsStringViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 'test'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 1
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Type;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsTraversableViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfConditionMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => new ObjectStorage()
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfConditionNotMatched() {
$arguments = array(
'then' => 'then',
'else' => 'else',
'value' => 1
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Variable;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IsNullViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfVariableIsNull() {
$arguments = array(
'value' => NULL,
'then' => 'then',
'else' => 'else'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals($arguments['then'], $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfVariableIsNotNull() {
$arguments = array(
'value' => TRUE,
'then' => 'then',
'else' => 'else'
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals($arguments['else'], $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Condition\Variable;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IssetViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfVariableIsSet() {
$arguments = array(
'name' => 'test',
'then' => 'then',
'else' => 'else'
);
$variables = array(
'test' => TRUE
);
$result = $this->executeViewHelper($arguments, $variables);
$this->assertEquals($arguments['then'], $result);
$staticResult = $this->executeViewHelperStatic($arguments, $variables);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfVariableIsNotSet() {
$arguments = array(
'name' => 'test',
'then' => 'then',
'else' => 'else'
);
$variables = array();
$result = $this->executeViewHelper($arguments, $variables);
$this->assertEquals($arguments['else'], $result);
$staticResult = $this->executeViewHelperStatic($arguments, $variables);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Content;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class GetViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$this->assertEmpty($this->executeViewHelper());
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Content;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class InfoViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$this->assertEmpty($this->executeViewHelper());
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Content\Random;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class GetViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$this->assertEmpty($this->executeViewHelper());
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Content\Random;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class RenderViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$this->assertEmpty($this->executeViewHelper());
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Content;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class RenderViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$this->assertEmpty($this->executeViewHelper());
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Content\Resources;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class FalViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$GLOBALS['TYPO3_DB'] = $this->getMock(
'TYPO3\\CMS\\Core\\Database\\DatabaseConnection',
array('fullQuoteStr', 'exec_SELECTquery', 'sql_fetch_assoc'),
array(), '', FALSE
);
$GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')->willReturnArgument(0);
$GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->willReturn(NULL);
$GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')->willReturn(array());
$this->assertEmpty($this->executeViewHelper());
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Content;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class ResourcesViewHelperTest extends AbstractViewHelperTest {
public function testRenderFailsWithoutFieldArgument() {
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'The "field" argument was not found');
$this->executeViewHelper();
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Context;
/***************************************************************
* Copyright notice
*
* (c) 2014 Claus Due <claus@namelesscoder.net>
*
* 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!
* ************************************************************* */
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class GetViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsContext() {
$valid = array('Development', 'Testing', 'Production');
$result = $this->executeViewHelper(array());
$this->assertContains($result, $valid);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) 2014 Claus Due <claus@namelesscoder.net>
*
* 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!
* ************************************************************* */
use TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class DebugViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsDebugOutput() {
$viewHelper = $this->createInstance();
$viewHelperNode = new ViewHelperNode($viewHelper, array());
$result = $this->executeViewHelper(array(), array(), $viewHelperNode);
$this->assertContains('ViewHelper Debug ViewHelper', $result);
$this->assertContains('[ARGUMENTS]', $result);
$this->assertContains('[CURRENT ARGUMENTS]', $result);
$this->assertContains('[RENDER METHOD DOC]', $result);
}
/**
* @test
*/
public function debugsChildNodeObjectAccessors() {
$viewHelper = $this->createInstance();
$viewHelperNode = new ViewHelperNode($viewHelper, array());
$result = $this->executeViewHelperUsingTagContent(
'ObjectAccessor',
'test.test',
array('test' => array('test' => 'test')),
array(),
$viewHelperNode
);
$this->assertContains('[VARIABLE ACCESSORS]', $result);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Extension;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers\Extension
*/
class IconViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersUsingArgument() {
$test = $this->executeViewHelper(array('extensionName' => 'Vhs'));
$this->assertSame(ExtensionManagementUtility::extPath('vhs', 'ext_icon.gif'), $test);
}
/**
* @test
*/
public function rendersUsingControllerContext() {
$test = $this->executeViewHelper(array(), array(), NULL, 'Vhs');
$this->assertSame(ExtensionManagementUtility::extPath('vhs', 'ext_icon.gif'), $test);
}
/**
* @test
*/
public function throwsErrorWhenUnableToDetectExtensionName() {
$this->setExpectedException('RuntimeException', NULL, 1364167519);
$this->executeViewHelper(array(), array(), NULL, NULL, 'FakePlugin');
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Extension;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers\Extension
*/
class LoadedViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildIfExtensionIsLoaded() {
$arguments = array(
'extensionName' => 'Vhs',
'then' => 1, '
else' => 0
);
$result = $this->executeViewHelper($arguments);
$this->assertSame(1, $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildIfExtensionIsNotLoaded() {
$arguments = array(
'extensionName' => 'Void',
'then' => 1,
'else' => 0
);
$result = $this->executeViewHelper($arguments);
$this->assertSame(0, $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Extension\Path;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers\Extension\Path
*/
class AbsoluteViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersUsingArgument() {
$test = $this->executeViewHelper(array('extensionName' => 'Vhs'));
$this->assertSame(ExtensionManagementUtility::extPath('vhs'), $test);
}
/**
* @test
*/
public function rendersUsingControllerContext() {
$test = $this->executeViewHelper(array(), array(), NULL, 'Vhs');
$this->assertSame(ExtensionManagementUtility::extPath('vhs'), $test);
}
/**
* @test
*/
public function throwsErrorWhenUnableToDetectExtensionName() {
$this->setExpectedException('RuntimeException', NULL, 1364167519);
$this->executeViewHelper(array(), array(), NULL, NULL, 'FakePlugin');
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Extension\Path;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers\Extension\Path
*/
class RelativeViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersUsingArgument() {
$test = $this->executeViewHelper(array('extensionName' => 'Vhs'));
$this->assertSame(ExtensionManagementUtility::extRelPath('vhs'), $test);
}
/**
* @test
*/
public function rendersUsingControllerContext() {
$test = $this->executeViewHelper(array(), array(), NULL, 'Vhs');
$this->assertSame(ExtensionManagementUtility::extRelPath('vhs'), $test);
}
/**
* @test
*/
public function throwsErrorWhenUnableToDetectExtensionName() {
$this->setExpectedException('RuntimeException', NULL, 1364167519);
$this->executeViewHelper(array(), array(), NULL, NULL, 'FakePlugin');
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Extension\Path;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers\Extension\Path
*/
class ResourcesViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersUsingArgument() {
$test = $this->executeViewHelper(array('extensionName' => 'Vhs', 'path' => 'ext_icon.gif'));
$this->assertSame(ExtensionManagementUtility::extRelPath('vhs') . 'Resources/Public/ext_icon.gif', $test);
}
/**
* @test
*/
public function rendersUsingControllerContext() {
$test = $this->executeViewHelper(array('path' => 'ext_icon.gif'), array(), NULL, 'Vhs');
$this->assertSame(ExtensionManagementUtility::extRelPath('vhs') . 'Resources/Public/ext_icon.gif', $test);
}
/**
* @test
*/
public function throwsErrorWhenUnableToDetectExtensionName() {
$this->setExpectedException('RuntimeException', NULL, 1364167519);
$this->executeViewHelper(array(), array(), NULL, NULL, 'FakePlugin');
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Extension\Path;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers\Extension\Path
*/
class SiteRelativeViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersUsingArgument() {
$test = $this->executeViewHelper(array('extensionName' => 'Vhs'));
$this->assertSame(ExtensionManagementUtility::siteRelPath('vhs'), $test);
}
/**
* @test
*/
public function rendersUsingControllerContext() {
$test = $this->executeViewHelper(array(), array(), NULL, 'Vhs');
$this->assertSame(ExtensionManagementUtility::siteRelPath('vhs'), $test);
}
/**
* @test
*/
public function throwsErrorWhenUnableToDetectExtensionName() {
$this->setExpectedException('RuntimeException', NULL, 1364167519);
$this->executeViewHelper(array(), array(), NULL, NULL, 'FakePlugin');
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Form;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class FieldNameViewHelperTest extends AbstractViewHelperTest {
/**
* @dataProvider getRenderTestValues
* @param array $arguments
* @param string|NULL $prefix
* @param string|NULL $objectName
* @param array|NULL $names
* @param string $expected
*/
public function testRender(array $arguments, $prefix, $objectName, $names, $expected) {
$instance = $this->buildViewHelperInstance($arguments, array(), NULL, 'Vhs');
$viewHelperVariableContainer = new ViewHelperVariableContainer();
if (NULL !== $objectName) {
$viewHelperVariableContainer->add('TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper', 'formObjectName', $objectName);
}
if (NULL !== $prefix) {
$viewHelperVariableContainer->add('TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper', 'fieldNamePrefix', $prefix);
}
if (NULL !== $names) {
$viewHelperVariableContainer->add('TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper', 'formFieldNames', $names);
}
ObjectAccess::setProperty($instance, 'viewHelperVariableContainer', $viewHelperVariableContainer, TRUE);
$instance->setArguments($arguments);
$result = $instance->render();
$this->assertEquals($expected, $result);
}
/**
* @return array
*/
public function getRenderTestValues() {
return array(
array(array(), NULL, NULL, NULL, ''),
array(array('name' => 'test'), NULL, NULL, NULL, 'test'),
array(array('property' => 'test'), NULL, NULL, NULL, ''),
array(array('name' => 'test'), 'prefix', 'object', NULL, 'prefix[test]'),
array(array('property' => 'test'), 'prefix', 'object', NULL, 'prefix[object][test]'),
array(array('name' => 'test'), '', '', NULL, 'test'),
array(array('property' => 'test'), '', '', NULL, 'test'),
array(array('name' => 'test'), 'prefix', '', NULL, 'prefix[test]'),
array(array('property' => 'test'), 'prefix', '', NULL, 'prefix[test]'),
array(array('name' => 'test'), 'prefix', 'object', array(), 'prefix[test]'),
array(array('property' => 'test'), 'prefix', 'object', array(), 'prefix[object][test]'),
);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Form\Select;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers\Form\Select
*/
class OptgroupViewHelperTest extends AbstractViewHelperTest {
/**
* @dataProvider getRenderTestValues
* @param array $arguments
* @param string|NULL $content
* @param string $expected
*/
public function testRender(array $arguments, $content, $expected) {
$result = $this->executeViewHelperUsingTagContent('Text', $content, $arguments);
$this->assertEquals($expected, $result);
}
/**
* @return array
*/
public function getRenderTestValues() {
return array(
array(array('label' => 'test'), '', '<optgroup label="test" />'),
array(array('label' => 'test'), 'content', '<optgroup label="test">content</optgroup>')
);
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Form\Select;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers\Form\Select
*/
class OptionViewHelperTest extends AbstractViewHelperTest {
/**
* @param mixed $content
* @return mixed
*/
public static function fakeRenderChildrenClosure($content) {
return $content;
}
/**
* @return void
*/
public function testRenderWithoutContextThrowsException() {
$this->setExpectedException('RuntimeException');
$this->executeViewHelper();
}
/**
* @dataProvider getRenderTestValues
* @param array $arguments
* @param mixed $selectedValue
* @param mixed $content
* @param string $expected
*/
public function testRender(array $arguments, $selectedValue, $content, $expected) {
$instance = $this->buildViewHelperInstance($arguments, array(), NULL, 'Vhs');
$viewHelperVariableContainer = new ViewHelperVariableContainer();
$viewHelperVariableContainer->add('FluidTYPO3\Vhs\ViewHelpers\Form\SelectViewHelper', 'options', array());
$viewHelperVariableContainer->add('FluidTYPO3\Vhs\ViewHelpers\Form\SelectViewHelper', 'value', $selectedValue);
ObjectAccess::setProperty($instance, 'viewHelperVariableContainer', $viewHelperVariableContainer, TRUE);
$instance->setArguments($arguments);
$instance->setRenderChildrenClosure(function() use ($content) { return $content; });
$result = $instance->render();
$this->assertEquals($expected, $result);
}
/**
* @return array
*/
public function getRenderTestValues() {
return array(
array(array(), '', '', '<option selected="selected" />'),
array(array(), 'notfound', '', '<option />'),
array(array(), 'notfound', 'content', '<option>content</option>'),
array(array('selected' => TRUE), 'notfound', 'content', '<option selected="selected">content</option>'),
array(
array('value' => 'notfound'),
'notfound',
'content',
'<option selected="selected" value="notfound">content</option>'
),
array(
array('value' => 'a'),
array('a', 'b'),
'content',
'<option selected="selected" value="a">content</option>'
),
);
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Form;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Foo;
use FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Bar;
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
* @subpackage ViewHelpers\Form
*/
class SelectViewHelperTest extends AbstractViewHelperTest {
/**
* @dataProvider getRenderTestValues
* @param array $arguments
* @param string $expected
*/
public function testRender(array $arguments, $expected) {
$result = $this->executeViewHelper($arguments);
$this->assertEquals($expected, $result);
}
/**
* @return array
*/
public function getRenderTestValues() {
$model1 = new Foo();
$model1->setName('Model1');
$model2 = new Bar();
$model2->setName('Model2');
$model1id = spl_object_hash($model1);
$model2id = spl_object_hash($model2);
$model1name = 'FluidTYPO3\\Vhs\\Tests\\Fixtures\\Domain\\Model\\Foo:';
$model2name = 'FluidTYPO3\\Vhs\\Tests\\Fixtures\\Domain\\Model\\Bar:';
return array(
array(array(), '<select name="" />'),
array(array('name' => 'test'), '<select name="test" />'),
array(
array('name' => 'test', 'multiple' => TRUE),
'<input type="hidden" name="test" value="" /><select name="test[]" multiple="multiple" />'
),
array(
array('name' => 'test', 'multiple' => TRUE, 'selectAllbyDefault' => TRUE, 'value' => 'test'),
'<input type="hidden" name="test" value="" /><select name="test[]" multiple="multiple" />'
),
array(
array(
'name' => 'test', 'multiple' => TRUE, 'selectAllbyDefault' => TRUE, 'value' => array($model1id, $model1id),
'optionLabelField' => 'name'
),
'<input type="hidden" name="test" value="" /><select name="test[]" multiple="multiple" />'
),
array(
array('name' => 'foobar', 'options' => array('foo' => 'bar')),
'<select name="foobar"><option value="foo">bar</option>' . PHP_EOL . '</select>'
),
array(
array('name' => 'foobar', 'options' => array('foo' => 'bar'), 'value' => 'foo'),
'<select name="foobar"><option value="foo" selected="selected">bar</option>' . PHP_EOL . '</select>'
),
array(
array('name' => 'foobar', 'options' => array($model1)),
'<select name="foobar"><option value="' . $model1id . '">' . $model1name . '</option>' . PHP_EOL . '</select>'
),
array(
array('name' => 'foobar', 'options' => array($model1), 'value' => $model1),
'<select name="foobar[__identity]"><option value="' . $model1id . '" selected="selected">'
. $model1name .'</option>' . PHP_EOL . '</select>'
),
array(
array('name' => 'foobar', 'options' => array($model1, $model2)),
'<select name="foobar"><option value="' . $model1id . '">' . $model1name . '</option>' . PHP_EOL
. '<option value="' . $model2id . '">' . $model2name . '</option>' . PHP_EOL . '</select>'
),
array(
array('name' => 'foobar', 'options' => array($model1), 'optionLabelField' => 'name'),
'<select name="foobar"><option value="' . $model1id . '">' . $model1->getName() . '</option>' . PHP_EOL . '</select>'
),
array(
array('name' => 'foobar', 'options' => array($model1), 'optionLabelField' => 'bar'),
'<select name="foobar"><option value="' . $model1id . '">baz</option>' . PHP_EOL . '</select>'
),
array(
array('name' => 'foobar', 'options' => array($model1), 'optionValueField' => 'bar'),
'<select name="foobar"><option value="baz">' . $model1name . '</option>' . PHP_EOL . '</select>'
),
);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class AppendViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function canAppendValueToArgument() {
$arguments = array(
'subject' => 'before',
'add' => 'after'
);
$test = $this->executeViewHelper($arguments);
$this->assertStringEndsWith($arguments['add'], $test);
}
/**
* @test
*/
public function canAppendValueToChildContent() {
$arguments = array(
'add' => 'after'
);
$test = $this->executeViewHelperUsingTagContent('Text', 'before', $arguments);
$this->assertStringEndsWith($arguments['add'], $test);
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use FluidTYPO3\Vhs\ViewHelpers\Format\CaseViewHelper;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
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('lowerstring', CaseViewHelper::CASE_UCFIRST, 'Lowerstring'),
array('UPPERSTRING', CaseViewHelper::CASE_LCFIRST, 'uPPERSTRING'),
*/
array('lots of words', CaseViewHelper::CASE_UCWORDS, 'Lots Of Words'),
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')
);
}
}

View File

@@ -0,0 +1,156 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class DateRangeViewHelperTest extends AbstractViewHelperTest {
/**
* @var array
*/
protected $arguments = array(
'start' => 1,
'end' => 86401,
'intervalFormat' => NULL,
'startFormat' => 'Y-m-d',
'endFormat' => 'Y-m-d',
'glue' => '-',
'spaceGlue' => TRUE,
'return' => NULL,
);
/**
* @test
*/
public function rendersWithDefaultArguments() {
$test = $this->executeViewHelper($this->arguments);
$this->assertSame('1970-01-01 - 1970-01-02', $test);
}
/**
* @test
*/
public function usesNowAsStart() {
$arguments = $this->arguments;
unset($arguments['start']);
$now = new \DateTime('now');
$expected = $now->format($arguments['startFormat']);
$test = $this->executeViewHelper($arguments);
$this->assertSame($expected . ' - 1970-01-02', $test);
}
/**
* @test
*/
public function rendersStrftimeFormats() {
$arguments = $this->arguments;
$arguments['startFormat'] = '%h';
$test = $this->executeViewHelper($arguments);
$this->assertSame('Jan - 1970-01-02', $test);
}
/**
* @test
*/
public function canReturnDateTime() {
$arguments = $this->arguments;
$arguments['return'] = 'DateTime';
$test = $this->executeViewHelper($arguments);
$this->assertInstanceOf('DateTime', $test);
}
/**
* @test
*/
public function canReturnIntervalComponentArray() {
$arguments = $this->arguments;
$arguments['return'] = array('d', 's');
$test = $this->executeViewHelper($arguments);
$this->assertSame(array('1', '0'), $test);
}
/**
* @test
*/
public function canReturnFormattedInterval() {
$arguments = $this->arguments;
$arguments['return'] = 'd';
$test = $this->executeViewHelper($arguments);
$this->assertSame('1', $test);
}
/**
* @test
*/
public function canReturnFormattedStrftimeFormat() {
$arguments = $this->arguments;
$arguments['return'] = 'd';
$test = $this->executeViewHelper($arguments);
$this->assertSame('1', $test);
}
/**
* @test
*/
public function supportsIntervalFormat() {
$arguments = $this->arguments;
$arguments['intervalFormat'] = 'P3M';
unset($arguments['end']);
$test = $this->executeViewHelper($arguments);
$this->assertSame('1970-01-01 - 1970-04-01', $test);
}
/**
* @test
*/
public function returnsErrorIfMissingRequiredArgumentsEndAndIntervalFormat() {
$arguments = $this->arguments;
unset($arguments['end'], $arguments['intervalFormat']);
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'Either end or intervalFormat has to be provided.');
$this->executeViewHelper($arguments);
}
/**
* @test
*/
public function returnsErrorOnInvalidDateInterval() {
$arguments = $this->arguments;
$arguments['intervalFormat'] = 'what is this then';
unset($arguments['end']);
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', '"what is this then" could not be parsed by \\DateInterval constructor');
$this->executeViewHelper($arguments);
}
/**
* @test
*/
public function returnsErrorOnInvalidStart() {
$arguments = $this->arguments;
$arguments['start'] = 'what is this then';
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', '"what is this then" could not be parsed by \\DateTime constructor');
$this->executeViewHelper($arguments);
}
/**
* @test
*/
public function returnsErrorOnInvalidEnd() {
$arguments = $this->arguments;
$arguments['end'] = 'what is this then';
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', '"what is this then" could not be parsed by \\DateTime constructor');
$this->executeViewHelper($arguments);
}
}

View File

@@ -0,0 +1,189 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class EliminateViewHelperTest extends AbstractViewHelperTest {
/**
* @var array
*/
protected $arguments = array(
'caseSensitive' => TRUE,
'characters' => NULL,
'strings' => NULL,
'whitespace' => FALSE,
'tabs' => FALSE,
'unixBreaks' => FALSE,
'windowsBreaks' => FALSE,
'digits' => FALSE,
'letters' => FALSE,
'nonAscii' => FALSE
);
/**
* @test
*/
public function removesNonAscii() {
$arguments = $this->arguments;
$arguments['nonAscii'] = TRUE;
$test = $this->executeViewHelperUsingTagContent('Text', 'fooøæåbar', $arguments);
$this->assertSame('foobar', $test);
}
/**
* @test
*/
public function removesLetters() {
$arguments = $this->arguments;
$arguments['letters'] = TRUE;
$test = $this->executeViewHelperUsingTagContent('Text', 'foo123bar', $arguments);
$this->assertSame('123', $test);
}
/**
* @test
*/
public function removesLettersRespectsCaseSensitive() {
$arguments = $this->arguments;
$arguments['letters'] = TRUE;
$arguments['caseSensitive'] = FALSE;
$test = $this->executeViewHelperUsingTagContent('Text', 'FOO123bar', $arguments);
$this->assertSame('123', $test);
}
/**
* @test
*/
public function removesDigits() {
$arguments = $this->arguments;
$arguments['digits'] = TRUE;
$test = $this->executeViewHelperUsingTagContent('Text', 'foo123bar', $arguments);
$this->assertSame('foobar', $test);
}
/**
* @test
*/
public function removesWindowsCarriageReturns() {
$arguments = $this->arguments;
$arguments['windowsBreaks'] = TRUE;
$test = $this->executeViewHelperUsingTagContent('Text', "breaks\rbreaks", $arguments);
$this->assertSame('breaksbreaks', $test);
}
/**
* @test
*/
public function removesUnixBreaks() {
$arguments = $this->arguments;
$arguments['unixBreaks'] = TRUE;
$test = $this->executeViewHelperUsingTagContent('Text', "breaks\nbreaks", $arguments);
$this->assertSame('breaksbreaks', $test);
}
/**
* @test
*/
public function removesTabs() {
$arguments = $this->arguments;
$arguments['tabs'] = TRUE;
$test = $this->executeViewHelperUsingTagContent('Text', 'tabs tabs', $arguments);
$this->assertSame('tabstabs', $test);
}
/**
* @test
*/
public function removesWhitespace() {
$arguments = $this->arguments;
$arguments['whitespace'] = TRUE;
$test = $this->executeViewHelperUsingTagContent('Text', ' trimmed ', $arguments);
$this->assertSame('trimmed', $test);
}
/**
* @test
*/
public function removesWhitespaceBetweenHtmlTags() {
$arguments = $this->arguments;
$arguments['whitespaceBetweenHtmlTags'] = TRUE;
$test = $this->executeViewHelperUsingTagContent('Text', ' <p> Foo </p> <p> Bar </p> ', $arguments);
$this->assertSame('<p> Foo </p><p> Bar </p>', $test);
}
/**
* @test
*/
public function removesCharactersRespectsCaseSensitive() {
$arguments = $this->arguments;
$arguments['characters'] = 'abc';
$arguments['caseSensitive'] = FALSE;
$result = $this->executeViewHelperUsingTagContent('Text', 'ABCdef', $arguments);
$this->assertSame('def', $result);
}
/**
* @test
*/
public function removesCharactersAsString() {
$arguments = $this->arguments;
$arguments['characters'] = 'abc';
$result = $this->executeViewHelperUsingTagContent('Text', 'abcdef', $arguments);
$this->assertSame('def', $result);
}
/**
* @test
*/
public function removesCharactersAsArray() {
$arguments = $this->arguments;
$arguments['characters'] = array('a', 'b', 'c');
$result = $this->executeViewHelperUsingTagContent('Text', 'abcdef', $arguments);
$this->assertSame('def', $result);
}
/**
* @test
*/
public function removesStringsRespectsCaseSensitive() {
$arguments = $this->arguments;
$arguments['strings'] = 'abc,def,ghi';
$arguments['caseSensitive'] = FALSE;
$result = $this->executeViewHelperUsingTagContent('Text', 'aBcDeFgHijkl', $arguments);
$this->assertSame('jkl', $result);
}
/**
* @test
*/
public function removesStringsAsString() {
$arguments = $this->arguments;
$arguments['strings'] = 'abc,def,ghi';
$result = $this->executeViewHelperUsingTagContent('Text', 'abcdefghijkl', $arguments);
$this->assertSame('jkl', $result);
}
/**
* @test
*/
public function removesStringsAsArray() {
$arguments = $this->arguments;
$arguments['strings'] = array('abc', 'def', 'ghi');
$result = $this->executeViewHelperUsingTagContent('Text', 'abcdefghijkl', $arguments);
$this->assertSame('jkl', $result);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class HideViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function hidesTagContent() {
$test = $this->executeViewHelperUsingTagContent('Text', 'this is hidden');
$this->assertNull($test);
}
/**
* @test
*/
public function canBeDisabled() {
$test = $this->executeViewHelperUsingTagContent('Text', 'this is shown', array('disabled' => TRUE));
$this->assertSame('this is shown', $test);
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format\Json;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
* @package Vhs
*/
class DecodeViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsNullForEmptyArguments() {
$viewHelper = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(''));
$this->assertNull($viewHelper->render());
}
/**
* @test
*/
public function returnsExpectedValueForProvidedArguments() {
$fixture = '{"foo":"bar","bar":true,"baz":1,"foobar":null}';
$expected = array(
'foo' => 'bar',
'bar' => TRUE,
'baz' => 1,
'foobar' => NULL,
);
$viewHelper = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($fixture));
$this->assertEquals($expected, $viewHelper->render());
}
/**
* @test
*/
public function throwsExceptionForInvalidArgument() {
$invalidJson = "{'foo': 'bar'}";
$viewHelper = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($invalidJson));
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception');
$this->assertEquals('null', $viewHelper->render());
}
}

View File

@@ -0,0 +1,128 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format\Json;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Fixtures\Domain\Model\Foo;
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
* @package Vhs
*/
class EncodeViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function encodesDateTime() {
$dateTime = \DateTime::createFromFormat('U', 86400);
$instance = $this->createInstance();
$test = $this->callInaccessibleMethod($instance, 'encodeValue', $dateTime, FALSE, TRUE, NULL, NULL);
$this->assertEquals(86400000, $test);
}
/**
* @test
*/
public function encodesRecursiveDomainObject() {
/** @var Foo $object */
$object = $this->objectManager->get('FluidTYPO3\\Vhs\\Tests\\Fixtures\\Domain\\Model\\Foo');
$object->setFoo($object);
$instance = $this->createInstance();
$test = $this->callInaccessibleMethod($instance, 'encodeValue', $object, TRUE, TRUE, NULL, NULL);
$this->assertEquals('{"bar":"baz","children":[],"foo":null,"name":null,"pid":null,"uid":null}', $test);
}
/**
* @test
*/
public function encodesDateTimeWithFormat() {
$dateTime = \DateTime::createFromFormat('U', 86401);
$arguments = array(
'value' => array(
'date' => $dateTime,
),
'dateTimeFormat' => 'Y-m-d',
);
$test = $this->executeViewHelper($arguments);
$this->assertEquals('{"date":"1970-01-02"}', $test);
}
/**
* @test
*/
public function encodesTraversable() {
$traversable = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
$instance = $this->createInstance();
$test = $this->callInaccessibleMethod($instance, 'encodeValue', $traversable, FALSE, TRUE, NULL, NULL);
$this->assertEquals('[]', $test);
}
/**
* @test
*/
public function returnsEmptyJsonObjectForEmptyArguments() {
$viewHelper = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(NULL));
$this->assertEquals('{}', $viewHelper->render());
}
/**
* @test
*/
public function returnsExpectedStringForProvidedArguments() {
$storage = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
$fixture = array(
'foo' => 'bar',
'bar' => TRUE,
'baz' => 1,
'foobar' => NULL,
'date' => \DateTime::createFromFormat('U', 3216548),
'traversable' => $storage
);
$expected = '{"foo":"bar","bar":true,"baz":1,"foobar":null,"date":3216548000,"traversable":[]}';
$viewHelper = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($fixture));
$this->assertEquals($expected, $viewHelper->render());
}
/**
* @test
*/
public function throwsExceptionForInvalidArgument() {
$viewHelper = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue("\xB1\x31"));
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception');
$this->assertEquals('null', $viewHelper->render());
}
/**
* @test
*/
public function returnsJsConsumableTimestamps() {
$date = new \DateTime('now');
$jsTimestamp = $date->getTimestamp() * 1000;
$fixture = array('foo' => $date, 'bar' => array('baz' => $date));
$expected = sprintf('{"foo":%s,"bar":{"baz":%s}}', $jsTimestamp, $jsTimestamp);
$viewHelper = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($fixture));
$this->assertEquals($expected, $viewHelper->render());
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class MarkdownViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function supportsHtmlEntities() {
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'Use of Markdown requires the "markdown" shell utility to be installed');
$this->executeViewHelper(array('text' => 'test < test', 'trim' => TRUE, 'htmlentities' => TRUE));
}
/**
* @test
*/
public function rendersUsingArgument() {
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'Use of Markdown requires the "markdown" shell utility to be installed');
$this->executeViewHelper(array('text' => 'test', 'trim' => TRUE, 'htmlentities' => FALSE));
}
/**
* @test
*/
public function rendersUsingTagContent() {
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'Use of Markdown requires the "markdown" shell utility to be installed');
$this->executeViewHelperUsingTagContent('Text', 'test', array('trim' => TRUE, 'htmlentities' => FALSE));
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format\Placeholder;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class ImageViewHelperTest extends AbstractViewHelperTest {
/**
* @var array
*/
protected $arguments = array(
'width' => 100,
'height' => 100,
'backgroundColor' => '333333',
'textColor' => 'FFFFFF'
);
/**
* @test
*/
public function rendersImage() {
$arguments = $this->arguments;
$test = $this->executeViewHelper($arguments);
$this->assertSame('<img src="http://placehold.it/100/333333/FFFFFF" alt="http://placehold.it/100/333333/FFFFFF" width="100" height="100" />', $test);
}
/**
* @test
*/
public function rendersImageWithText() {
$arguments = $this->arguments;
$arguments['text'] = 'test';
$test = $this->executeViewHelper($arguments);
$this->assertSame('<img src="http://placehold.it/100/333333/FFFFFF/&amp;text=test" alt="http://placehold.it/100/333333/FFFFFF/&amp;text=test" width="100" height="100" />', $test);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format\Placeholder;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class LipsumViewHelperTest extends AbstractViewHelperTest {
/**
* @var array
*/
protected $arguments = array(
'paragraphs' => 5,
'skew' => 0,
'html' => FALSE,
'parseFuncTSPath' => ''
);
/**
* @test
*/
public function supportsParagraphCount() {
$arguments = $this->arguments;
$firstRender = $this->executeViewHelper($arguments);
$arguments['paragraphs'] = 6;
$secondRender = $this->executeViewHelper($arguments);
$this->assertLessThan(strlen($secondRender), strlen($firstRender));
}
/**
* @test
*/
public function supportsHtmlArgument() {
$arguments = $this->arguments;
$arguments['html'] = TRUE;
$test = $this->executeViewHelper($arguments);
$this->assertNotEmpty($test);
}
/**
* @test
*/
public function detectsFileByShortPath() {
$arguments = $this->arguments;
$arguments['lipsum'] = 'EXT:vhs/Tests/Fixtures/Files/foo.txt';
$test = $this->executeViewHelper($arguments);
$this->assertNotEmpty($test);
}
/**
* @test
*/
public function canFallBackWhenUsingFileAndFileDoesNotExist() {
$arguments = $this->arguments;
$arguments['lipsum'] = 'EXT:vhs/None.txt';
$test = $this->executeViewHelper($arguments);
$this->assertNotEmpty($test);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class PlaintextViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function formatsToPlaintext() {
$input = " This string\n is plain-text formatted";
$expected = "This string\nis plain-text formatted";
$result = $this->executeViewHelper(array('content' => $input));
$result2 = $this->executeViewHelperUsingTagContent('Text', $input);
$this->assertEquals($expected, $result);
$this->assertEquals($result, $result2);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class PrependViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function canPrependValueToArgument() {
$arguments = array(
'subject' => 'before',
'add' => 'after'
);
$test = $this->executeViewHelper($arguments);
$this->assertStringStartsWith($arguments['add'], $test);
}
/**
* @test
*/
public function canPrependValueToChildContent() {
$arguments = array(
'add' => 'after'
);
$node = $this->createNode('Text', 'before');
$test = $this->executeViewHelper($arguments, array(), $node);
$this->assertStringStartsWith($arguments['add'], $test);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class RegularExpressionViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function canReplaceValues() {
$arguments = array(
'subject' => 'foo123bar',
'return' => FALSE,
'pattern' => '/[0-9]{3}/',
'replacement' => 'baz',
);
$test = $this->executeViewHelper($arguments);
$this->assertSame('foobazbar', $test);
}
/**
* @test
*/
public function canReturnMatches() {
$arguments = array(
'subject' => 'foo123bar',
'return' => TRUE,
'pattern' => '/[0-9]{3}/',
'replacement' => 'baz',
);
$test = $this->executeViewHelper($arguments);
$this->assertSame(array('123'), $test);
}
/**
* @test
*/
public function canTakeSubjectFromRenderChildren() {
$arguments = array(
'return' => TRUE,
'pattern' => '/[0-9]{3}/',
'replacement' => 'baz',
);
$test = $this->executeViewHelperUsingTagContent('Text', 'foo123bar', $arguments);
$this->assertSame(array('123'), $test);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class RemoveXssViewHelperTest extends AbstractViewHelperTest {
public function testRender() {
$this->assertEmpty($this->executeViewHelper());
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class ReplaceViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function canReplaceUsingArguments() {
$arguments = array(
'content' => 'foobar',
'substring' => 'foo',
'replacement' => ''
);
$test = $this->executeViewHelper($arguments);
$this->assertSame('bar', $test);
}
/**
* @test
*/
public function canReplaceUsingTagContent() {
$arguments = array(
'substring' => 'foo',
'replacement' => ''
);
$test = $this->executeViewHelperUsingTagContent('Text', 'foobar', $arguments);
$this->assertSame('bar', $test);
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class SubstringViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function canRenderUsingArguments() {
$arguments = array(
'content' => 'foobar',
'length' => NULL,
'start' => 3
);
$test = $this->executeViewHelper($arguments);
$this->assertSame('bar', $test);
}
/**
* @test
*/
public function canRenderWithLengthArgument() {
$arguments = array(
'content' => 'foobar',
'length' => 3,
'start' => 2
);
$test = $this->executeViewHelper($arguments);
$this->assertSame('oba', $test);
}
/**
* @test
*/
public function canRenderUsingTagContent() {
$arguments = array(
'length' => NULL,
'start' => 3
);
$test = $this->executeViewHelperUsingTagContent('Text', 'foobar', $arguments);
$this->assertSame('bar', $test);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class TidyViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function throwsErrorWhenNoTidyIsInstalled() {
$instance = $this->createInstance();
ObjectAccess::setProperty($instance, 'hasTidy', FALSE, TRUE);
$this->setExpectedException('RuntimeException', NULL, 1352059753);
$instance->render('test', 'utf8');
}
/**
* @test
*/
public function canTidySourceFromTagContent() {
$instance = $this->createInstance();
if (FALSE === class_exists('tidy')) {
$this->markTestSkipped('No tidy support');
return;
}
$source = '<foo> <bar>
</bar> </foo>';
$test = $this->executeViewHelperUsingTagContent('Text', $source, array('encoding' => 'utf8'));
$this->assertNotSame($source, $test);
}
/**
* @test
*/
public function canTidySourceFromArgument() {
$instance = $this->createInstance();
if (FALSE === class_exists('tidy')) {
$this->markTestSkipped('No tidy support');
return;
}
$source = '<foo> <bar>
</bar> </foo>';
$test = $this->executeViewHelper(array('content' => $source, 'encoding' => 'utf8'));
$this->assertNotSame($source, $test);
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class TrimViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function canTrimSpecificCharacters() {
$arguments = array(
'content' => 'ztrimmedy',
'characters' => 'zy'
);
$test = $this->executeViewHelper($arguments);
$this->assertSame('trimmed', $test);
}
/**
* @test
*/
public function canTrimWithArgument() {
$arguments = array(
'content' => ' trimmed '
);
$test = $this->executeViewHelper($arguments);
$this->assertSame('trimmed', $test);
}
/**
* @test
*/
public function canTrimChildContent() {
$arguments = array();
$node = $this->createNode('Text', ' trimmed ');
$test = $this->executeViewHelper($arguments, array(), $node);
$this->assertSame('trimmed', $test);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format\Url;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
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);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format\Url;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
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);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format\Url;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
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-oeaeaa-chars-are-not-allowed'),
array('many spaces become one dash', 'many-spaces-become-one-dash')
);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Format;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Björn Fromme <fromme@dreipunktnull.com>
* @package Vhs
*/
class WordWrapViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function willWrapStringAccordingToArguments() {
$content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Debitis, et id ipsum modi molestiae molestias numquam! Aperiam assumenda commodi ducimus harum iure nostrum odit, vel voluptatem! Beatae commodi qui rem!';
$arguments = array(
'limit' => 25,
'break' => PHP_EOL,
'glue' => '|',
);
$test = $this->executeViewHelperUsingTagContent('Text', $content, $arguments);
$this->assertRegExp('/.{0,25}\|/', $test);
}
}

View File

@@ -0,0 +1,213 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
/**
* @protection off
* @author Danilo Bürger <danilo.buerger@hmspl.de>, Heimspiel GmbH
* @package Vhs
*/
class IfViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function rendersThenChildWithFlatComparison() {
$stack = array(array('foo'), '==', array('foo'));
$arguments = array(
'then' => 'then',
'else' => 'else',
'stack' => $stack
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersThenChildWithPrecedence() {
$stack = array(1, 'OR', 0, 'AND', 0);
$arguments = array(
'then' => 'then',
'else' => 'else',
'stack' => $stack
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildWithFlatArrayComparison() {
$stack = array(array('foo'), '==', '3');
$arguments = array(
'then' => 'then',
'else' => 'else',
'stack' => $stack
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersThenChildWithFlatLogicalOperator() {
$stack = array(1, '==', 1, 'AND', 1);
$arguments = array(
'then' => 'then',
'else' => 'else',
'stack' => $stack
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersThenChildWithRightStack() {
$stack = array(1, '==', 1, 'AND', array(1, '!=', 0));
$arguments = array(
'then' => 'then',
'else' => 'else',
'stack' => $stack
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersThenChildWithStacks() {
$stack = array(array('foo', '!=', 'bar'), 'AND', 1, 'OR', array(1, '==', '0'));
$arguments = array(
'then' => 'then',
'else' => 'else',
'stack' => $stack
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('then', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildWithStacks() {
$stack = array(array('foo', '!=', 'bar'), 'AND', array('foo', '==', 'bar'));
$arguments = array(
'then' => 'then',
'else' => 'else',
'stack' => $stack
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildWithEmptyStack() {
$stack = array();
$arguments = array(
'then' => 'then',
'else' => 'else',
'stack' => $stack
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('else', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function rendersElseChildWithNoLogicalOperator() {
$this->setExpectedException('RuntimeException', NULL, 1385071197);
$stack = array(array('foo', '!=', 'bar'), array('foo', '==', 'bar'));
$this->executeViewHelper(array('then' => 'then', 'else' => 'else', 'stack' => $stack));
}
/**
* @test
*/
public function rendersElseChildWithWrongLogicalOperatorOrder() {
$this->setExpectedException('RuntimeException', NULL, 1385072228);
$stack = array(array('foo', '!=', 'bar'), 'AND', 'AND', array('foo', '==', 'bar'));
$this->executeViewHelper(array('then' => 'then', 'else' => 'else', 'stack' => $stack));
}
/**
* @test
*/
public function evaluateLogicalOperatorAnd() {
$instance = $this->createInstance();
$this->assertEquals(FALSE, $this->callInaccessibleMethod($instance, 'evaluateLogicalOperator', array(TRUE), 'AND', array(FALSE)));
}
/**
* @test
*/
public function evaluateLogicalOperatorOr() {
$instance = $this->createInstance();
$this->assertEquals(TRUE, $this->callInaccessibleMethod($instance, 'evaluateLogicalOperator', array(TRUE), 'OR', array(FALSE)));
}
/**
* @test
*/
public function evaluateLogicalOperatorInternalError() {
$this->setExpectedException('RuntimeException', NULL, 1385072357);
$instance = $this->createInstance();
$this->callInaccessibleMethod($instance, 'evaluateLogicalOperator', array(TRUE), 'foo', array(FALSE));
}
/**
* @test
*/
public function prepareSideForEvaluation() {
$instance = $this->createInstance();
$this->assertEquals(array(TRUE), $this->callInaccessibleMethod($instance, 'prepareSideForEvaluation', array(TRUE)));
}
/**
* @test
*/
public function prepareSideForEvaluationArray() {
$instance = $this->createInstance();
$this->assertEquals(array(TRUE), $this->callInaccessibleMethod($instance, 'prepareSideForEvaluation', array(array(TRUE))));
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Björn Fromme <fromme@dreipunktnull.com>
* @package Vhs
*/
class ChunkViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsConfiguredItemNumberIfFixed() {
$arguments = array(
'count' => 5,
'fixed' => TRUE,
'subject' => array('a', 'b', 'c', 'd', 'e'),
);
$result = $this->executeViewHelper($arguments);
$this->assertCount(5, $result);
}
/**
* @test
*/
public function returnsConfiguredItemNumberIfFixedAndSubjectIsEmpty() {
$arguments = array(
'count' => 5,
'fixed' => TRUE,
'subject' => array(),
);
$result = $this->executeViewHelper($arguments);
$this->assertCount(5, $result);
}
/**
* @test
*/
public function returnsExpectedItemNumberIfNotFixed() {
$arguments = array(
'count' => 4,
'subject' => array('a', 'b', 'c', 'd', 'e'),
);
$result = $this->executeViewHelper($arguments);
$this->assertCount(2, $result);
}
/**
* @test
*/
public function returnsEmptyResultForEmptySubjectAndNotFixed() {
$arguments = array(
'count' => 5,
'subject' => array(),
);
$result = $this->executeViewHelper($arguments);
$this->assertCount(0, $result);
}
/**
* @test
*/
public function returnsEmptyResultForZeroCount() {
$arguments = array(
'count' => 0,
'subject' => array('a', 'b', 'c', 'd', 'e'),
);
$result = $this->executeViewHelper($arguments);
$this->assertCount(0, $result);
}
/**
* @test
*/
public function preservesArrayKeysIfRequested() {
$arguments = array(
'count' => 2,
'subject' => array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5),
'preserveKeys' => TRUE,
);
$result = $this->executeViewHelper($arguments);
$expected = array(array('a' => 1, 'b' => 2), array('c' => 3, 'd' => 4), array('e' => 5));
$this->assertEquals($expected, $result);
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class ExplodeViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function explodesString() {
$arguments = array('content' => '1,2,3', 'glue' => ',');
$result = $this->executeViewHelper($arguments);
$this->assertEquals(array('1', '2', '3'), $result);
}
/**
* @test
*/
public function supportsCustomGlue() {
$arguments = array('content' => '1;2;3', 'glue' => ';');
$result = $this->executeViewHelper($arguments);
$this->assertEquals(array('1', '2', '3'), $result);
}
/**
* @test
*/
public function supportsConstantsGlue() {
$arguments = array('content' => "1\n2\n3", 'glue' => 'constant:LF');
$result = $this->executeViewHelper($arguments);
$this->assertEquals(array('1', '2', '3'), $result);
}
/**
* @test
*/
public function passesThroughUnknownSpecialGlue() {
$arguments = array('content' => '1-2-3', 'glue' => 'unknown:-');
$result = $this->executeViewHelper($arguments);
$this->assertEquals(array('1', '2', '3'), $result);
}
/**
* @test
*/
public function renderMethodCallsRenderChildrenIfContentIsNull() {
$array = array('1', '2', '3');
$arguments = array('glue' => ',');
$mock = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$mock->setArguments($arguments);
$mock->expects($this->once())->method('renderChildren')->will($this->returnValue('1,2,3'));
$result = $mock->render();
$this->assertEquals($array, $result);
}
/**
* @test
*/
public function renderMethodCallsRenderChildrenAndTemplateVariableContainerAddAndRemoveIfAsArgumentGiven() {
$array = array('1', '2', '3');
$arguments = array('as' => 'test', 'content' => '1,2,3', 'glue' => ',');
$mock = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$mock->expects($this->once())->method('renderChildren')->will($this->returnValue('test'));
$mock->setArguments($arguments);
$mockContainer = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer', array('add', 'get', 'remove', 'exists'));
$mockContainer->expects($this->once())->method('exists')->with('test')->will($this->returnValue(TRUE));
$mockContainer->expects($this->exactly(2))->method('add')->with('test', $array);
$mockContainer->expects($this->once())->method('get')->with('test')->will($this->returnValue($array));
$mockContainer->expects($this->exactly(2))->method('remove')->with('test');
ObjectAccess::setProperty($mock, 'templateVariableContainer', $mockContainer, TRUE);
$mock->render();
}
}

View File

@@ -0,0 +1,203 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* @author Andreas Lappe <nd@kaeufli.ch>
* @package Vhs
*/
class ExtractViewHelperTest extends AbstractViewHelperTest {
/**
* @var ExtractViewHelper
*/
protected $fixture;
/**
* @return void
*/
public function setUp() {
parent::setUp();
$this->fixture = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Iterator\ExtractViewHelper', array('hasArgument'));
}
/**
* @return void
*/
public function tearDown() {
unset($this->fixture);
}
/**
* @return array
*/
public function simpleStructures() {
$structures = array(
// structure, key, expected
'flat associative array' => array(
array('myKey' => 'myValue'),
'myKey',
'myValue'
),
'deeper associative array' => array(
array(
'myFirstKey' => array(
'mySecondKey' => array(
'myThirdKey' => 'myValue'
)
)
),
'myFirstKey.mySecondKey.myThirdKey',
'myValue'
),
);
return $structures;
}
/**
* @return ObjectStorage
*/
public function constructObjectStorageContainingFrontendUser() {
$storage = new ObjectStorage();
$user1 = new FrontendUser();
$user2 = new FrontendUser();
$user3 = new FrontendUser();
$user1->setFirstName('Peter');
$user2->setFirstName('Paul');
$user3->setFirstName('Marry');
$storage->attach($user1);
$storage->attach($user2);
$storage->attach($user3);
return $storage;
}
/**
* @return ObjectStorage
*/
public function constructObjectStorageContainingFrontendUsersWithUserGroups() {
$storage = new ObjectStorage();
$userGroup1 = new FrontendUserGroup('my first group');
$userGroup2 = new FrontendUserGroup('my second group');
$user1 = new FrontendUser();
$user2 = new FrontendUser();
$user1->addUsergroup($userGroup1);
$user2->addUsergroup($userGroup2);
$storage->attach($user1);
$storage->attach($user2);
return $storage;
}
/**
* @return array
*/
public function nestedStructures() {
$structures = array(
// structure, key, expected
'simple indexed_search searchWords array' => array(
array(
0 => array(
'sword' => 'firstWord',
'oper' => 'AND'
),
),
'sword',
array(
'firstWord'
)
),
'interesting indexed_search searchWords array' => array(
array(
0 => array(
'sword' => 'firstWord',
'oper' => 'AND'
),
1 => array(
'sword' => 'secondWord',
'oper' => 'AND'
),
3 => array(
'sword' => 'thirdWord',
'oper' => 'AND'
)
),
'sword',
array(
'firstWord',
'secondWord',
'thirdWord'
)
),
'ridiculously nested array' => array(
array(
array(
array(
array(
array(
array(
'l' => 'some'
)
)
),
array(
'l' => 'text'
)
)
)
),
'l',
array(
0 => 'some',
1 => 'text',
)
),
'ObjectStorage containing FrontendUser' => array(
$this->constructObjectStorageContainingFrontendUser(),
'firstname',
array(
'Peter',
'Paul',
'Marry'
)
),
);
return $structures;
}
/**
* @test
* @dataProvider nestedStructures
*/
public function recursivelyExtractKey($structure, $key, $expected) {
$recursive = TRUE;
$this->assertSame(
$expected,
$this->fixture->render($key, $structure, $recursive)
);
}
/**
* @test
* @dataProvider simpleStructures
*/
public function extractByKeyExtractsKeyByPath($structure, $key, $expected) {
$this->assertSame(
$expected,
$this->fixture->extractByKey($structure, $key)
);
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class FilterViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function nullSubjectCallsRenderChildrenToReadValue() {
$subject = array('test' => 'test');
$arguments = array(
'preserveKeys' => TRUE
);
$result = $this->executeViewHelperUsingTagContent('Array', $subject, $arguments);
$this->assertSame($subject, $result);
}
/**
* @test
*/
public function filteringEmptySubjectReturnsEmptyArrayOnInvalidSubject() {
$arguments = array(
'subject' => new \DateTime('now')
);
$result = $this->executeViewHelper($arguments);
$this->assertSame($result, array());
}
/**
* @test
*/
public function supportsIterators() {
$array = array('test' => 'test');
$iterator = new \ArrayIterator($array);
$arguments = array(
'subject' => $iterator,
'filter' => 'test',
'preserveKeys' => TRUE
);
$result = $this->executeViewHelper($arguments);
$this->assertSame($result, $array);
}
/**
* @test
*/
public function supportsPropertyName() {
$array = array(array('test' => 'test'));
$iterator = new \ArrayIterator($array);
$arguments = array(
'subject' => $iterator,
'filter' => 'test',
'propertyName' => 'test',
'preserveKeys' => TRUE
);
$result = $this->executeViewHelper($arguments);
$this->assertSame($result, $array);
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class FirstViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsFirstElement() {
$array = array('a', 'b', 'c');
$arguments = array(
'haystack' => $array
);
$output = $this->executeViewHelper($arguments);
$this->assertEquals('a', $output);
}
/**
* @test
*/
public function supportsIterators() {
$array = new \ArrayIterator(array('a', 'b', 'c'));
$arguments = array(
'haystack' => $array
);
$output = $this->executeViewHelper($arguments);
$this->assertEquals('a', $output);
}
/**
* @test
*/
public function supportsTagContent() {
$array = array('a', 'b', 'c');
$arguments = array(
'haystack' => NULL
);
$output = $this->executeViewHelperUsingTagContent('Array', $array, $arguments);
$this->assertEquals('a', $output);
}
/**
* @test
*/
public function returnsNullIfHaystackIsNull() {
$arguments = array(
'haystack' => NULL
);
$output = $this->executeViewHelper($arguments);
$this->assertEquals(NULL, $output);
}
/**
* @test
*/
public function returnsNullIfHaystackIsEmptyArray() {
$arguments = array(
'haystack' => array()
);
$output = $this->executeViewHelper($arguments);
$this->assertEquals(NULL, $output);
}
/**
* @test
*/
public function throwsExceptionOnUnsupportedHaystacks() {
$arguments = array(
'haystack' => new \DateTime('now')
);
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'Invalid argument supplied to Iterator/FirstViewHelper - expected array, Iterator or NULL but got');
$this->executeViewHelper($arguments);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class ForViewHelperTest extends AbstractViewHelperTest {
}

View File

@@ -0,0 +1,88 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class ImplodeViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function implodesString() {
$arguments = array('content' => array('1', '2', '3'), 'glue' => ',');
$result = $this->executeViewHelper($arguments);
$this->assertEquals('1,2,3', $result);
}
/**
* @test
*/
public function supportsCustomGlue() {
$arguments = array('content' => array('1', '2', '3'), 'glue' => ';');
$result = $this->executeViewHelper($arguments);
$this->assertEquals('1;2;3', $result);
}
/**
* @test
*/
public function supportsConstantsGlue() {
$arguments = array('content' => array('1', '2', '3'), 'glue' => 'constant:LF');
$result = $this->executeViewHelper($arguments);
$this->assertEquals("1\n2\n3", $result);
}
/**
* @test
*/
public function passesThroughUnknownSpecialGlue() {
$arguments = array('content' => array('1', '2', '3'), 'glue' => 'unknown:-');
$result = $this->executeViewHelper($arguments);
$this->assertEquals('1-2-3', $result);
}
/**
* @test
*/
public function renderMethodCallsRenderChildrenIfContentIsNull() {
$array = array('1', '2', '3');
$arguments = array('glue' => ',');
$mock = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$mock->setArguments($arguments);
$mock->expects($this->once())->method('renderChildren')->will($this->returnValue($array));
$result = $mock->render();
$this->assertEquals('1,2,3', $result);
}
/**
* @test
*/
public function renderMethodCallsRenderChildrenAndTemplateVariableContainerAddAndRemoveIfAsArgumentGiven() {
$array = array('1', '2', '3');
$arguments = array('as' => 'test', 'content' => $array, 'glue' => ',');
$mock = $this->getMock($this->getViewHelperClassName(), array('renderChildren'));
$mock->expects($this->once())->method('renderChildren')->will($this->returnValue('test'));
$mock->setArguments($arguments);
$mockContainer = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer', array('add', 'get', 'remove', 'exists'));
$mockContainer->expects($this->once())->method('exists')->with('test')->will($this->returnValue(TRUE));
$mockContainer->expects($this->exactly(2))->method('add')->with('test', '1,2,3');
$mockContainer->expects($this->once())->method('get')->with('test')->will($this->returnValue($array));
$mockContainer->expects($this->exactly(2))->method('remove')->with('test');
ObjectAccess::setProperty($mock, 'templateVariableContainer', $mockContainer, TRUE);
$mock->render();
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class IndexOfViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsIndexOfElement() {
$array = array('a', 'b', 'c');
$arguments = array(
'haystack' => $array,
'needle' => 'c',
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals(2, $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
/**
* @test
*/
public function returnsNegativeOneIfNeedleDoesNotExist() {
$array = array('a', 'b', 'c');
$arguments = array(
'haystack' => $array,
'needle' => 'd',
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals(-1, $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Danilo Bürger <danilo.buerger@hmspl.de>, Heimspiel GmbH
* @package Vhs
*/
class IntersectViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function intersectTest() {
$array1 = array('a' => 'green', 'red', 'blue');
$array2 = array('b' => 'green', 'yellow', 'red');
$arguments = array('a' => $array1, 'b' => $array2);
$result = $this->executeViewHelper($arguments);
$this->assertEquals(array('a' => 'green', 0 => 'red'), $result);
}
/**
* @test
*/
public function intersectTestWithTagContent() {
$array1 = array('a' => 'green', 'red', 'blue');
$array2 = array('b' => 'green', 'yellow', 'red');
$arguments = array('b' => $array2);
$result = $this->executeViewHelperUsingTagContent('Array', $array1, $arguments);
$this->assertEquals(array('a' => 'green', 0 => 'red'), $result);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Stefan Neufeind <info (at) speedpartner.de>
* @package Vhs
*/
class KeysViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsKeys() {
$array = array('a' => 'A', 'b' => 'B', 'c' => 'C');
$expected = array('a', 'b', 'c');
$arguments = array(
'subject' => $array,
);
$output = $this->executeViewHelper($arguments);
$output2 = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'v', array(), array('v' => $array));
$this->assertEquals($expected, $output);
$this->assertEquals($output, $output2);
}
/**
* @test
*/
public function supportsAsArgument() {
$array = array('a' => 'A', 'b' => 'B', 'c' => 'C');
$arguments = array('as' => 'v', 'subject' => $array);
$result = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'v.1', $arguments);
$this->assertEquals('b', $result);
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Iterator;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection on
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class LastViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsLastElement() {
$array = array('a', 'b', 'c');
$arguments = array(
'haystack' => $array
);
$output = $this->executeViewHelper($arguments);
$this->assertEquals('c', $output);
}
/**
* @test
*/
public function supportsIterators() {
$array = new \ArrayIterator(array('a', 'b', 'c'));
$arguments = array(
'haystack' => $array
);
$output = $this->executeViewHelper($arguments);
$this->assertEquals('c', $output);
}
/**
* @test
*/
public function supportsTagContent() {
$array = array('a', 'b', 'c');
$arguments = array(
'haystack' => NULL
);
$output = $this->executeViewHelperUsingTagContent('Array', $array, $arguments);
$this->assertEquals('c', $output);
}
/**
* @test
*/
public function returnsNullIfHaystackIsEmptyArray() {
$arguments = array(
'haystack' => array()
);
$output = $this->executeViewHelper($arguments);
$this->assertEquals(NULL, $output);
}
}

Some files were not shown because too many files have changed in this diff Show More