c3lf-system-3/tests/ItemTest.php

174 lines
6.2 KiB
PHP
Raw Permalink 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-19 00:07:08 +00:00
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, '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));
2020-01-18 20:37:02 +00:00
$this->assertEquals(1, $response[0]['uid']);
2020-01-18 14:41:42 +00:00
$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-19 00:07:08 +00:00
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'1']);
$file = File::create(['iid'=>$item->iid, 'data'=>",".base64_encode("foo")]);
2020-01-18 14:41:42 +00:00
$this->get('/1/EVENT/items');
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
$this->assertEquals(1, count($response));
2020-01-18 20:37:02 +00:00
$this->assertEquals(1, $response[0]['uid']);
2020-01-18 14:41:42 +00:00
$this->assertEquals('1', $response[0]['description']);
$this->assertEquals($box->name, $response[0]['box']);
$this->assertEquals($box->cid, $response[0]['cid']);
2020-01-19 00:07:08 +00:00
$this->assertEquals($file->hash, $response[0]['file']);
2020-01-18 14:41:42 +00:00
}
public function testmultiMembers()
{
$event = Event::create(['slug'=>'EVENT','name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
2020-01-19 00:07:08 +00:00
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'1']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'2']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, '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);
2020-01-18 20:37:02 +00:00
$this->assertEquals(1, $response['uid']);
2020-01-18 14:41:42 +00:00
$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));
2020-01-18 20:37:02 +00:00
$this->assertEquals(1, $items[0]['uid']);
2020-01-18 14:41:42 +00:00
$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-19 00:07:08 +00:00
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'1']);
2020-01-18 14:41:42 +00:00
2020-01-18 20:37:02 +00:00
$this->assertEquals(1, $item['uid']);
2020-01-18 14:41:42 +00:00
$this->assertEquals('1', $item['description']);
$this->assertEquals($box->cid, $item['cid']);
2020-01-18 20:37:02 +00:00
$this->put('/1/EVENT/item/'.$item->uid,['description'=>'2']);
2020-01-18 14:41:42 +00:00
$response = $this->response->getOriginalContent();
$this->assertResponseOk();
2020-01-18 20:37:02 +00:00
$this->assertEquals(1, $response['uid']);
2020-01-18 14:41:42 +00:00
$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));
2020-01-18 20:37:02 +00:00
$this->assertEquals(1, $items[0]['uid']);
2020-01-18 14:41:42 +00:00
$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-19 00:07:08 +00:00
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'1']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'2']);
2020-01-18 14:41:42 +00:00
$this->assertEquals(2, count(Item::all()));
2020-01-18 20:37:02 +00:00
$this->delete('/1/EVENT/item/'.$item->uid);
2020-01-18 14:41:42 +00:00
$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']);
2020-01-19 00:07:08 +00:00
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'1']);
$item2 = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'2']);
2020-01-18 19:53:46 +00:00
$this->assertEquals(2, count(Item::all()));
2020-01-18 20:55:27 +00:00
$this->delete('/1/EVENT/item/'.$item2->uid);
2020-01-18 19:53:46 +00:00
$this->assertResponseOk();
$this->assertEquals(1, count(Item::all()));
2020-01-19 00:07:08 +00:00
$item3 = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'3']);
2020-01-18 19:53:46 +00:00
2020-01-18 20:37:02 +00:00
$this->assertEquals(3, $item3['uid']);
2020-01-18 19:53:46 +00:00
$this->assertEquals(2, count(Item::all()));
}
2020-01-18 14:41:42 +00:00
}