*/
protected $escapeChildren = false;
+ /**
+ * Initialize arguments.
+ *
+ * @api
+ * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
+ */
+ public function initializeArguments()
+ {
+ parent::initializeArguments();
+ $this->registerArgument('key', 'string', 'Translation Key');
+ $this->registerArgument('id', 'string', 'Translation Key compatible to TYPO3 Flow');
+ $this->registerArgument('default', 'string', 'If the given locallang key could not be found, this value is used. If this argument is not set, child nodes will be used to render the default');
+ $this->registerArgument('htmlEscape', 'bool', 'TRUE if the result should be htmlescaped. This won\'t have an effect for the default value');
+ $this->registerArgument('arguments', 'array', 'Arguments to be replaced in the resulting string');
+ $this->registerArgument('extensionName', 'string', 'UpperCamelCased extension key (for example BlogExample)');
+ }
+
/**
* Render translation
*
- * @param string $key Translation Key
- * @param string $id Translation Key compatible to TYPO3 Flow
- * @param string $default If the given locallang key could not be found, this value is used. If this argument is not set, child nodes will be used to render the default
- * @param bool $htmlEscape TRUE if the result should be htmlescaped. This won't have an effect for the default value
- * @param array $arguments Arguments to be replaced in the resulting string
- * @param string $extensionName UpperCamelCased extension key (for example BlogExample)
* @return string The translated key or tag body if key doesn't exist
*/
- public function render($key = null, $id = null, $default = null, $htmlEscape = null, array $arguments = null, $extensionName = null)
+ public function render()
{
+ $key = $this->arguments['key'];
+ $id = $this->arguments['id'];
+ $default = $this->arguments['default'];
+ $htmlEscape = $this->arguments['htmlEscape'];
+ $arguments = $this->arguments['arguments'];
+ $extensionName = $this->arguments['extensionName'];
+
return static::renderStatic(
array(
'key' => $key,
*
* The TYPO3 project - inspiring people to share!
*/
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\TranslateViewHelperFixtureForEmptyString;
-use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\TranslateViewHelperFixtureForTranslatedString;
use TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper;
/**
/**
* @var TranslateViewHelper
*/
- protected $subject;
+ protected $viewHelper;
+
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->viewHelper = new TranslateViewHelper();
+ $this->injectDependenciesIntoViewHelper($this->viewHelper);
+ }
/**
* @test
*/
public function renderThrowsExceptionIfNoKeyOrIdParameterIsGiven()
{
- $this->subject = GeneralUtility::makeInstance(TranslateViewHelper::class);
- $this->injectDependenciesIntoViewHelper($this->subject);
-
$this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException::class);
$this->expectExceptionCode(1351584844);
- $this->subject->render();
+ $this->setArgumentsUnderTest(
+ $this->viewHelper,
+ []
+ );
+ $this->viewHelper->initializeArgumentsAndRender();
}
/**
*/
public function renderReturnsStringForGivenKey()
{
- $this->subject = GeneralUtility::makeInstance(TranslateViewHelperFixtureForTranslatedString::class);
- $this->injectDependenciesIntoViewHelper($this->subject);
- $this->assertEquals('<p>hello world</p>', $this->subject->render('foo'));
+ $this->viewHelper->setRenderChildrenClosure(
+ function () {
+ return '<p>hello world</p>';
+ }
+ );
+ $this->setArgumentsUnderTest(
+ $this->viewHelper,
+ [
+ 'key' => 'foo'
+ ]
+ );
+ $actualResult = $this->viewHelper->initializeArgumentsAndRender();
+ $this->assertEquals('<p>hello world</p>', $actualResult);
}
/**
*/
public function renderReturnsStringForGivenId()
{
- $this->subject = GeneralUtility::makeInstance(TranslateViewHelperFixtureForTranslatedString::class);
- $this->injectDependenciesIntoViewHelper($this->subject);
- $this->assertEquals('<p>hello world</p>', $this->subject->render(null, 'bar'));
+ $this->viewHelper->setRenderChildrenClosure(
+ function () {
+ return '<p>hello world</p>';
+ }
+ );
+ $this->setArgumentsUnderTest(
+ $this->viewHelper,
+ [
+ 'key' => null,
+ 'id' => 'bar'
+ ]
+ );
+ $actualResult = $this->viewHelper->initializeArgumentsAndRender();
+ $this->assertEquals('<p>hello world</p>', $actualResult);
}
/**
*/
public function renderReturnsDefaultIfNoTranslationIsFound()
{
- $this->subject = GeneralUtility::makeInstance(TranslateViewHelperFixtureForEmptyString::class);
- $this->injectDependenciesIntoViewHelper($this->subject);
- $this->assertEquals('default', $this->subject->render(null, 'bar', 'default'));
+ $this->viewHelper->setRenderChildrenClosure(
+ function () {
+ return 'default';
+ }
+ );
+ $this->setArgumentsUnderTest(
+ $this->viewHelper,
+ [
+ 'key' => null,
+ 'id' => 'bar',
+ 'default' => 'default'
+ ]
+ );
+ $actualResult = $this->viewHelper->initializeArgumentsAndRender();
+ $this->assertEquals('default', $actualResult);
}
}