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,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);
}
}

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 LoopViewHelperTest extends AbstractViewHelperTest {
}

View File

@@ -0,0 +1,31 @@
<?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 MergeViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function testMergesArraysWithOverrule() {
$array1 = array('foo');
$array2 = array('bar');
$expected = array('bar');
$result = $this->executeViewHelper(array('a' => $array1, 'b' => $array2, 'useKeys' => FALSE));
$this->assertEquals($expected, $result);
}
}

View File

@@ -0,0 +1,37 @@
<?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 NextViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsNextElement() {
$array = array('a', 'b', 'c');
next($array);
$arguments = array(
'haystack' => $array,
'needle' => 'b',
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('c', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,72 @@
<?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 PopViewHelperTest extends AbstractViewHelperTest {
/**
* @test
* @dataProvider getRenderTestValues
* @param array $arguments
* @param mixed $expectedValue
*/
public function testRender(array $arguments, $expectedValue) {
if (TRUE === isset($arguments['as'])) {
$value = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'variable', $arguments);
} else {
$value = $this->executeViewHelper($arguments);
$value2 = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'v', array(), array('v' => $arguments['subject']));
$this->assertEquals($value, $value2);
}
$this->assertEquals($value, $expectedValue);
}
/**
* @return array
*/
public function getRenderTestValues() {
return array(
array(array('subject' => array()), NULL),
array(array('subject' => array('foo', 'bar')), 'bar'),
array(array('subject' => array('foo', 'bar'), 'as' => 'variable'), 'bar'),
array(array('subject' => new \ArrayIterator(array('foo', 'bar'))), 'bar'),
array(array('subject' => new \ArrayIterator(array('foo', 'bar')), 'as' => 'variable'), 'bar'),
);
}
/**
* @test
* @dataProvider getErrorTestValues
* @param mixed $subject
*/
public function testThrowsErrorsOnInvalidSubjectType($subject) {
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'Unsupported input type; cannot convert to array!');
$this->executeViewHelper(array('subject' => $subject));
}
/**
* @return array
*/
public function getErrorTestValues() {
return array(
array(0),
array(NULL),
array(new \DateTime()),
array(new \stdClass()),
);
}
}

View File

@@ -0,0 +1,37 @@
<?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 PreviousViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsPreviousElement() {
$array = array('a', 'b', 'c');
next($array);
$arguments = array(
'haystack' => $array,
'needle' => 'c',
);
$result = $this->executeViewHelper($arguments);
$this->assertEquals('b', $result);
$staticResult = $this->executeViewHelperStatic($arguments);
$this->assertEquals($result, $staticResult, 'The regular viewHelper output doesn\'t match the static output!');
}
}

View File

@@ -0,0 +1,62 @@
<?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 RandomViewHelperTest extends AbstractViewHelperTest {
/**
* @test
* @dataProvider getRenderTestValues
* @param array $arguments
* @param array $asArray
*/
public function testRender(array $arguments, array $asArray) {
if (TRUE === isset($arguments['as'])) {
$value = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'variable', $arguments);
} else {
$value = $this->executeViewHelper($arguments);
$value2 = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'v', array(), array('v' => $arguments['subject']));
if (NULL !== $value2) {
$this->assertContains($value2, $asArray);
}
}
if (NULL !== $value) {
$this->assertContains($value, $asArray);
} else {
$this->assertNull($value);
}
}
/**
* @return array
*/
public function getRenderTestValues() {
$queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult',
array('toArray', 'initialize', 'rewind', 'valid', 'count'), array(), '', FALSE);
$queryResult->expects($this->any())->method('toArray')->will($this->returnValue(array('foo', 'bar')));
$queryResult->expects($this->any())->method('count')->will($this->returnValue(0));
$queryResult->expects($this->any())->method('valid')->will($this->returnValue(FALSE));
return array(
array(array('subject' => array('foo', 'bar')), array('foo', 'bar')),
array(array('subject' => array('foo', 'bar'), 'as' => 'variable'), array('foo', 'bar')),
array(array('subject' => new \ArrayIterator(array('foo', 'bar'))), array('foo', 'bar')),
array(array('subject' => new \ArrayIterator(array('foo', 'bar')), 'as' => 'variable'), array('foo', 'bar')),
array(array('subject' => $queryResult), array('foo', 'bar')),
array(array('subject' => $queryResult, 'as' => 'variable'), array('foo', 'bar'))
);
}
}

View File

