All checks were successful
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/functional-tests/2 Pipeline was successful
ci/woodpecker/push/functional-tests/1 Pipeline was successful
ci/woodpecker/push/functional-tests/3 Pipeline was successful
ci/woodpecker/push/functional-tests/4 Pipeline was successful
78 lines
2.5 KiB
PHP
78 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DigiComp\FluidJsonViews\Tests\Functional;
|
|
|
|
use Neos\Flow\Mvc\Routing\Route;
|
|
use Neos\Flow\Tests\FunctionalTestCase;
|
|
use Neos\FluidAdaptor\Tests\Functional\Form\Fixtures\Domain\Model\Tag;
|
|
|
|
class FluidJsonTest extends FunctionalTestCase
|
|
{
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected static $testablePersistenceEnabled = true;
|
|
|
|
/**
|
|
* Initializer
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$route = new Route();
|
|
$route->setUriPattern('test/fluidjsonviews/test(/{@action})');
|
|
$route->setDefaults([
|
|
'@package' => 'DigiComp.FluidJsonViews',
|
|
'@subpackage' => 'Tests\Functional\Fixtures',
|
|
'@controller' => 'Test',
|
|
'@action' => 'index',
|
|
]);
|
|
$route->setAppendExceedingArguments(true);
|
|
$this->router->addRoute($route);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function itAllowsFluidToRenderWrappedArray(): 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/fluidjsonviews/test');
|
|
$link = $this->browser->getCrawler()->selectLink('jsonView')->link()->getUri();
|
|
$response = $this->browser->request($link);
|
|
static::assertEquals('application/json', $response->getHeaderLine('Content-Type'));
|
|
$result = \json_decode((string)$response->getBody(), true);
|
|
static::assertEquals(2, $result['recordsTotal']);
|
|
static::assertCount(2, $result['results']);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function itFiltersIfTermProvided(): 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/fluidjsonviews/test');
|
|
$link = $this->browser->getCrawler()->selectLink('jsonView')->link()->getUri();
|
|
$response = $this->browser->request($link . '&term=2');
|
|
$result = \json_decode((string)$response->getBody(), true);
|
|
static::assertEquals('application/json', $response->getHeaderLine('Content-Type'));
|
|
|
|
static::assertEquals(2, $result['recordsTotal']);
|
|
static::assertEquals(1, $result['recordsFiltered']);
|
|
static::assertCount(1, $result['results']);
|
|
}
|
|
}
|