summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-06-13 15:47:48 -0400
committerFrederic Guillot <fred@kanboard.net>2015-06-13 15:47:48 -0400
commit0b7435b8827081341a331ecdd5546ac25121d87d (patch)
treee439735e077ceb0b4f77266b1f3e9fcd337e55e8 /tests
parent41610150238a67471d79caa5bcb2ace1dd4578d1 (diff)
API: new procedure 'removeAllFiles' and contract change for 'createFile'
Diffstat (limited to 'tests')
-rw-r--r--tests/functionals.sqlite.xml2
-rw-r--r--tests/functionals/ApiTest.php17
-rw-r--r--tests/units/FileTest.php163
-rw-r--r--tests/units/NotificationTest.php2
4 files changed, 179 insertions, 5 deletions
diff --git a/tests/functionals.sqlite.xml b/tests/functionals.sqlite.xml
index bf5d4117..0d011ac3 100644
--- a/tests/functionals.sqlite.xml
+++ b/tests/functionals.sqlite.xml
@@ -5,7 +5,7 @@
</testsuite>
</testsuites>
<php>
- <const name="API_URL" value="http://localhost:8000/jsonrpc.php" />
+ <const name="API_URL" value="http://127.0.0.1:8000/jsonrpc.php" />
<const name="API_KEY" value="19ffd9709d03ce50675c3a43d1c49c1ac207f4bc45f06c5b2701fbdf8929" />
<const name="DB_DRIVER" value="sqlite" />
<const name="DB_FILENAME" value="data/db.sqlite" />
diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php
index b5039759..ab64b6d0 100644
--- a/tests/functionals/ApiTest.php
+++ b/tests/functionals/ApiTest.php
@@ -937,7 +937,7 @@ class Api extends PHPUnit_Framework_TestCase
public function testCreateFile()
{
- $this->assertTrue($this->client->createFile(1, 1, 'My file', false, base64_encode('plain text file')));
+ $this->assertEquals(1, $this->client->createFile(1, 1, 'My file', base64_encode('plain text file')));
}
public function testGetAllFiles()
@@ -962,4 +962,19 @@ class Api extends PHPUnit_Framework_TestCase
$this->assertTrue($this->client->removeFile($file['id']));
$this->assertEmpty($this->client->getAllFiles(1));
}
+
+ public function testRemoveAllFiles()
+ {
+ $this->assertEquals(1, $this->client->createFile(1, 1, 'My file 1', base64_encode('plain text file')));
+ $this->assertEquals(2, $this->client->createFile(1, 1, 'My file 2', base64_encode('plain text file')));
+
+ $files = $this->client->getAllFiles(array('task_id' => 1));
+ $this->assertNotEmpty($files);
+ $this->assertCount(2, $files);
+
+ $this->assertTrue($this->client->removeAllFiles(array('task_id' => 1)));
+
+ $files = $this->client->getAllFiles(array('task_id' => 1));
+ $this->assertEmpty($files);
+ }
} \ No newline at end of file
diff --git a/tests/units/FileTest.php b/tests/units/FileTest.php
index 5e882fdb..4ea7f386 100644
--- a/tests/units/FileTest.php
+++ b/tests/units/FileTest.php
@@ -9,6 +9,36 @@ use Model\Project;
class FileTest extends Base
{
+ public function testCreation()
+ {
+ $p = new Project($this->container);
+ $f = new File($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->assertEquals(1, $f->create(1, 'test', '/tmp/foo', 10));
+
+ $file = $f->getById(1);
+ $this->assertNotEmpty($file);
+ $this->assertEquals('test', $file['name']);
+ $this->assertEquals('/tmp/foo', $file['path']);
+ $this->assertEquals(0, $file['is_image']);
+ $this->assertEquals(1, $file['task_id']);
+ $this->assertEquals(time(), $file['date'], '', 2);
+ $this->assertEquals(0, $file['user_id']);
+ $this->assertEquals(10, $file['size']);
+
+ $this->assertEquals(2, $f->create(1, 'test2.png', '/tmp/foobar', 10));
+
+ $file = $f->getById(2);
+ $this->assertNotEmpty($file);
+ $this->assertEquals('test2.png', $file['name']);
+ $this->assertEquals('/tmp/foobar', $file['path']);
+ $this->assertEquals(1, $file['is_image']);
+ }
+
public function testCreationFileNameTooLong()
{
$p = new Project($this->container);
@@ -18,8 +48,8 @@ class FileTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
- $this->assertTrue($f->create(1, 'test', '/tmp/foo', false, 10));
- $this->assertTrue($f->create(1, str_repeat('a', 1000), '/tmp/foo', false, 10));
+ $this->assertNotFalse($f->create(1, 'test', '/tmp/foo', 10));
+ $this->assertNotFalse($f->create(1, str_repeat('a', 1000), '/tmp/foo', 10));
$files = $f->getAll(1);
$this->assertNotEmpty($files);
@@ -28,4 +58,133 @@ class FileTest extends Base
$this->assertEquals(str_repeat('a', 255), $files[0]['name']);
$this->assertEquals('test', $files[1]['name']);
}
+
+ public function testIsImage()
+ {
+ $f = new File($this->container);
+
+ $this->assertTrue($f->isImage('test.png'));
+ $this->assertTrue($f->isImage('test.jpeg'));
+ $this->assertTrue($f->isImage('test.gif'));
+ $this->assertTrue($f->isImage('test.jpg'));
+ $this->assertTrue($f->isImage('test.JPG'));
+
+ $this->assertFalse($f->isImage('test.bmp'));
+ $this->assertFalse($f->isImage('test'));
+ $this->assertFalse($f->isImage('test.pdf'));
+ }
+
+ public function testGeneratePath()
+ {
+ $f = new File($this->container);
+
+ $this->assertStringStartsWith('12/34/', $f->generatePath(12, 34, 'test.png'));
+ $this->assertNotEquals($f->generatePath(12, 34, 'test1.png'), $f->generatePath(12, 34, 'test2.png'));
+ }
+
+ public function testUploadScreenshot()
+ {
+ $p = new Project($this->container);
+ $f = new File($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->assertEquals(1, $f->uploadScreenshot(1, 1, base64_encode('image data')));
+
+ $file = $f->getById(1);
+ $this->assertNotEmpty($file);
+ $this->assertStringStartsWith('Screenshot taken ', $file['name']);
+ $this->assertStringStartsWith('1/1/', $file['path']);
+ $this->assertEquals(1, $file['is_image']);
+ $this->assertEquals(1, $file['task_id']);
+ $this->assertEquals(time(), $file['date'], '', 2);
+ $this->assertEquals(0, $file['user_id']);
+ $this->assertEquals(10, $file['size']);
+ }
+
+ public function testUploadFileContent()
+ {
+ $p = new Project($this->container);
+ $f = new File($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->assertEquals(1, $f->uploadContent(1, 1, 'my file.pdf', base64_encode('file data')));
+
+ $file = $f->getById(1);
+ $this->assertNotEmpty($file);
+ $this->assertEquals('my file.pdf', $file['name']);
+ $this->assertStringStartsWith('1/1/', $file['path']);
+ $this->assertEquals(0, $file['is_image']);
+ $this->assertEquals(1, $file['task_id']);
+ $this->assertEquals(time(), $file['date'], '', 2);
+ $this->assertEquals(0, $file['user_id']);
+ $this->assertEquals(9, $file['size']);
+ }
+
+ public function testGetAll()
+ {
+ $p = new Project($this->container);
+ $f = new File($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10));
+ $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10));
+ $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10));
+ $this->assertEquals(4, $f->create(1, 'C.JPG', '/tmp/foo', 10));
+
+ $files = $f->getAll(1);
+ $this->assertNotEmpty($files);
+ $this->assertCount(4, $files);
+ $this->assertEquals('A.png', $files[0]['name']);
+ $this->assertEquals('B.pdf', $files[1]['name']);
+ $this->assertEquals('C.JPG', $files[2]['name']);
+ $this->assertEquals('D.doc', $files[3]['name']);
+
+ $files = $f->getAllImages(1);
+ $this->assertNotEmpty($files);
+ $this->assertCount(2, $files);
+ $this->assertEquals('A.png', $files[0]['name']);
+ $this->assertEquals('C.JPG', $files[1]['name']);
+
+ $files = $f->getAllDocuments(1);
+ $this->assertNotEmpty($files);
+ $this->assertCount(2, $files);
+ $this->assertEquals('B.pdf', $files[0]['name']);
+ $this->assertEquals('D.doc', $files[1]['name']);
+ }
+
+ public function testRemove()
+ {
+ $p = new Project($this->container);
+ $f = new File($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10));
+ $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10));
+ $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10));
+
+ $this->assertTrue($f->remove(2));
+
+ $files = $f->getAll(1);
+ $this->assertNotEmpty($files);
+ $this->assertCount(2, $files);
+ $this->assertEquals('B.pdf', $files[0]['name']);
+ $this->assertEquals('D.doc', $files[1]['name']);
+
+ $this->assertTrue($f->removeAll(1));
+
+ $files = $f->getAll(1);
+ $this->assertEmpty($files);
+ }
}
diff --git a/tests/units/NotificationTest.php b/tests/units/NotificationTest.php
index 5a7a782c..f86d02e1 100644
--- a/tests/units/NotificationTest.php
+++ b/tests/units/NotificationTest.php
@@ -247,7 +247,7 @@ class NotificationTest extends Base
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
$this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
$this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
- $this->assertEquals(1, $f->create(1, 'test', 'blah', false, 123));
+ $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
$task = $tf->getDetails(1);
$subtask = $s->getById(1, true);