DigiComp.FluidJsonViews/Tests/Functional/FluidJsonTest.php

79 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2024-06-02 01:59:15 +02:00
<?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']);
}
}