Completed
Pull Request — develop (#579)
by
unknown
15:32 queued 10:40
created

testCustomerCreateDateFilteringIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47
Code Lines 17

Duplication

Lines 47
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 47
loc 47
rs 9.0303
cc 1
eloc 17
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
                'GravitonDyn\CustomerBundle\DataFixtures\MongoDB\LoadCustomerData',
39
            ),
40
            null,
41
            'doctrine_mongodb'
42
        );
43
    }
44
45
    /**
46
     * Testing basic functionality
47
     * @return void
48
     */
49 View Code Duplication
    public function testIndex()
50
    {
51
        $client = static::createClient();
52
53
        $client->request('GET', $this->router->generate('graviton_analytics_homepage'));
54
55
        $content = $client->getResponse()->getContent();
56
        $service = json_decode($content);
57
58
        $this->assertEquals(3, count($service->services));
59
60
        // Let's get information from the schema
61
        $client->request('GET', $service->services[0]->profile);
62
        $content = $client->getResponse()->getContent();
63
        $schema = json_decode($content);
64
65
        // Check schema
66
        $sampleSchema = json_decode(
67
            '{
68
                    "title": "Application usage",
69
                    "description": "Data use for application access",
70
                    "type": "object",
71
                    "representation": "pie",
72
                    "properties": {
73
                      "id": {
74
                        "title": "ID",
75
                        "description": "Unique identifier",
76
                        "type": "string"
77
                      },
78
                      "count": {
79
                        "title": "count",
80
                        "description": "Sum of result",
81
                        "type": "integer"
82
                      }
83
                    }
84
                  }'
85
        );
86
        $this->assertEquals($sampleSchema, $schema);
87
88
        // Let's get information from the count
89
        $client->request('GET', $service->services[0]->{'$ref'});
90
        $content = $client->getResponse()->getContent();
91
        $data = json_decode($content);
92
93
        // Counter data result of aggregate
94
        $sampleData = json_decode('{"_id":"app-count","count":2}');
95
        $this->assertEquals($sampleData, $data);
96
    }
97
98
    /**
99
     * Testing basic functionality
100
     * @return void
101
     */
102
    public function testApp2Index()
103
    {
104
        $client = static::createClient();
105
106
        $client->request('GET', $this->router->generate('graviton_analytics_homepage'));
107
108
        $content = $client->getResponse()->getContent();
109
        $service = json_decode($content);
110
111
        // Let's get information from the count
112
        $client->request('GET', $service->services[1]->{'$ref'});
113
        $content = $client->getResponse()->getContent();
114
        $data = json_decode($content);
115
116
        // Counter data result of aggregate
117
        $sampleData = json_decode('{"_id":"app-count-2","count":1}');
118
        $this->assertEquals($sampleData, $data);
119
    }
120
121
    /**
122
     * Testing basic functionality
123
     * @return void
124
     */
125 View Code Duplication
    public function testCustomerCreateDateFilteringIndex()
126
    {
127
        $client = static::createClient();
128
129
        $client->request('GET', $this->router->generate('graviton_analytics_homepage'));
130
131
        $content = $client->getResponse()->getContent();
132
        $service = json_decode($content);
133
134
        // Let's get information from the count
135
        $client->request('GET', $service->services[2]->{'$ref'});
136
        $content = $client->getResponse()->getContent();
137
        $data = json_decode($content);
138
139
        // Counter data result of aggregate
140
        $sampleData = json_decode(
141
            '[
142
              {
143
                "_id": "100",
144
                "customerNumber": 1100,
145
                "name": "Acme Corps.",
146
                "created_year": 2014,
147
                "created_month": 7
148
              }
149
            ]'
150
        );
151
        $this->assertEquals($sampleData, $data);
152
153
        // Let's get information from the count, but cached version
154
        $client->request('GET', $service->services[2]->{'$ref'});
155
        $content = $client->getResponse()->getContent();
156
        $data = json_decode($content);
157
158
        // Counter data result of aggregate
159
        $sampleData = json_decode(
160
            '[
161
              {
162
                "_id": "100",
163
                "customerNumber": 1100,
164
                "name": "Acme Corps.",
165
                "created_year": 2014,
166
                "created_month": 7
167
              }
168
            ]'
169
        );
170
        $this->assertEquals($sampleData, $data);
171
    }
172
}
173