c3lf-system-3/tests/EventTest.php

105 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2020-01-18 12:03:32 +00:00
<?php
use App\Event;
class EventTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testEmpty()
{
$this->get('/1/events');
$this->assertResponseOk();
$this->assertEquals('[]',$this->response->getContent());
}
public function testMembers()
{
Event::create(['slug'=>'EVENT','name'=>'Event']);
$this->get('/1/events');
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(1, count($response));
$this->assertEquals(1, $response[0]['eid']);
$this->assertEquals('EVENT', $response[0]['slug']);
$this->assertEquals('Event', $response[0]['name']);
}
public function testmultiMembers()
{
Event::create(['slug'=>'EVENT1','name'=>'Event 1']);
Event::create(['slug'=>'EVENT2','name'=>'Event 2']);
Event::create(['slug'=>'EVENT3','name'=>'Event 3']);
$this->get('/1/events');
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(3, count($response));
}
public function testCreateEvent()
{
$this->post('/1/event', ['slug'=>'EVENT', 'name'=>'Event']);
$response = $this->response->getOriginalContent();
2020-01-18 12:35:31 +00:00
$this->assertResponseStatus(201);
2020-01-18 12:03:32 +00:00
$this->assertEquals(1, $response['eid']);
$this->assertEquals('EVENT', $response['slug']);
$this->assertEquals('Event', $response['name']);
$events = Event::all();
$this->assertEquals(1, count($events));
$this->assertEquals('EVENT', $events[0]['slug']);
$this->assertEquals('Event', $events[0]['name']);
}
public function testUpdateEvent()
{
$event = Event::create(['slug'=>'EVENT1','name'=>'Event 1']);
$this->assertEquals(1, $event['eid']);
$this->assertEquals('EVENT1', $event['slug']);
$this->assertEquals('Event 1', $event['name']);
$this->put('/1/event/'.$event->eid, ['slug'=>'EVENT2', 'name'=>'Event 2']);
$response = $this->response->getOriginalContent();
2020-01-18 12:35:31 +00:00
$this->assertResponseOk();
2020-01-18 12:03:32 +00:00
$this->assertEquals(1, $response['eid']);
$this->assertEquals('EVENT2', $response['slug']);
$this->assertEquals('Event 2', $response['name']);
$events = Event::all();
$this->assertEquals(1, count($events));
$this->assertEquals('EVENT2', $events[0]['slug']);
$this->assertEquals('Event 2', $events[0]['name']);
}
public function testRemoveEvent()
{
$event = Event::create(['slug'=>'EVENT1','name'=>'Event 1']);
Event::create(['slug'=>'EVENT2','name'=>'Event 2']);
$this->assertEquals(1, $event['eid']);
$this->assertEquals('EVENT1', $event['slug']);
$this->assertEquals('Event 1', $event['name']);
$this->assertEquals(2, count(Event::all()));
$this->delete('/1/event/'.$event->eid);
2020-01-18 12:35:31 +00:00
$this->assertResponseOk();
2020-01-18 12:03:32 +00:00
$this->assertEquals(1, count(Event::all()));
}
}