add tests for events api
This commit is contained in:
parent
73366605ed
commit
23c550428a
1 changed files with 101 additions and 0 deletions
101
tests/EventTest.php
Normal file
101
tests/EventTest.php
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
<?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();
|
||||||
|
|
||||||
|
$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();
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$this->assertEquals(1, count(Event::all()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue