1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00
date-poll-api/tests/Functional/CommentControllerTest.php
2022-02-10 10:32:13 +01:00

77 lines
1.9 KiB
PHP
Executable File

<?php
namespace App\Tests\Functional;
use Liip\TestFixturesBundle\Test\FixturesTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AdminControllerTest extends WebTestCase {
use FixturesTrait;
// Test getting all comments from one Poll
public function testGetAllComments() {
$client = static::createClient();
$this->loadFixtures(array(
'App\DataFixtures\AppPollFixtures',
'App\DataFixtures\CommentFixtures',
));
$client->request('GET', '/api/v1/poll/1/comments');
$response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$body = $response->getContent();
$json = json_decode($body, true);
$this->assertEquals(5, count($json['data']));
}
public function testNewComment() {
$client = static::createClient();
$this->loadFixtures(array(
'App\DataFixtures\AppPollFixtures',
'App\DataFixtures\CommentFixtures',
));
$data = [
'text' => "Mon nouveau commentaire de test !",
'email' => "email@host.plop"
];
$client->request('POST', '/api/v1/poll/1/comment', [
'body' => json_encode($data)
],
[],
[
'CONTENT_TYPE' => 'application/json',
'HTTP_ACCEPT' => 'application/json',
],
json_encode($data)
);
$response = $client->getResponse();
$this->assertEquals(201, $response->getStatusCode());
$body = $response->getContent();
$json = json_decode($body, true);
$this->assertEquals("email@host.plop", $json['data']['your_comment']['pseudo']);
}
public function testDeleteComments() {
$client = static::createClient();
$this->loadFixtures(array(
'App\DataFixtures\AppPollFixtures',
'App\DataFixtures\CommentFixtures',
));
$client->request('DELETE', '/api/v1/poll/1/comments');
$response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
}