-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from sitegeist/task/testing
Task/testing
- Loading branch information
Showing
30 changed files
with
730 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Tests/Fixtures/Integration/Components/ContentParameter/ContentParameter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<fc:component> | ||
<fc:renderer>{content}</fc:renderer> | ||
</fc:component> |
4 changes: 4 additions & 0 deletions
4
Tests/Fixtures/Integration/Components/DateTimeParameter/DateTimeParameter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<fc:component> | ||
<fc:param name="date" type="string" /> | ||
<fc:renderer><f:format.date date="{date}" format="r" /></fc:renderer> | ||
</fc:component> |
10 changes: 10 additions & 0 deletions
10
Tests/Fixtures/Integration/Components/ScalarParameters/ScalarParameters.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<fc:component> | ||
<fc:param name="stringParameter" type="string" /> | ||
<fc:param name="integerParameter" type="integer" /> | ||
<fc:param name="trueParameter" type="boolean" /> | ||
<fc:param name="falseParameter" type="boolean" /> | ||
|
||
<fc:renderer> | ||
{stringParameter}|{integerParameter}|{trueParameter}|{falseParameter} | ||
</fc:renderer> | ||
</fc:component> |
5 changes: 5 additions & 0 deletions
5
Tests/Fixtures/Integration/Components/WithoutParameters/WithoutParameters.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<fc:component> | ||
<fc:renderer> | ||
Just a renderer. | ||
</fc:renderer> | ||
</fc:component> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
Tests/Helpers/ComponentArgumentConverter/DummyConversionInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
namespace SMS\FluidComponents\Tests\Helpers\ComponentArgumentConverter; | ||
|
||
interface DummyConversionInterface | ||
{ | ||
public static function fromString(string $value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
namespace SMS\FluidComponents\Tests\Helpers\ComponentArgumentConverter; | ||
|
||
class DummyValue implements DummyConversionInterface | ||
{ | ||
public $value; | ||
|
||
public function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function fromString(string $value) | ||
{ | ||
return new static($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace SMS\FluidComponents\Tests\Integration; | ||
|
||
use SMS\FluidComponents\Fluid\ViewHelper\ComponentRenderer; | ||
use TYPO3\CMS\Core\Cache\Backend\NullBackend; | ||
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker; | ||
|
||
class ComponentRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase | ||
{ | ||
protected $fluidNamespaces; | ||
protected $componentNamespaces; | ||
|
||
protected $testNamespace = 'SMS\\FluidComponents\\Tests\\Fixtures\\Integration\\Components'; | ||
|
||
protected $resetSingletonInstances = true; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
// Add fc ViewHelpers | ||
$this->fluidNamespaces = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces'] ?? null; | ||
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['fc'][] = 'SMS\\FluidComponents\\ViewHelpers'; | ||
|
||
// Register test components | ||
$this->componentNamespaces = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['fluid_components']['namespaces'] ?? null; | ||
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['fluid_components']['namespaces'] = [ | ||
$this->testNamespace => realpath(dirname(__FILE__) . '/../Fixtures/Integration/Components/') | ||
]; | ||
|
||
// Register and then disable fluid cache | ||
// This is necessary because of the way the RenderingContext deals with the fluid cache | ||
$cacheClass = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['frontend']; | ||
$cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class); | ||
$cacheManager->registerCache(new $cacheClass('fluid_template', new NullBackend(null))); | ||
|
||
$this->invoker = GeneralUtility::makeInstance(ViewHelperInvoker::class); | ||
$this->renderer = GeneralUtility::makeInstance(ComponentRenderer::class); | ||
} | ||
|
||
public function renderComponentProvider() | ||
{ | ||
return [ | ||
['WithoutParameters', [], '', 'Just a renderer.'], | ||
['ContentParameter', ['content' => 'children'], '', 'children'], | ||
['ContentParameter', [], 'children', 'children'], | ||
['ScalarParameters', [ | ||
'stringParameter' => 'This is a string', | ||
'integerParameter' => 123, | ||
'trueParameter' => true, // strange fluid behavior: will be 1 | ||
'falseParameter' => false, // strange fluid behavior: will be empty string | ||
], '', 'This is a string|123|1|'], | ||
['DateTimeParameter', ['date' => 1601371704], '', 'Tue, 29 Sep 2020 09:28:24 +0000'] | ||
]; | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider renderComponentProvider | ||
*/ | ||
public function renderComponent($component, $arguments, $content, $expected) | ||
{ | ||
// Render single component | ||
$this->renderer->setComponentNamespace($this->testNamespace . '\\' . $component); | ||
$renderingContext = GeneralUtility::makeInstance(RenderingContext::class); | ||
$output = $this->invoker->invoke( | ||
$this->renderer, | ||
$arguments, | ||
$renderingContext, | ||
function () use ($content) { | ||
return $content; | ||
} | ||
); | ||
|
||
// Ignore whitespace output from components | ||
$output = trim($output); | ||
|
||
$this->assertEquals($expected, $output); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['fluid_components']['namespaces'] = $this->componentNamespaces; | ||
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces'] = $this->fluidNamespaces; | ||
parent::tearDown(); | ||
} | ||
} |
Oops, something went wrong.