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,229 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\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\Fixtures\Domain\Model\Foo;
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
* @package Vhs
*/
class ConvertViewHelperTest extends AbstractViewHelperTest {
/**
* @param mixed $value
* @param string $type
* @param mixed $expected
* @return void
*/
protected function executeConversion($value, $type, $expected) {
$this->assertEquals($expected, $this->executeViewHelper(array('value' => $value, 'type' => $type)));
}
/**
* @test
*/
public function throwsRuntimeExceptionIfTypeOfDefaultValueIsUnsupported() {
$this->setExpectedException('RuntimeException', NULL, 1364542576);
$this->executeViewHelper(array('type' => 'foobar', 'value' => NULL, 'default' => '1'));
}
/**
* @test
*/
public function throwsRuntimeExceptionIfTypeIsUnsupportedAndNoDefaultProvided() {
$this->setExpectedException('RuntimeException', NULL, 1364542884);
$this->executeViewHelper(array('type' => 'unsupported', 'value' => NULL));
}
/**
* @test
*/
public function throwsRuntimeExceptionIfTypeOfDefaultIsNotSameAsType() {
$this->setExpectedException('RuntimeException', NULL, 1364542576);
$this->executeViewHelper(array('type' => 'ObjectStorage', 'value' => NULL, 'default' => '1'));
}
/**
* @test
*/
public function convertNullToString() {
$this->executeConversion(NULL, 'string', '');
}
/**
* @test
*/
public function convertNullToInteger() {
$this->executeConversion(NULL, 'integer', 0);
}
/**
* @test
*/
public function convertNullToFloat() {
$this->executeConversion(NULL, 'float', 0);
}
/**
* @test
*/
public function convertStringToString() {
$this->executeConversion('1', 'string', '1');
}
/**
* @test
*/
public function convertStringToInteger() {
$this->executeConversion('1', 'integer', 1);
}
/**
* @test
*/
public function convertArrayToObjectStorage() {
$dummy = new Foo();
$storage = new ObjectStorage();
$storage->attach($dummy);
$this->executeConversion(array($dummy), 'ObjectStorage', $storage);
}
/**
* @test
*/
public function convertObjectStorageToArray() {
$dummy = new Foo();
$storage = new ObjectStorage();
$storage->attach($dummy);
$this->executeConversion($storage, 'array', array($dummy));
}
/**
* @test
*/
public function returnsEmptyStringForTypeStringAndValueNull() {
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(NULL));
$viewHelper->setArguments(array('type' => 'string'));
$converted = $viewHelper->render();
$this->assertEquals('', $converted);
}
/**
* @test
*/
public function returnsStringForTypeStringAndValueInteger() {
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(12345));
$viewHelper->setArguments(array('type' => 'string'));
$converted = $viewHelper->render();
$this->assertInternalType('string', $converted);
}
/**
* @test
*/
public function returnsArrayForTypeArrayAndValueNull() {
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(NULL));
$viewHelper->setArguments(array('type' => 'array'));
$converted = $viewHelper->render();
$this->assertInternalType('array', $converted);
}
/**
* @test
*/
public function returnsArrayForTypeArrayAndValueString() {
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
$viewHelper->setArguments(array('type' => 'array'));
$converted = $viewHelper->render();
$this->assertInternalType('array', $converted);
$this->assertEquals(array('foo'), $converted);
}
/**
* @test
*/
public function returnsObjectStorageForTypeArrayAndValueNull() {
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(NULL));
$viewHelper->setArguments(array('type' => 'ObjectStorage'));
$converted = $viewHelper->render();
$this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', $converted);
$this->assertEquals(0, $converted->count());
}
/**
* @test
*/
public function returnsArrayForTypeObjectStorage() {
$domainObject = new Foo();
$storage = new ObjectStorage();
$storage->attach($domainObject);
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($storage));
$viewHelper->setArguments(array('type' => 'array'));
$converted = $viewHelper->render();
$this->assertInternalType('array', $converted);
$this->assertEquals(1, count($converted));
}
/**
* @test
*/
public function returnsBooleanForTypeBooleanAndValueNull() {
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(NULL));
$viewHelper->setArguments(array('type' => 'boolean'));
$converted = $viewHelper->render();
$this->assertInternalType('boolean', $converted);
$this->assertFalse($converted);
}
/**
* @test
*/
public function returnsBooleanForTypeBooleanAndValueInteger() {
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(1));
$viewHelper->setArguments(array('type' => 'boolean'));
$converted = $viewHelper->render();
$this->assertInternalType('boolean', $converted);
$this->assertTrue($converted);
}
/**
* @test
*/
public function returnsBooleanForTypeBooleanAndValueString() {
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
$viewHelper->setArguments(array('type' => 'boolean'));
$converted = $viewHelper->render();
$this->assertInternalType('boolean', $converted);
$this->assertTrue($converted);
}
/**
* @test
*/
public function returnsExpectedDefaultValue() {
$viewHelper = $this->getAccessibleMock('FluidTYPO3\Vhs\ViewHelpers\Variable\ConvertViewHelper', array('renderChildren'));
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(NULL));
$viewHelper->setArguments(array('type' => 'boolean', 'default' => TRUE));
$converted = $viewHelper->render();
$this->assertInternalType('boolean', $converted);
$this->assertTrue($converted);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\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\Fixtures\Domain\Model\Foo;
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class GetViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsNullIfVariableDoesNotExist() {
$this->assertNull($this->executeViewHelper(array('name' => 'void', array())));
}
/**
* @test
*/
public function returnsDirectValueIfExists() {
$this->assertEquals(1, $this->executeViewHelper(array('name' => 'test'), array('test' => 1)));
}
/**
* @test
*/
public function returnsNestedValueIfRootExists() {
$this->assertEquals(1, $this->executeViewHelper(array('name' => 'test.test'), array('test' => array('test' => 1))));
}
/**
* @test
*/
public function returnsNestedValueUsingRawKeysIfRootExists() {
$this->assertEquals(1, $this->executeViewHelper(array('name' => 'test.test', 'useRawKeys' => TRUE), array('test' => array('test' => 1))));
}
/**
* @test
*/
public function returnsNestedValueIfRootExistsAndMembersAreNumeric() {
$this->assertEquals(2, $this->executeViewHelper(array('name' => 'test.1'), array('test' => array(1, 2))));
}
/**
* @test
*/
public function returnsNullAndSuppressesExceptionOnInvalidPropertyGetting() {
$user = new Foo();
$this->assertEquals(NULL, $this->executeViewHelper(array('name' => 'test.void'), array('test' => $user)));
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Variable\Register;
/*
* 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 Stefan Neufeind <info (at) speedpartner.de>
* @package Vhs
*/
class GetViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function silentlyIgnoresMissingFrontendController() {
$result = $this->executeViewHelper(array('name' => 'name'));
$this->assertNull($result);
}
/**
* @test
*/
public function returnsNullIfRegisterDoesNotExist() {
$GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
$name = uniqid();
$this->assertEquals(NULL, $this->executeViewHelper(array('name' => $name)));
}
/**
* @test
*/
public function returnsValueIfRegisterExists() {
$GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
$name = uniqid();
$value = uniqid();
$GLOBALS['TSFE']->register[$name] = $value;
$this->assertEquals($value, $this->executeViewHelper(array('name' => $name)));
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\Variable\Register;
/*
* 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 Stefan Neufeind <info (at) speedpartner.de>
* @package Vhs
*/
class SetViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function silentlyIgnoresMissingFrontendController() {
$result = $this->executeViewHelper(array('name' => 'name'));
$this->assertNull($result);
}
/**
* @test
*/
public function canSetRegister() {
$GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(array(), 1, 1));
$name = uniqid();
$value = uniqid();
$this->executeViewHelper(array('name' => $name, 'value' => $value));
$this->assertEquals($value, $GLOBALS['TSFE']->register[$name]);
}
/**
* @test
*/
public function canSetVariableWithValueFromTagContent() {
$GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(array(), 1, 1));
$name = uniqid();
$value = uniqid();
$this->executeViewHelperUsingTagContent('Text', $value, array('name' => $name));
$this->assertEquals($value, $GLOBALS['TSFE']->register[$name]);
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\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\Fixtures\Domain\Model\Foo;
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
/**
* @protection off
* @author Claus Due <claus@namelesscoder.net>
* @package Vhs
*/
class SetViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function canSetVariable() {
$variables = new \ArrayObject(array('test' => TRUE));
$this->executeViewHelper(array('name' => 'test', 'value' => FALSE), $variables);
$this->assertFalse($variables['test']);
}
/**
* @test
*/
public function canSetVariableInExistingArrayValue() {
$variables = new \ArrayObject(array('test' => array('test' => TRUE)));
$this->executeViewHelper(array('name' => 'test.test', 'value' => FALSE), $variables);
$this->assertFalse($variables['test']['test']);
}
/**
* @test
*/
public function ignoresNestedVariableIfRootDoesNotExist() {
$variables = new \ArrayObject(array('test' => array('test' => TRUE)));
$result = $this->executeViewHelper(array('name' => 'doesnotexist.test', 'value' => FALSE), $variables);
$this->assertNull($result);
}
/**
* @test
*/
public function ignoresNestedVariableIfRootDoesNotAllowSetting() {
$domainObject = new Foo();
$variables = new \ArrayObject(array('test' => $domainObject));
$result = $this->executeViewHelper(array('name' => 'test.propertydoesnotexist', 'value' => FALSE), $variables);
$this->assertNull($result);
}
/**
* @test
*/
public function ignoresNestedVariableIfRootPropertyNameIsInvalid() {
$variables = new \ArrayObject(array('test' => 'test'));
$result = $this->executeViewHelper(array('name' => 'test.test', 'value' => FALSE), $variables);
$this->assertNull($result);
}
/**
* @test
*/
public function canSetVariableWithValueFromTagContent() {
$variables = new \ArrayObject(array('test' => TRUE));
$this->executeViewHelperUsingTagContent('Boolean', FALSE, array('name' => 'test'), $variables);
$this->assertFalse($variables['test']);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\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 TyposcriptViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function returnsNullIfPathIsNull() {
$this->assertNull($this->executeViewHelper(array('path' => NULL)));
}
/**
* @test
*/
public function returnsArrayIfPathContainsArray() {
$this->assertThat($this->executeViewHelper(array('path' => 'config.tx_extbase.features')), new \PHPUnit_Framework_Constraint_IsType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY));
}
/**
* @test
*/
public function canGetPathUsingArgument() {
$this->assertNotEmpty($this->executeViewHelper(array('path' => 'config.tx_extbase.features')));
}
/**
* @test
*/
public function canGetPathUsingTagContent() {
$this->assertNotEmpty($this->executeViewHelperUsingTagContent('Text', 'config.tx_extbase.features'));
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\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 UnsetViewHelperTest extends AbstractViewHelperTest {
/**
* @test
*/
public function canUnsetVariable() {
$variables = new \ArrayObject(array('test' => TRUE));
$this->executeViewHelper(array('name' => 'test'), $variables);
$this->assertNotContains('test', $variables);
}
}