1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Test\TestCase\Controller; |
4
|
|
|
|
5
|
|
|
use Cake\Core\Configure; |
6
|
|
|
use Cake\ORM\TableRegistry; |
7
|
|
|
use Cake\TestSuite\IntegrationTestCase; |
8
|
|
|
|
9
|
|
|
class IncidentsControllerTest extends IntegrationTestCase |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
public $fixtures = [ |
12
|
|
|
'app.Notifications', |
13
|
|
|
'app.Developers', |
14
|
|
|
'app.Reports', |
15
|
|
|
'app.Incidents', |
16
|
|
|
]; |
17
|
|
|
|
18
|
|
|
public function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->Incidents = TableRegistry::get('Incidents'); |
|
|
|
|
21
|
|
|
//$Session = new SessionComponent(new ComponentRegistry()); |
22
|
|
|
$this->session(['Developer.id' => 1]); |
23
|
|
|
$this->Reports = TableRegistry::get('Reports'); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testView() |
27
|
|
|
{ |
28
|
|
|
$this->get('/incidents/view/1'); |
29
|
|
|
|
30
|
|
|
$this->assertNotEmpty($this->viewVariable('incident')); |
31
|
|
|
$this->assertInternalType( |
32
|
|
|
'array', |
33
|
|
|
$this->viewVariable('incident')['stacktrace'] |
34
|
|
|
); |
35
|
|
|
$this->assertInternalType( |
36
|
|
|
'array', |
37
|
|
|
$this->viewVariable('incident')['full_report'] |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testJson() |
42
|
|
|
{ |
43
|
|
|
$this->get('/incidents/json/1'); |
44
|
|
|
$incident = json_decode($this->_response->body(), true); |
|
|
|
|
45
|
|
|
$expected = [ |
46
|
|
|
'id' => 1, |
47
|
|
|
'error_name' => 'Lorem ipsum dolor sit amet', |
48
|
|
|
'error_message' => 'Lorem ipsum dolor sit amet', |
49
|
|
|
'pma_version' => 'Lorem ipsum dolor sit amet', |
50
|
|
|
'php_version' => '5.5', |
51
|
|
|
'browser' => 'Lorem ipsum dolor sit amet', |
52
|
|
|
'user_os' => 'Lorem ipsum dolor sit amet', |
53
|
|
|
'locale' => 'Lorem ipsum dolor sit amet', |
54
|
|
|
'server_software' => 'Lorem ipsum dolor sit amet', |
55
|
|
|
'stackhash' => 'hash1', |
56
|
|
|
'configuration_storage' => 'Lorem ipsum dolor sit amet', |
57
|
|
|
'script_name' => 'Lorem ipsum dolor sit amet', |
58
|
|
|
'steps' => 'Lorem ipsum dolor sit amet', |
59
|
|
|
'stacktrace' => [['context' => ['test']]], |
60
|
|
|
'full_report' => [ |
61
|
|
|
'pma_version' => '', |
62
|
|
|
'php_version' => '', |
63
|
|
|
'browser_name' => '', |
64
|
|
|
'browser_version' => '', |
65
|
|
|
'user_agent_string' => '', |
66
|
|
|
'server_software' => '', |
67
|
|
|
'locale' => '', |
68
|
|
|
'exception' => ['uri' => ''], |
69
|
|
|
'configuration_storage' => '', |
70
|
|
|
'microhistory' => '', |
71
|
|
|
], |
72
|
|
|
'report_id' => 1, |
73
|
|
|
'created' => '2013-08-29T18:10:01+00:00', |
74
|
|
|
'modified' => '2013-08-29T18:10:01+00:00', |
75
|
|
|
'exception_type' => null, |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
$this->assertEquals($expected, $incident); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testCreate() |
82
|
|
|
{ |
83
|
|
|
$bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_js.json'); |
84
|
|
|
$bugReportDecoded = json_decode($bugReport, true); |
85
|
|
|
$this->configRequest(['input' => $bugReport]); |
86
|
|
|
$this->post('/incidents/create'); |
87
|
|
|
|
88
|
|
|
$report = $this->Reports->find( |
89
|
|
|
'all', |
90
|
|
|
['order' => 'Reports.created desc'] |
91
|
|
|
)->all()->first(); |
92
|
|
|
$subject = 'A new report has been submitted ' |
|
|
|
|
93
|
|
|
. 'on the Error Reporting Server: ' |
94
|
|
|
. $report['id']; |
95
|
|
|
$this->assertEquals('4.5.4.1', $report['pma_version']); |
96
|
|
|
|
97
|
|
|
//FIXME: test email sending |
98
|
|
|
// Test notification email |
99
|
|
|
//$emailContent = Configure::read('test_transport_email'); |
100
|
|
|
|
101
|
|
|
//$this->assertEquals(Configure::read('NotificationEmailsFrom'), $emailContent['headers']['From']); |
102
|
|
|
//$this->assertEquals(Configure::read('NotificationEmailsTo'), $emailContent['headers']['To']); |
103
|
|
|
//$this->assertEquals($subject, $emailContent['headers']['Subject']); |
104
|
|
|
|
105
|
|
|
//Configure::write('test_transport_email', null); |
106
|
|
|
|
107
|
|
|
$this->post('/incidents/create'); |
108
|
|
|
|
109
|
|
|
$report = $this->Reports->find( |
110
|
|
|
'all', |
111
|
|
|
['order' => 'Reports.created desc'] |
112
|
|
|
)->all()->first(); |
113
|
|
|
$this->Reports->id = $report['id']; |
114
|
|
|
$incidents = $this->Reports->getIncidents(); |
115
|
|
|
$incidents = $incidents->hydrate(false)->toArray(); |
116
|
|
|
$this->assertEquals(2, count($incidents)); |
117
|
|
|
$this->assertEquals( |
118
|
|
|
$bugReportDecoded['exception']['message'], |
119
|
|
|
$report['error_message'] |
120
|
|
|
); |
121
|
|
|
$this->assertEquals( |
122
|
|
|
$bugReportDecoded['exception']['name'], |
123
|
|
|
$report['error_name'] |
124
|
|
|
); |
125
|
|
|
$this->assertEquals( |
126
|
|
|
$this->Incidents->getStrippedPmaVersion($bugReportDecoded['pma_version']), |
127
|
|
|
$report['pma_version'] |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$this->configRequest(['input' => '']); |
131
|
|
|
$this->post('/incidents/create'); |
132
|
|
|
$result = json_decode($this->_response->body(), true); |
|
|
|
|
133
|
|
|
$this->assertEquals(false, $result['success']); |
134
|
|
|
|
135
|
|
|
// Test invalid Notification email configuration |
136
|
|
|
Configure::write('NotificationEmailsTo', ''); |
137
|
|
|
|
138
|
|
|
$bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_php.json'); |
139
|
|
|
$bugReportDecoded = json_decode($bugReport, true); |
|
|
|
|
140
|
|
|
$this->configRequest(['input' => $bugReport]); |
141
|
|
|
$this->post('/incidents/create'); |
142
|
|
|
|
143
|
|
|
$report = $this->Reports->find( |
144
|
|
|
'all', |
145
|
|
|
['order' => 'Reports.created desc'] |
146
|
|
|
)->all()->first(); |
147
|
|
|
$subject = 'A new report has been submitted ' |
148
|
|
|
. 'on the Error Reporting Server: ' |
149
|
|
|
. $report['id']; |
150
|
|
|
$this->assertEquals('4.5.4.1', $report['pma_version']); |
151
|
|
|
|
152
|
|
|
$emailContent = Configure::read('test_transport_email'); |
153
|
|
|
|
154
|
|
|
// Since no email sent |
155
|
|
|
$this->assertEquals(null, $emailContent); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|