@@ -0,0 +1,77 @@
<?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 ReverseViewHelperTest extends AbstractViewHelperTest {
/**
* @test
* @dataProvider getRenderTestValues
* @param array $arguments
* @param mixed $expectedValue
*/
public function testRender(array $arguments, $expectedValue) {
if (TRUE === isset($arguments['as'])) {
$value = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'variable', $arguments);
} else {
$value = $this->executeViewHelper($arguments);
$value2 = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'v', array(), array('v' => $arguments['subject']));
$this->assertEquals($value, $value2);
}
$this->assertEquals($value, $expectedValue);
}
/**
* @return array
*/
public function getRenderTestValues() {
$queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult',
array('toArray', 'initialize', 'rewind', 'valid', 'count'), array(), '', FALSE);
$queryResult->expects($this->any())->method('toArray')->will($this->returnValue(array('foo', 'bar')));
$queryResult->expects($this->any())->method('valid')->will($this->returnValue(FALSE));
$queryResult->expects($this->any())->method('count')->will($this->returnValue(1));
return array(
array(array('subject' => array()), array()),
array(array('subject' => array('foo', 'bar')), array(1 => 'bar', 0 => 'foo')),
array(array('subject' => array('foo', 'bar'), 'as' => 'variable'), array(1 => 'bar', 0 => 'foo')),
array(array('subject' => new \ArrayIterator(array('foo', 'bar'))), array(1 => 'bar', 0 => 'foo')),
array(array('subject' => new \ArrayIterator(array('foo', 'bar')), 'as' => 'variable'), array(1 => 'bar', 0 => 'foo'))
);
}
/**
* @test
* @dataProvider getErrorTestValues
* @param mixed $subject
*/
public function testThrowsErrorsOnInvalidSubjectType($subject) {
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'Unsupported input type; cannot convert to array!');
$this->executeViewHelper(array('subject' => $subject));
}
/**
* @return array
*/
public function getErrorTestValues() {
return array(
array(0),
array(NULL),
array(new \DateTime()),
array(new \stdClass()),
);
}
}

View File

@@ -0,0 +1,72 @@
<?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 ShiftViewHelperTest extends AbstractViewHelperTest {
/**
* @test
* @dataProvider getRenderTestValues
* @param array $arguments
* @param mixed $expectedValue
*/
public function testRender(array $arguments, $expectedValue) {
if (TRUE === isset($arguments['as'])) {
$value = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'variable', $arguments);
} else {
$value = $this->executeViewHelper($arguments);
$value2 = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'v', array(), array('v' => $arguments['subject']));
$this->assertEquals($value, $value2);
}
$this->assertEquals($value, $expectedValue);
}
/**
* @return array
*/
public function getRenderTestValues() {
return array(
array(array('subject' => array()), NULL),
array(array('subject' => array('foo', 'bar')), 'foo'),
array(array('subject' => array('foo', 'bar'), 'as' => 'variable'), 'foo'),
array(array('subject' => new \ArrayIterator(array('foo', 'bar'))), 'foo'),
array(array('subject' => new \ArrayIterator(array('foo', 'bar')), 'as' => 'variable'), 'foo'),
);
}
/**
* @test
* @dataProvider getErrorTestValues
* @param mixed $subject
*/
public function testThrowsErrorsOnInvalidSubjectType($subject) {
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'Unsupported input type; cannot convert to array!');
$this->executeViewHelper(array('subject' => $subject));
}
/**
* @return array
*/
public function getErrorTestValues() {
return array(
array(0),
array(NULL),
array(new \DateTime()),
array(new \stdClass()),
);
}
}

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 SliceViewHelperTest extends AbstractViewHelperTest {
/**
* @test
* @dataProvider getRenderTestValues
* @param array $arguments
* @param mixed $expectedValue
*/
public function testRender(array $arguments, $expectedValue) {
if (TRUE === isset($arguments['as'])) {
$value = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'variable', $arguments);
} else {
$value = $this->executeViewHelper($arguments);
$haystack = $arguments['haystack'];
unset($arguments['haystack']);
$value2 = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'v', $arguments, array('v' => $haystack));
$this->assertEquals($value, $value2);
}
$this->assertEquals($value, $expectedValue);
}
/**
* @return array
*/
public function getRenderTestValues() {
return array(
array(array('haystack' => array(), 'length' => 0, 'start' => 0), array()),
array(array('haystack' => array('foo', 'bar'), 'length' => 1, 'start' => 0), array('foo')),
array(array('haystack' => array('foo', 'bar'), 'length' => 1, 'start' => 0, 'as' => 'variable'), array('foo')),
array(array('haystack' => new \ArrayIterator(array('foo', 'bar')), 'start' => 1, 'length' => 1), array(1 => 'bar')),
array(array('haystack' => new \ArrayIterator(array('foo', 'bar')), 'start' => 1, 'length' => 1, 'as' => 'variable'), array(1 => 'bar')),
);
}
}

View File

@@ -0,0 +1,29 @@
<?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 SortViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function throwsExceptionOnUnsupportedSortFlag() {
$arguments = array('sortFlags' => 'FOOBAR');
$this->setExpectedException('TYPO3\CMS\Fluid\Core\ViewHelper\Exception', 'The constant "FOOBAR" you\'re trying to use as a sortFlag is not allowed.');
$this->executeViewHelperUsingTagContent('Array', array('a', 'b', 'c'), $arguments);
}
}

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 ValuesViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsValuesUsingArgument() {
$result = $this->executeViewHelper(array('subject' => array('foo' => 'bar')));
$this->assertEquals(array('bar'), $result);
}
/**
* @test
*/
public function returnsValuesUsingTagContent() {
$result = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'test', array(), array('test' => array('foo' => 'bar')));
$this->assertEquals(array('bar'), $result);
}
/**
* @test
*/
public function returnsValuesUsingTagContentAndAsArgument() {
$result = $this->executeViewHelperUsingTagContent('ObjectAccessor', 'test.0', array('as' => 'test', 'subject' => array('foo' => 'bar')), array());
$this->assertEquals('bar', $result);
}
/**
* @test
*/
public function supportsIterators() {
$result = $this->executeViewHelper(array('subject' => new \ArrayIterator(array('foo' => 'bar'))));
$this->assertEquals(array('bar'), $result);
}
}

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