summaryrefslogtreecommitdiff
path: root/tests/integration/TaskFileProcedureTest.php
blob: 60909ecdb95ea76f1678cc9b7565c9183998c8cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

require_once __DIR__.'/BaseProcedureTest.php';

class TaskFileProcedureTest extends BaseProcedureTest
{
    protected $projectName = 'My project to test task files';
    protected $fileId;

    public function testAll()
    {
        $this->assertCreateTeamProject();
        $this->assertCreateTask();
        $this->assertCreateTaskFile();
        $this->assertGetTaskFile();
        $this->assertDownloadTaskFile();
        $this->assertGetAllFiles();
        $this->assertRemoveTaskFile();
        $this->assertRemoveAllTaskFiles();
    }

    public function assertCreateTaskFile()
    {
        $this->fileId = $this->app->createTaskFile($this->projectId, $this->taskId, 'My file', base64_encode('plain text file'));
        $this->assertNotFalse($this->fileId);
    }

    public function assertGetTaskFile()
    {
        $file = $this->app->getTaskFile($this->fileId);
        $this->assertNotEmpty($file);
        $this->assertEquals('My file', $file['name']);
    }

    public function assertDownloadTaskFile()
    {
        $content = $this->app->downloadTaskFile($this->fileId);
        $this->assertNotEmpty($content);
        $this->assertEquals('plain text file', base64_decode($content));
    }

    public function assertGetAllFiles()
    {
        $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId));
        $this->assertCount(1, $files);
        $this->assertEquals('My file', $files[0]['name']);
    }

    public function assertRemoveTaskFile()
    {
        $this->assertTrue($this->app->removeTaskFile($this->fileId));

        $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId));
        $this->assertEmpty($files);
    }

    public function assertRemoveAllTaskFiles()
    {
        $this->assertCreateTaskFile();
        $this->assertCreateTaskFile();

        $this->assertTrue($this->app->removeAllTaskFiles($this->taskId));

        $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId));
        $this->assertEmpty($files);
    }
}