Completed
Push — feature/EVO-10415-Analytics-wi... ( e2b3ad )
by
unknown
12:30
created

DefaultControllerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
/**
3
 * Test cases for basic coverage for Analytics Bundle
4
 */
5
namespace Graviton\AnalyticsBundle\Tests\Controller;
6
7
use Symfony\Component\Routing\Router;
8
9
use Graviton\TestBundle\Test\RestTestCase;
10
11
/**
12
 * Basic functional test for Analytics
13
 *
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class DefaultControllerTest extends RestTestCase
19
{
20
    /** @var Router */
21
    private $router;
22
23
    /**
24
     * Initial setup
25
     * @return void
26
     */
27
    public function setUp()
28
    {
29
        $this->router = $this->getContainer()->get('router');
30
31
        $this->loadFixtures(
32
            array(
33
                'Graviton\CoreBundle\DataFixtures\MongoDB\LoadAppData',
34
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadLanguageData',
35
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadMultiLanguageData',
36
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadTranslatableData',
37
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadTranslatablesApp'
38
            ),
39
            null,
40
            'doctrine_mongodb'
41
        );
42
    }
43
44
    /**
45
     * Testing basic functionality
46
     * @return void
47
     */
48
    public function testIndex()
49
    {
50
        $client = static::createClient();
51
52
        $client->request('GET', $this->router->generate('graviton_analytics_homepage'));
53
54
        $content = $client->getResponse()->getContent();
55
        $service = json_decode($content);
56
57
        $this->assertEquals(1, count($service->services));
58
59
        // Let's get information from the schema
60
        $client->request('GET', $service->services[0]->profile);
61
        $content = $client->getResponse()->getContent();
62
        $schema = json_decode($content);
63
64
        // Check schema
65
        $sampleSchema = json_decode(
66
            '{
67
                    "title": "Application usage",
68
                    "description": "Data use for application access",
69
                    "type": "object",
70
                    "representation": "pie",
71
                    "properties": {
72
                      "id": {
73
                        "title": "ID",
74
                        "description": "Unique identifier",
75
                        "type": "string"
76
                      },
77
                      "count": {
78
                        "title": "count",
79
                        "description": "Sum of result",
80
                        "type": "integer"
81
                      }
82
                    }
83
                  }'
84
        );
85
        $this->assertEquals($sampleSchema, $schema);
86
87
        // Let's get information from the count
88
        $client->request('GET', $service->services[0]->{'$ref'});
89
        $content = $client->getResponse()->getContent();
90
        $data = json_decode($content);
91
92
        // Counter data result of aggregate
93
        $sampleData = json_decode('{"_id":"app-count","count":2}');
94
        $this->assertEquals($sampleData, $data);
95
    }
96
}
97