summaryrefslogtreecommitdiff
path: root/tests/integration/Base.php
blob: 6facd9ce5b1aecc7a2d678202abd9043c45a7cf1 (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
<?php

require_once __DIR__.'/../../vendor/autoload.php';

abstract class Base extends PHPUnit_Framework_TestCase
{
    protected $app = null;
    protected $admin = null;
    protected $user = null;

    public static function setUpBeforeClass()
    {
        if (DB_DRIVER === 'sqlite') {
            @unlink(DB_FILENAME);
        } elseif (DB_DRIVER === 'mysql') {
            $pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
            $pdo->exec('DROP DATABASE '.DB_NAME);
            $pdo->exec('CREATE DATABASE '.DB_NAME);
            $pdo = null;
        } elseif (DB_DRIVER === 'postgres') {
            $pdo = new PDO('pgsql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
            $pdo->exec('DROP DATABASE '.DB_NAME);
            $pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME);
            $pdo = null;
        }

        $service = new Kanboard\ServiceProvider\DatabaseProvider;

        $db = $service->getInstance();
        $db->table('settings')->eq('option', 'api_token')->update(array('value' => API_KEY));
        $db->closeConnection();
    }

    public function setUp()
    {
        $this->app = new JsonRPC\Client(API_URL);
        $this->app->authentication('jsonrpc', API_KEY);
        $this->app->debug = true;

        $this->admin = new JsonRPC\Client(API_URL);
        $this->admin->authentication('admin', 'admin');
        // $this->admin->debug = true;

        $this->user = new JsonRPC\Client(API_URL);
        $this->user->authentication('user', 'password');
        // $this->user->debug = true;
    }

    protected function getProjectId()
    {
        $projects = $this->app->getAllProjects();
        $this->assertNotEmpty($projects);
        return $projects[0]['id'];
    }

    protected function getGroupId()
    {
        $groups = $this->app->getAllGroups();
        $this->assertNotEmpty($groups);
        return $groups[0]['id'];
    }
}