infinito/application/symfony/tests/Functional/FormatFunctionTest.php

75 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Functional;
use Infinito\Domain\Fixture\FixtureSource\HomepageFixtureSource;
2020-04-02 21:13:35 +02:00
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
/**
* @author kevinfrantz
*/
class FormatFunctionTest extends WebTestCase
{
2019-03-29 18:44:22 +01:00
/**
* @var Client
*/
private $client;
2019-03-29 23:21:52 +01:00
/**
* @var string
*/
private $identity;
/**
* {@inheritdoc}
*
* @see \PHPUnit\Framework\TestCase::setUp()
*/
2019-03-29 18:44:22 +01:00
public function setUp(): void
{
$this->client = static::createClient();
2019-03-29 23:21:52 +01:00
$this->identity = HomepageFixtureSource::getSlug();
2019-03-29 18:44:22 +01:00
}
public function testHomepage(): void
{
2019-03-29 23:21:52 +01:00
$this->client->request(Request::METHOD_GET, 'api/rest/source/'.$this->identity);
2019-03-29 18:44:22 +01:00
$this->assertEquals(200, $this->client->getResponse()
->getStatusCode());
$this->assertJson($this->client->getResponse()
->getContent());
}
public function testHomepageWithHTML(): void
{
2019-03-29 23:21:52 +01:00
$this->client->request(Request::METHOD_GET, 'api/rest/source/'.$this->identity.'.html');
2019-03-29 18:44:22 +01:00
$this->assertEquals(200, $this->client->getResponse()
->getStatusCode());
$this->assertContains('<html', $this->client->getResponse()
->getContent());
}
public function testHomepageWithJSON(): void
{
2019-03-29 23:21:52 +01:00
$this->client->request(Request::METHOD_GET, 'api/rest/source/'.$this->identity.'.json');
2019-03-29 18:44:22 +01:00
$this->assertEquals(200, $this->client->getResponse()
->getStatusCode());
$this->assertJson($this->client->getResponse()
->getContent());
}
public function testHomepageWithXML(): void
{
2019-03-29 23:21:52 +01:00
$this->client->request(Request::METHOD_GET, 'api/rest/source/'.$this->identity.'.xml');
2019-03-29 18:44:22 +01:00
$this->assertEquals(200, $this->client->getResponse()
->getStatusCode());
$content = $this->client->getResponse()->getContent();
$xml = new \XMLReader();
$xml->XML($content);
$xml->setParserProperty(\XMLReader::VALIDATE, true);
$this->assertTrue($xml->isValid());
}
}