c3lf-system-3/tests/FileTest.php

63 lines
2.4 KiB
PHP

<?php
use App\Container;
use App\Event;
use App\Item;
use App\File;
class FileTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testListFiles(){
$item = File::create(['iid'=>1,'data'=>",".base64_encode("foo")]);
$this->get( '/1/files');
$this->assertResponseOk();
$this->assertEquals(1, json_decode($this->response->getContent(),true)[0]['iid']);
$this->assertEquals($item->hash, json_decode($this->response->getContent(),true)[0]['hash']);
$this->assertEquals(32, strlen(json_decode($this->response->getContent(),true)[0]['hash']));
}
public function testOneFile(){
$item = File::create(['iid'=>1,'data'=>",".base64_encode("foo")]);
$this->get( '/1/file/'.$item->hash);
$this->assertResponseOk();
$this->assertEquals(1, json_decode($this->response->getContent(),true)['iid']);
$this->assertEquals($item->hash, json_decode($this->response->getContent(),true)['hash']);
$this->assertEquals(32, strlen(json_decode($this->response->getContent(),true)['hash']));
}
public function testCreateFile(){
$event = Event::create(['slug'=>'EVENT', 'name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'1']);
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'2']);
$this->post( '/1/file',['data'=>",".base64_encode("foo"), 'iid'=>$item->iid]);
$this->assertResponseStatus(201);
$this->assertEquals($item->iid, json_decode($this->response->getContent(),true)['iid']);
$this->assertEquals(32, strlen(json_decode($this->response->getContent(),true)['hash']));
}
public function testDeleteFile(){
$event = Event::create(['slug'=>'EVENT', 'name'=>'Event']);
$box = Container::create(['name'=>'BOX']);
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'description'=>'1']);
File::create(['iid'=>$item->iid,'data'=>",".base64_encode("foo")]);
$file = File::create(['iid'=>$item->iid,'data'=>",".base64_encode("bar")]);
$this->assertEquals(2, count(File::all()));
$this->delete( '/1/file/'.$file->hash);
$this->assertResponseOk();
$this->assertEquals(1, count(Item::all()));
}
}