DigiComp.FluidRenderFunctions/Tests/Functional/RenderFunctionsTest.php

99 lines
3.3 KiB
PHP
Raw Normal View History

2024-06-01 23:15:35 +02:00
<?php
declare(strict_types=1);
namespace DigiComp\FluidRenderFunctions\Tests\Functional;
use DigiComp\FluidRenderFunctions\Tests\Functional\Fixtures\Domain\Post;
2024-06-01 23:15:35 +02:00
use Neos\Flow\Mvc\Routing\Route;
use Neos\Flow\Tests\FunctionalTestCase;
use Neos\FluidAdaptor\Tests\Functional\Form\Fixtures\Domain\Model\Tag;
use Symfony\Component\DomCrawler\Crawler;
2024-06-01 23:15:35 +02:00
class RenderFunctionsTest extends FunctionalTestCase
{
protected static $testablePersistenceEnabled = true;
/**
* Initializer
*/
protected function setUp(): void
{
parent::setUp();
$route = new Route();
$route->setUriPattern('test/fluidrenderfunctions/test(/{@action})');
$route->setDefaults([
'@package' => 'DigiComp.FluidRenderFunctions',
'@subpackage' => 'Tests\Functional\Fixtures',
'@controller' => 'Test',
'@action' => 'index',
]);
$route->setAppendExceedingArguments(true);
$this->router->addRoute($route);
}
/**
* @test
*/
public function itAllowsFluidToRenderWrappedArray(): void
{
$response = $this->browser->request('http://localhost/test/fluidrenderfunctions/test');
static::assertEquals("hallo is cool\n", (string)$response->getBody());
}
/**
* @test
*/
public function itAllowsToRenderTheOptionsArgumentOfSelectNicely(): void
{
$post1 = new Tag('hallo');
$this->persistenceManager->add($post1);
$post2 = new Tag('hallo 2');
$this->persistenceManager->add($post2);
2024-06-01 23:15:35 +02:00
$this->persistenceManager->persistAll();
$this->browser->request('http://localhost/test/fluidrenderfunctions/test/select');
$options = $this->browser->getCrawler()
->filterXPath('//select[1]/option')
->each(fn (Crawler $node) => $node->text());
static::assertEquals(['hallo is cool', 'hallo 2 is cool'], $options);
}
/**
* @test
*/
public function itAllowsRenderFunctionOnStandardSelect(): void
{
$post1 = new Tag('hallo');
$this->persistenceManager->add($post1);
$post2 = new Tag('hallo 2');
$this->persistenceManager->add($post2);
$this->persistenceManager->persistAll();
$this->browser->request('http://localhost/test/fluidrenderfunctions/test/extendedselect');
$options = $this->browser->getCrawler()
->filterXPath('//select[1]/option')
->each(fn (Crawler $node) => $node->text());
static::assertEquals(['hallo is cool', 'hallo 2 is cool'], $options);
}
/**
* @test
*/
public function itAllowsRenderFunctionOnStandardTextField(): void
{
$testDate = new \DateTimeImmutable('2024-06-02T15:03:00Z');
$post1 = new Post('hallo', $testDate);
$this->persistenceManager->add($post1);
$this->persistenceManager->persistAll();
$this->browser->request('http://localhost/test/fluidrenderfunctions/test/extendedtextfield');
$input1 = $this->browser->getCrawler()->filterXPath('//input[@type="text"][1]/@value')->text('input not found');
static::assertEquals('02.06.2024', $input1);
$input2 = $this->browser->getCrawler()->filterXPath('//input[@type="text"][2]/@value')->text('input not found');
static::assertEquals('02.06.2024', $input2);
2024-06-01 23:15:35 +02:00
}
}