Completed
Push — feature/EVO-7278-tracking-info... ( a5fe2c...35e86f )
by
unknown
172:49 queued 167:19
created

ActivityManagerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 72
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testGetConfigValue() 0 19 2
A testGetHeader() 0 23 1
1
<?php
2
/**
3
 * Basic functional test for ActivityManager
4
 */
5
namespace Graviton\AuditTrackingBundle\Tests\Manager;
6
7
use Graviton\AuditTrackingBundle\Manager\ActivityManager;
8
use Graviton\TestBundle\Test\RestTestCase;
9
10
/**
11
 * @category GravitonCoreBundle
12
 * @package  Graviton
13
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
14
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
15
 * @link     http://swisscom.ch
16
 */
17
class ActivityManagerTest extends RestTestCase
18
{
19
    /** @var ActivityManager */
20
    private $activityManager;
21
22
    /**
23
     * Ensure a clean Db for test
24
     *
25
     * @return void
26
     */
27
    public function setUp()
28
    {
29
        $this->activityManager = $this->getContainer()->get('graviton.audit.manager.activity');
30
    }
31
32
    /**
33
     * Verifies the correct behavior of:
34
     * setConfiguration()
35
     * getConfigValue()
36
     *
37
     * @return void
38
     */
39
    public function testGetConfigValue()
40
    {
41
        $keys = [
42
            'bool_true' => true,
43
            'bool_false' => false,
44
            'int_1' => 1,
45
            'int' => 14,
46
            'string_a' => "simple string",
47
            'array_a' => ['item1', 'item2']
48
        ];
49
50
        $this->activityManager->setConfiguration($keys);
51
52
        foreach ($keys as $key => $val) {
53
            $type = explode('_', $key);
54
            $value = $this->activityManager->getConfigValue($key, $type[0]);
55
            $this->assertEquals($value, $val, 'Key '.$key.' was not handled as expected');
56
        }
57
    }
58
59
    /**
60
     * Verifies the correct behavior of:
61
     * extractHeaderLink()
62
     *
63
     * @return void
64
     */
65
    public function testGetHeader()
66
    {
67
        $method = $this->getPrivateClassMethod(get_class($this->activityManager), 'extractHeaderLink');
68
69
        // Double links
70
        $args = ['<http://localhost/core/app/bap>; rel="self",<http://localhost/core/app/bap/>; rel="next"', 'self'];
71
        $result = $method->invokeArgs($this->activityManager, $args);
72
        $this->assertEquals('http://localhost/core/app/bap', $result);
73
74
        // Simple link
75
        $args = ['<http://localhost/core/app/bap/>; rel="self"', 'self'];
76
        $result = $method->invokeArgs($this->activityManager, $args);
77
        $this->assertEquals('http://localhost/core/app/bap/', $result);
78
79
        // Triple links
80
        $args = [
81
            '<http://localhost/core/app/?limit(1%2C1)>; rel="next",'.
82
            '<http://localhost/core/app/?limit(1%2C2)>; rel="last",'.
83
            '<http://localhost/core/app/?limit(1)>; rel="self"',
84
            'self'];
85
        $result = $method->invokeArgs($this->activityManager, $args);
86
        $this->assertEquals('http://localhost/core/app/?limit(1)', $result);
87
    }
88
}
89