c3lf-system-3/tests/ItemTest.php
2020-01-18 15:41:42 +01:00

152 lines
5.9 KiB
PHP

<?php
use App\Container;
use App\Event;
use App\Item;
use App\File;
class ItemTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testEmpty()
{
$event = Event::create(['slug'=>'EVENT','name'=>'Event']);
$this->get('/1/EVENT/items');
$this->assertResponseOk();
$this->assertEquals('[]',$this->response->getContent());
}
public function testMembers()
{
$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']);
$this->get('/1/EVENT/items');
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(1, count($response));
$this->assertEquals(1, $response[0]['item_uid']);
$this->assertEquals('1', $response[0]['description']);
$this->assertEquals($box->name, $response[0]['box']);
$this->assertEquals($box->cid, $response[0]['cid']);
$this->assertEquals(null, $response[0]['file']);
}
public function testMembersWithFile()
{
$event = Event::create(['slug'=>'EVENT','name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'item_uid'=>1, 'wann'=>'', 'wo'=>'','description'=>'1']);
File::create(['iid'=>$item->iid, 'hash'=>'filename']);
$this->get('/1/EVENT/items');
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(1, count($response));
$this->assertEquals(1, $response[0]['item_uid']);
$this->assertEquals('1', $response[0]['description']);
$this->assertEquals($box->name, $response[0]['box']);
$this->assertEquals($box->cid, $response[0]['cid']);
$this->assertEquals('filename', $response[0]['file']);
}
public function testmultiMembers()
{
$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']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'item_uid'=>3, 'wann'=>'', 'wo'=>'','description'=>'3']);
$this->get('/1/EVENT/items');
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(3, count($response));
}
public function testCreateItem(){
Event::create(['slug'=>'EVENT','name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
$this->post('/1/EVENT/item',['cid'=>$box->cid, 'wann'=>'', 'description'=>'1']);
$response = $this->response->getOriginalContent();
$this->assertResponseStatus(201);
$this->assertEquals(1, $response['item_uid']);
$this->assertEquals('1', $response['description']);
//$this->assertEquals($box->name, $response['box']);
$this->assertEquals($box->cid, $response['cid']);
//$this->assertEquals('filename', $response['file']);
$items = Item::all();
$this->assertEquals(1, count($items));
$this->assertEquals(1, $items[0]['item_uid']);
$this->assertEquals('1', $items[0]['description']);
//$this->assertEquals($box->name, $items[0]['box']);
$this->assertEquals($box->cid, $items[0]['cid']);
//$this->assertEquals('filename', $items[0]['file']);
}
public function testCreateItemFail(){
Event::create(['slug'=>'EVENT','name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
$this->post('/1/EVENT/item',[]);
$response = $this->response->getOriginalContent();
$this->assertResponseStatus(500);
}
public function testUpdateItem(){
$event = Event::create(['slug'=>'EVENT','name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'item_uid'=>1, 'wann'=>'', 'wo'=>'','description'=>'1']);
$this->assertEquals(1, $item['item_uid']);
$this->assertEquals('1', $item['description']);
$this->assertEquals($box->cid, $item['cid']);
$this->put('/1/EVENT/item/'.$item->item_uid,['description'=>'2']);
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(1, $response['item_uid']);
$this->assertEquals('2', $response['description']);
//$this->assertEquals($box->name, $response['box']);
$this->assertEquals($box->cid, $response['cid']);
//$this->assertEquals('filename', $response['file']);
$items = Item::all();
$this->assertEquals(1, count($items));
$this->assertEquals(1, $items[0]['item_uid']);
$this->assertEquals('2', $items[0]['description']);
//$this->assertEquals($box->name, $items[0]['box']);
$this->assertEquals($box->cid, $items[0]['cid']);
//$this->assertEquals('filename', $items[0]['file']);
}
public function testDeleteItem(){
$event = Event::create(['slug'=>'EVENT','name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
$item = 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->assertEquals(2, count(Item::all()));
$this->delete('/1/EVENT/item/'.$item->item_uid);
$this->assertResponseOk();
$this->assertEquals(1, count(Item::all()));
}
}