c3lf-system-3/tests/ContainerTest.php

117 lines
3.5 KiB
PHP
Raw Normal View History

2020-01-18 00:28:21 +00:00
<?php
use App\Container;
use App\Event;
use App\Item;
class ContainerTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testEmpty()
{
$this->get('/1/boxes');
$this->assertResponseOk();
$this->assertEquals('[]',$this->response->getContent());
}
public function testMembers()
{
Container::create(['name'=>'BOX']);
$this->get('/1/boxes');
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(1, count($response));
$this->assertEquals(1, $response[0]['cid']);
$this->assertEquals('BOX', $response[0]['name']);
$this->assertEquals(0, $response[0]['itemCount']);
}
public function testmultiMembers()
{
Container::create(['name'=>'BOX 1']);
Container::create(['name'=>'BOX 2']);
Container::create(['name'=>'BOX 3']);
$this->get('/1/boxes');
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(3, count($response));
}
public function testItemCount()
{
$event = Event::create(['slug'=>'EVENT','name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'item_uid'=>1, 'wann'=>'', 'wo'=>'','description'=>'1']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'item_uid'=>2, 'wann'=>'', 'wo'=>'','description'=>'2']);
$this->get('/1/boxes');
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(1, count($response));
$this->assertEquals(2, $response[0]['itemCount']);
}
2020-01-18 12:35:31 +00:00
public function testCreateContainer(){
$this->post('/1/box', ['name'=>'BOX']);
$response = $this->response->getOriginalContent();
$this->assertResponseStatus(201);
$this->assertEquals(1, $response['cid']);
$this->assertEquals('BOX', $response['name']);
$this->assertEquals(0, $response['itemCount']);
$boxes = Container::all();
$this->assertEquals(1, count($boxes));
$this->assertEquals(1, $boxes[0]['cid']);
$this->assertEquals('BOX', $boxes[0]['name']);
$this->assertEquals(0, $boxes[0]['itemCount']);
}
public function testUpdateContainer(){
$box = Container::create(['name'=>'BOX 1']);
$this->assertEquals(1, $box['cid']);
$this->assertEquals('BOX 1', $box['name']);
$this->assertEquals(0, $box['itemCount']);
$this->put('/1/box/'.$box->cid, ['name'=>'BOX 2']);
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(1, $response['cid']);
$this->assertEquals('BOX 2', $response['name']);
$this->assertEquals(0, $response['itemCount']);
$boxes = Container::all();
$this->assertEquals(1, count($boxes));
$this->assertEquals(1, $boxes[0]['cid']);
$this->assertEquals('BOX 2', $boxes[0]['name']);
$this->assertEquals(0, $boxes[0]['itemCount']);
}
public function testDeleteContainer(){
$box = Container::create(['name'=>'BOX 1']);
Container::create(['name'=>'BOX 2']);
$this->assertEquals(2, count(Container::all()));
$this->delete('/1/box/'.$box->cid);
$this->assertResponseOk();
$this->assertEquals(1, count(Container::all()));
}
2020-01-18 00:28:21 +00:00
}