Completed
Push — master ( 664783...554f9d )
by
unknown
15:59
created

testCustomerCreateDateFilteringIndex()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 14

Duplication

Lines 42
Ratio 100 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
dl 42
loc 42
rs 8.8571
c 3
b 1
f 1
cc 1
eloc 14
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\HttpFoundation\Response;
8
use Symfony\Component\Routing\Router;
9
10
use Graviton\TestBundle\Test\RestTestCase;
11
12
/**
13
 * Basic functional test for Analytics
14
 *
15
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
16
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
17
 * @link     http://swisscom.ch
18
 */
19
class DefaultControllerTest extends RestTestCase
20
{
21
    /** @var Router */
22
    private $router;
23
24
    /**
25
     * Initial setup
26
     * @return void
27
     */
28
    public function setUp()
29
    {
30
        $this->router = $this->getContainer()->get('router');
31
32
        $this->loadFixtures(
33
            array(
34
                'Graviton\CoreBundle\DataFixtures\MongoDB\LoadAppData',
35
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadLanguageData',
36
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadMultiLanguageData',
37
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadTranslatableData',
38
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadTranslatablesApp',
39
                'GravitonDyn\CustomerBundle\DataFixtures\MongoDB\LoadCustomerData',
40
            ),
41
            null,
42
            'doctrine_mongodb'
43
        );
44
    }
45
46
    /**
47
     * test options request
48
     * @return void
49
     */
50 View Code Duplication
    public function testOptions()
51
    {
52
        $client = static::createRestClient();
53
        $client->request('OPTIONS', '/analytics/schema/app');
54
        $this->assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode());
55
        $this->assertEquals('GET, OPTIONS', $client->getResponse()->headers->get('Access-Control-Allow-Methods'));
56
        $this->assertEmpty($client->getResults());
57
    }
58
59
    /**
60
     * Testing basic functionality
61
     * @return void
62
     */
63 View Code Duplication
    public function testIndex()
64
    {
65
        $client = static::createClient();
66
67
        // Let's get information from the schema
68
        $client->request('GET', '/analytics/schema/app');
69
        $content = $client->getResponse()->getContent();
70
        $schema = json_decode($content);
71
72
        // Check schema
73
        $sampleSchema = json_decode(
74
            '{
75
                    "title": "Application usage",
76
                    "description": "Data use for application access",
77
                    "type": "object",
78
                    "representation": "pie",
79
                    "properties": {
80
                      "id": {
81
                        "title": "ID",
82
                        "description": "Unique identifier",
83
                        "type": "string"
84
                      },
85
                      "count": {
86
                        "title": "count",
87
                        "description": "Sum of result",
88
                        "type": "integer"
89
                      }
90
                    }
91
                  }'
92
        );
93
        $this->assertEquals($sampleSchema, $schema);
94
95
        // Let's get information from the count
96
        $client->request('GET', '/analytics/app');
97
        $content = $client->getResponse()->getContent();
98
        $data = json_decode($content);
99
100
        // Counter data result of aggregate
101
        $sampleData = json_decode('{"_id":"app-count","count":2}');
102
        $this->assertEquals($sampleData, $data);
103
    }
104
105
    /**
106
     * Testing basic functionality
107
     * @return void
108
     */
109
    public function testApp2Index()
110
    {
111
        $client = static::createClient();
112
113
        // Let's get information from the count
114
        $client->request('GET', '/analytics/app2');
115
        $content = $client->getResponse()->getContent();
116
        $data = json_decode($content);
117
118
        // Counter data result of aggregate
119
        $sampleData = json_decode('{"_id":"app-count-2","count":1}');
120
        $this->assertEquals($sampleData, $data);
121
    }
122
123
    /**
124
     * Testing basic functionality
125
     * @return void
126
     */
127 View Code Duplication
    public function testCustomerCreateDateFilteringIndex()
128
    {
129
        $client = static::createClient();
130
131
        // Let's get information from the count
132
        $client->request('GET', '/analytics/customer-created-by-date');
133
        $content = $client->getResponse()->getContent();
134
        $data = json_decode($content);
135
136
        // Counter data result of aggregate
137
        $sampleData = json_decode(
138
            '[
139
              {
140
                "_id": "100",
141
                "customerNumber": 1100,
142
                "name": "Acme Corps.",
143
                "created_year": 2014,
144
                "created_month": 7
145
              }
146
            ]'
147
        );
148
        $this->assertEquals($sampleData, $data);
149
150
        // Let's get information from the count, but cached version
151
        $client->request('GET', '/analytics/customer-created-by-date');
152
        $content = $client->getResponse()->getContent();
153
        $data = json_decode($content);
154
155
        // Counter data result of aggregate
156
        $sampleData = json_decode(
157
            '[
158
              {
159
                "_id": "100",
160
                "customerNumber": 1100,
161
                "name": "Acme Corps.",
162
                "created_year": 2014,
163
                "created_month": 7
164
              }
165
            ]'
166
        );
167
        $this->assertEquals($sampleData, $data);
168
    }
169
}
170