From 23c550428a8cb11b94753c7b209a3fc64b703406 Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 18 Jan 2020 13:03:32 +0100 Subject: [PATCH] add tests for events api --- tests/EventTest.php | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/EventTest.php diff --git a/tests/EventTest.php b/tests/EventTest.php new file mode 100644 index 0000000..166cb2a --- /dev/null +++ b/tests/EventTest.php @@ -0,0 +1,101 @@ +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())); + } + +}