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']); } }