2020-05-08 23:00:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Tests\Functional;
|
|
|
|
|
|
|
|
use Liip\TestFixturesBundle\Test\FixturesTrait;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
|
|
|
|
class PollControllerTest extends WebTestCase {
|
|
|
|
use FixturesTrait;
|
|
|
|
|
|
|
|
// Test getting all polls
|
|
|
|
public function testGetAllPolls() {
|
|
|
|
$client = static::createClient();
|
|
|
|
|
|
|
|
$this->loadFixtures(array(
|
|
|
|
'App\DataFixtures\AppPollFixtures'
|
|
|
|
));
|
|
|
|
|
|
|
|
$client->request('GET', '/api/v1/poll/');
|
|
|
|
|
|
|
|
$response = $client->getResponse();
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$body = $response->getContent();
|
|
|
|
$json = json_decode($body, true);
|
|
|
|
$this->assertEquals(4, count($json['poll']));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting one poll (we should try to check all poll property)
|
|
|
|
public function testGetOnePoll() {
|
|
|
|
$client = static::createClient();
|
|
|
|
|
|
|
|
$this->loadFixtures(array(
|
|
|
|
'App\DataFixtures\AppPollFixtures'
|
|
|
|
));
|
|
|
|
|
|
|
|
$client->request('GET', '/api/v1/poll/1');
|
|
|
|
|
|
|
|
$response = $client->getResponse();
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$body = $response->getContent();
|
|
|
|
$json = json_decode($body, true);
|
|
|
|
$this->assertEquals("citron ou orange", $json['poll']['title']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test Put some data on a poll
|
|
|
|
public function testPutOnePoll() {
|
|
|
|
$client = static::createClient();
|
|
|
|
|
|
|
|
$this->loadFixtures(array(
|
|
|
|
'App\DataFixtures\AppPollFixtures'
|
|
|
|
));
|
|
|
|
|
|
|
|
$client->request('PUT', '/api/v1/poll/1/notTheToken', [
|
|
|
|
'body' => "{
|
|
|
|
\"id\": 1,
|
|
|
|
\"title\": \"Fromage ou dessert ? \",
|
|
|
|
\"description\": \"Votre plat préféré\",
|
|
|
|
\"creation_date\": \"2048-04-25T16:19:48+02:00\",
|
|
|
|
\"expiracy_date\": \"2048-04-25T16:19:48+02:00\",
|
|
|
|
\"kind\": \"text\",
|
|
|
|
\"allowed_answers\": [
|
|
|
|
\"yes\"
|
|
|
|
],
|
|
|
|
\"modification_policy\": \"nobody\",
|
|
|
|
\"mail_on_vote\": true,
|
|
|
|
\"choices\": [
|
|
|
|
{
|
|
|
|
\"id\": 1,
|
|
|
|
\"name\": \"fromage\"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"id\": 2,
|
|
|
|
\"name\": \"dessert\"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
\"default_expiracy_days_from_now\": 365
|
|
|
|
}"
|
|
|
|
]);
|
|
|
|
$response = $client->getResponse();
|
|
|
|
$this->assertEquals(403, $response->getStatusCode());
|
|
|
|
|
|
|
|
//Same request but with admin key
|
|
|
|
$client->request('PUT', '/api/v1/poll/1/5eb5ade73ec4f', [
|
|
|
|
'body' => "{
|
|
|
|
\"id\": 1,
|
|
|
|
\"title\": \"Fromage ou dessert ? \",
|
|
|
|
\"description\": \"Votre plat préféré\",
|
|
|
|
\"creation_date\": \"2048-04-25T16:19:48+02:00\",
|
|
|
|
\"expiracy_date\": \"2048-04-25T16:19:48+02:00\",
|
|
|
|
\"kind\": \"text\",
|
|
|
|
\"allowed_answers\": [
|
|
|
|
\"yes\"
|
|
|
|
],
|
|
|
|
\"modification_policy\": \"nobody\",
|
|
|
|
\"mail_on_vote\": true,
|
|
|
|
\"choices\": [
|
|
|
|
{
|
|
|
|
\"id\": 1,
|
|
|
|
\"name\": \"fromage\"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
\"id\": 2,
|
|
|
|
\"name\": \"dessert\"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
\"default_expiracy_days_from_now\": 365
|
|
|
|
}"
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response = $client->getResponse();
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
|
|
|
|
//Checking the result of modification
|
|
|
|
$client->request('GET', '/api/v1/poll/1');
|
|
|
|
|
|
|
|
$response = $client->getResponse();
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$body = $response->getContent();
|
|
|
|
$json = json_decode($body, true);
|
|
|
|
$this->assertEquals("Fromage ou dessert ?", $json['poll']['title']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test Post new poll
|
|
|
|
public function testPostOnePoll() {
|
2020-05-23 16:00:31 +02:00
|
|
|
$client = static::createClient();
|
|
|
|
|
|
|
|
$this->loadFixtures(array(
|
|
|
|
'App\DataFixtures\AppPollFixtures'
|
|
|
|
));
|
|
|
|
|
2020-05-23 18:37:09 +02:00
|
|
|
$data = [
|
|
|
|
"title" => "Fromage ou dessert ? ",
|
|
|
|
"description" => "Votre plat préféré",
|
|
|
|
"creation_date" => "2048-04-25T16:19:48+02:00",
|
|
|
|
"expiracy_date" => "2048-04-25T16:19:48+02:00",
|
|
|
|
"kind" => "text",
|
|
|
|
"allowed_answers" => [
|
|
|
|
"yes"
|
|
|
|
],
|
|
|
|
"modification_policy" => "nobody",
|
|
|
|
"mail_on_vote" => true,
|
|
|
|
"choices" => [
|
|
|
|
[
|
|
|
|
"id" => 1,
|
|
|
|
"name" => "fromage"
|
2020-05-23 16:00:31 +02:00
|
|
|
],
|
2020-05-23 18:37:09 +02:00
|
|
|
[
|
|
|
|
"id" => 2,
|
|
|
|
"name" => "dessert"
|
|
|
|
]
|
|
|
|
],
|
|
|
|
"default_expiracy_days_from_now" => 365
|
|
|
|
];
|
|
|
|
|
|
|
|
$client->request('POST', '/api/v1/poll/', [
|
|
|
|
'json' => $data
|
|
|
|
], [], [], json_encode($data));
|
2020-05-23 16:00:31 +02:00
|
|
|
|
|
|
|
$response = $client->getResponse();
|
|
|
|
$this->assertEquals(201, $response->getStatusCode());
|
2020-05-08 23:00:57 +02:00
|
|
|
|
2020-05-23 16:00:31 +02:00
|
|
|
$data = $response->getContent();
|
|
|
|
$this->assertIsNumeric($data['poll']['id']);
|
2020-05-08 23:00:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|