summaryrefslogtreecommitdiffstats
path: root/library/Businessprocess/Test/BaseTestCase.php
blob: 807905dbefb7cdabbf14c1cd901fa1dac122454f (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

namespace Icinga\Module\Businessprocess\Test;

use Icinga\Application\Config;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Icinga;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Module\Businessprocess\Web\FakeRequest;
use PHPUnit_Framework_TestCase;

abstract class BaseTestCase extends PHPUnit_Framework_TestCase
{
    /** @var ApplicationBootstrap */
    private static $app;

    /**
     * @inheritdoc
     */
    public function setUp()
    {
        $this->app();
        FakeRequest::setConfiguredBaseUrl('/icingaweb2/');
    }

    protected function emptyConfigSection()
    {
        return Config::module('businessprocess')->getSection('global');
    }

    /***
     * @return BpConfig
     */
    protected function makeLoop()
    {
        return $this->makeInstance()->loadFromString(
            'loop',
            "a = b\nb = c\nc = a\nd = a"
        );
    }

    /**
     * @return LegacyStorage
     */
    protected function makeInstance()
    {
        return new LegacyStorage($this->emptyConfigSection());
    }

    /**
     * @param null $subDir
     * @return string
     */
    protected function getTestsBaseDir($subDir = null)
    {
        $dir = dirname(dirname(dirname(__DIR__))) . '/test';
        if ($subDir === null) {
            return $dir;
        } else {
            return $dir . '/' . ltrim($subDir, '/');
        }
    }

    /**
     * @return ApplicationBootstrap
     */
    protected function app()
    {
        if (self::$app === null) {
            self::$app = Icinga::app();
        }

        return self::$app;
    }
}