summaryrefslogtreecommitdiff
path: root/tests/integration/CategoryProcedureTest.php
blob: 2f5294babcba2e45757227380309b1753eed6ad0 (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
68
69
70
71
72
73
74
75
76
<?php

require_once __DIR__.'/BaseProcedureTest.php';

class CategoryProcedureTest extends BaseProcedureTest
{
    protected $projectName = 'My project to test categories';
    private $categoryId = 0;

    public function testAll()
    {
        $this->assertCreateTeamProject();
        $this->assertCreateCategory();
        $this->assertThatCategoriesAreUnique();
        $this->assertGetCategory();
        $this->assertGetAllCategories();
        $this->assertCategoryUpdate();
        $this->assertRemoveCategory();
    }

    public function assertCreateCategory()
    {
        $this->categoryId = $this->app->createCategory(array(
            'name' => 'Category',
            'project_id' => $this->projectId,
        ));

        $this->assertNotFalse($this->categoryId);
    }

    public function assertThatCategoriesAreUnique()
    {
        $this->assertFalse($this->app->execute('createCategory', array(
            'name' => 'Category',
            'project_id' => $this->projectId,
        )));
    }

    public function assertGetCategory()
    {
        $category = $this->app->getCategory($this->categoryId);

        $this->assertInternalType('array', $category);
        $this->assertEquals($this->categoryId, $category['id']);
        $this->assertEquals('Category', $category['name']);
        $this->assertEquals($this->projectId, $category['project_id']);
    }

    public function assertGetAllCategories()
    {
        $categories = $this->app->getAllCategories($this->projectId);

        $this->assertCount(1, $categories);
        $this->assertEquals($this->categoryId, $categories[0]['id']);
        $this->assertEquals('Category', $categories[0]['name']);
        $this->assertEquals($this->projectId, $categories[0]['project_id']);
    }

    public function assertCategoryUpdate()
    {
        $this->assertTrue($this->app->execute('updateCategory', array(
            'id' => $this->categoryId,
            'name' => 'Renamed category',
        )));

        $category = $this->app->getCategory($this->categoryId);
        $this->assertEquals('Renamed category', $category['name']);
    }

    public function assertRemoveCategory()
    {
        $this->assertTrue($this->app->removeCategory($this->categoryId));
        $this->assertFalse($this->app->removeCategory($this->categoryId));
        $this->assertFalse($this->app->removeCategory(1111));
    }
}