c3lf-system-3/tests/ItemTest.php

178 lines
6.7 KiB
PHP
Raw Normal View History

2020-01-18 14:41:42 +00:00
<?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']);
2020-01-18 19:53:46 +00:00
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'1']);
2020-01-18 14:41:42 +00:00
$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']);
2020-01-18 19:53:46 +00:00
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'1']);
2020-01-18 14:41:42 +00:00
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']);
2020-01-18 19:53:46 +00:00
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'1']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'2']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'3']);
2020-01-18 14:41:42 +00:00
$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']);
2020-01-18 19:53:46 +00:00
$this->post('/1/EVENT/item',['cid'=>$box->cid, 'description'=>'1']);
2020-01-18 14:41:42 +00:00
$response = $this->response->getOriginalContent();
$this->assertResponseStatus(201);
$this->assertEquals(1, $response['item_uid']);
$this->assertEquals('1', $response['description']);
2020-01-18 19:53:46 +00:00
$this->assertEquals($box->name, $response['box']);
2020-01-18 14:41:42 +00:00
$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']);
2020-01-18 19:53:46 +00:00
$this->assertEquals($box->name, $items[0]['box']);
2020-01-18 14:41:42 +00:00
$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']);
2020-01-18 19:53:46 +00:00
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'1']);
2020-01-18 14:41:42 +00:00
$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']);
2020-01-18 19:53:46 +00:00
$this->assertEquals($box->name, $response['box']);
2020-01-18 14:41:42 +00:00
$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']);
2020-01-18 19:53:46 +00:00
$this->assertEquals($box->name, $items[0]['box']);
2020-01-18 14:41:42 +00:00
$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']);
2020-01-18 19:53:46 +00:00
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'1']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'2']);
2020-01-18 14:41:42 +00:00
$this->assertEquals(2, count(Item::all()));
$this->delete('/1/EVENT/item/'.$item->item_uid);
$this->assertResponseOk();
$this->assertEquals(1, count(Item::all()));
}
2020-01-18 19:53:46 +00:00
public function testDeleteItem2(){
$event = Event::create(['slug'=>'EVENT','name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
$item1 = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'1']);
$item2 = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'2']);
$this->assertEquals(2, count(Item::all()));
$this->delete('/1/EVENT/item/'.$item1->item_uid);
$this->assertResponseOk();
$this->assertEquals(1, count(Item::all()));
$item3 = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'3']);
$this->assertEquals(3, $item3['item_uid']);
$this->assertEquals(2, count(Item::all()));
$this->delete('/1/EVENT/item/'.$item2->item_uid);
$this->assertResponseOk();
$this->assertEquals(1, count(Item::all()));
}
2020-01-18 14:41:42 +00:00
}