Completed
Push — feature/debug-travis-fail-on-d... ( c53067 )
by Lucas
84:33 queued 84:27
created

EventStatusControllerTest::testInvalidStatus()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 43
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 43
rs 8.8571
cc 1
eloc 29
nc 1
nop 0
1
<?php
2
/**
3
 * functional test for /event/status
4
 */
5
6
namespace Graviton\RabbitMqBundle\Tests\Controller;
7
8
use Graviton\TestBundle\Test\RestTestCase;
9
10
/**
11
 * Functional test for /event/status.
12
 *
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 EventStatusControllerTest extends RestTestCase
18
{
19
20
    /**
21
     * test to see if we can insert a status and if graviton complains about an invalid status
22
     *
23
     * @return void
24
     */
25
    public function testInvalidStatus()
26
    {
27
        $status = new \stdClass();
28
        $status->id = 'mynewstatus';
29
        $status->createDate = '2015-09-24T07:21:24+0000';
30
        $status->eventName = 'document.test.app.create';
31
32
        $statusEntry = new \stdClass();
33
        $statusEntry->workerId = 'testworker';
34
        $statusEntry->status = 'opened';
35
        $statusEntry->action  = 'status-key-action';
36
37
        $status->status = [$statusEntry];
38
39
        $client = static::createRestClient();
40
        $client->put('/event/status/mynewstatus', $status);
41
42
        $this->assertNull($client->getResults());
43
        $this->assertNull($client->getResponse()->headers->get('Location'));
44
        $this->assertEquals(204, $client->getResponse()->getStatusCode());
45
46
        // get our object again
47
        $client = static::createRestClient();
48
        $client->request('GET', '/event/status/mynewstatus');
49
        $results = $client->getResults();
50
51
        $this->assertEquals('opened', $results->status[0]->status);
52
        $this->assertEquals('status-key-action', $results->status[0]->action);
53
54
        // set invalid status
55
        $results->status[0]->status = 'thinking';
56
57
        $client = static::createRestClient();
58
        $client->put('/event/status/mynewstatus', $results);
59
        $results = $client->getResults();
60
61
        $this->assertEquals(400, $client->getResponse()->getStatusCode());
62
        $this->assertEquals("status[0].status", $results[0]->propertyPath);
63
        $this->assertContains(
64
            "Does not have a value in the enumeration [\"opened\",\"working\",\"ignored\",\"done\",\"failed\"]",
65
            $results[0]->message
66
        );
67
    }
68
69
    /**
70
     * test to see if we can insert a status and if graviton complains about an invalid status
71
     *
72
     * @return void
73
     */
74
    public function testInvalidInformationType()
75
    {
76
        $status = new \stdClass();
77
        $status->id = 'mynewstatus';
78
        $status->createDate = '2015-09-24T07:21:24+0000';
79
        $status->eventName = 'document.test.app.create';
80
81
        $informationEntry = new \stdClass();
82
        $informationEntry->workerId = 'testworker';
83
        $informationEntry->type = 'info';
84
        $informationEntry->content = 'see the attached document';
85
        $informationEntry->{'$ref'} = 'http://localhost/core/app/admin';
86
87
        $status->information = [$informationEntry];
88
89
        $client = static::createRestClient();
90
        $client->put('/event/status/mynewstatus', $status);
91
92
        $this->assertNull($client->getResults());
93
        $this->assertNull($client->getResponse()->headers->get('Location'));
94
        $this->assertEquals(204, $client->getResponse()->getStatusCode());
95
96
        // get our object again
97
        $client = static::createRestClient();
98
        $client->request('GET', '/event/status/mynewstatus');
99
        $results = $client->getResults();
100
101
        $this->assertEquals('testworker', $results->information[0]->workerId);
102
        $this->assertEquals('info', $results->information[0]->type);
103
        $this->assertEquals('see the attached document', $results->information[0]->content);
104
        $this->assertEquals('http://localhost/core/app/admin', $results->information[0]->{'$ref'});
105
106
        // set invalid information type
107
        $results->information[0]->type = 'bogus';
108
109
        $client = static::createRestClient();
110
        $client->put('/event/status/mynewstatus', $results);
111
        $results = $client->getResults();
112
113
        $this->assertEquals(400, $client->getResponse()->getStatusCode());
114
        $this->assertEquals("information[0].type", $results[0]->propertyPath);
115
        $this->assertContains(
116
            "Does not have a value in the enumeration [\"debug\",\"info\",\"warning\",\"error\"]",
117
            $results[0]->message
118
        );
119
    }
120
121
    /**
122
     * Event Status Action
123
     *
124
     * @return void
125
     */
126
    public function testEventStatusActionStatus()
127
    {
128
        // Create a action and translation
129
        $action = new \stdClass();
130
        $action->id = 'new-worker-action-id';
131
        $action->description = new \stdClass();
132
        $action->description->en = "Some translated action";
133
134
        $client = static::createRestClient();
135
        $client->put('/event/action/'.$action->id, $action);
136
137
        // Check result
138
        $this->assertEquals(204, $client->getResponse()->getStatusCode());
139
140
        // get our object again
141
        $client = static::createRestClient();
142
        $client->request('GET', '/event/action/'.$action->id);
143
        $results = $client->getResults();
144
        $this->assertEquals($action->description->en, $results->description->en);
145
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
146
147
        // Creating the event
148
        $eventStatus = new \stdClass();
149
        $eventStatus->id = 'mynewstatus2';
150
        $eventStatus->createDate = '2015-09-24T07:21:24+0000';
151
        $eventStatus->eventName = 'document.test.app.create';
152
153
        $status = new \stdClass();
154
        $status->workerId = 'testworker';
155
        $status->status = 'opened';
156
        $status->action = new \stdClass();
157
        $status->action->{'$ref'} = 'http://localhost/event/action/'.$action->id;
158
        $eventStatus->status = [$status];
159
160
        // Save the status
161
        $client = static::createRestClient();
162
        $client->put('/event/status/mynewstatus2', $eventStatus);
163
164
        $this->assertNull($client->getResults());
165
        $this->assertNull($client->getResponse()->headers->get('Location'));
166
        $this->assertEquals(204, $client->getResponse()->getStatusCode());
167
168
        // get our object again, checking
169
        $client = static::createRestClient();
170
        $client->request('GET', '/event/status/mynewstatus2');
171
        $results = $client->getResults();
172
173
        $this->assertEquals('opened', $results->status[0]->status);
174
        $this->assertEquals('http://localhost/event/action/'.$action->id, $results->status[0]->action->{'$ref'});
175
176
    }
177
}
178