|
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 = array( |
|
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(array('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('array', |
|
32
|
|
|
$this->viewVariable('incident')['stacktrace']); |
|
33
|
|
|
$this->assertInternalType('array', |
|
34
|
|
|
$this->viewVariable('incident')['full_report']); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testJson() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->get('/incidents/json/1'); |
|
40
|
|
|
$incident = json_decode($this->_response->body(), true); |
|
41
|
|
|
$expected = array( |
|
42
|
|
|
'id' => 1, |
|
43
|
|
|
'error_name' => 'Lorem ipsum dolor sit amet', |
|
44
|
|
|
'error_message' => 'Lorem ipsum dolor sit amet', |
|
45
|
|
|
'pma_version' => 'Lorem ipsum dolor sit amet', |
|
46
|
|
|
'php_version' => '5.5', |
|
47
|
|
|
'browser' => 'Lorem ipsum dolor sit amet', |
|
48
|
|
|
'user_os' => 'Lorem ipsum dolor sit amet', |
|
49
|
|
|
'locale' => 'Lorem ipsum dolor sit amet', |
|
50
|
|
|
'server_software' => 'Lorem ipsum dolor sit amet', |
|
51
|
|
|
'stackhash' => 'hash1', |
|
52
|
|
|
'configuration_storage' => 'Lorem ipsum dolor sit amet', |
|
53
|
|
|
'script_name' => 'Lorem ipsum dolor sit amet', |
|
54
|
|
|
'steps' => 'Lorem ipsum dolor sit amet', |
|
55
|
|
|
'stacktrace' => array(array('context' => array('test'))), |
|
56
|
|
|
'full_report' => array( |
|
57
|
|
|
'pma_version' => '', |
|
58
|
|
|
'php_version' => '', |
|
59
|
|
|
'browser_name' => '', |
|
60
|
|
|
'browser_version' => '', |
|
61
|
|
|
'user_agent_string' => '', |
|
62
|
|
|
'server_software' => '', |
|
63
|
|
|
'locale' => '', |
|
64
|
|
|
'exception' => array('uri' => ''), |
|
65
|
|
|
'configuration_storage' => '', |
|
66
|
|
|
'microhistory' => '', |
|
67
|
|
|
), |
|
68
|
|
|
'report_id' => 1, |
|
69
|
|
|
'created' => '2013-08-29T18:10:01', |
|
70
|
|
|
'modified' => '2013-08-29T18:10:01', |
|
71
|
|
|
'exception_type' => null, |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertEquals($expected, $incident); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testCreate() |
|
78
|
|
|
{ |
|
79
|
|
|
$bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_js.json'); |
|
80
|
|
|
$bugReportDecoded = json_decode($bugReport, true); |
|
81
|
|
|
$this->configRequest(array('input' => $bugReport)); |
|
82
|
|
|
$this->post('/incidents/create'); |
|
83
|
|
|
|
|
84
|
|
|
$report = $this->Reports->find('all', |
|
85
|
|
|
array('order' => 'Reports.created desc'))->all()->first(); |
|
86
|
|
|
$subject = 'A new report has been submitted ' |
|
87
|
|
|
. 'on the Error Reporting Server: ' |
|
88
|
|
|
. $report['id']; |
|
89
|
|
|
|
|
90
|
|
|
// Test notification email |
|
91
|
|
|
$emailContent = Configure::read('test_transport_email'); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertEquals('[email protected]', $emailContent['headers']['From']); |
|
94
|
|
|
$this->assertEquals('[email protected]', $emailContent['headers']['To']); |
|
95
|
|
|
$this->assertEquals($subject, $emailContent['headers']['Subject']); |
|
96
|
|
|
|
|
97
|
|
|
Configure::write('test_transport_email', NULL); |
|
98
|
|
|
|
|
99
|
|
|
$this->post('/incidents/create'); |
|
100
|
|
|
|
|
101
|
|
|
$report = $this->Reports->find('all', |
|
102
|
|
|
array('order' => 'Reports.created desc'))->all()->first(); |
|
103
|
|
|
//$report = $report->hydrate(false)->toArray(); |
|
104
|
|
|
$this->Reports->id = $report['id']; |
|
105
|
|
|
$incidents = $this->Reports->getIncidents(); |
|
106
|
|
|
$incidents = $incidents->hydrate(false)->toArray(); |
|
107
|
|
|
$this->assertEquals(2, count($incidents)); |
|
108
|
|
|
$this->assertEquals($bugReportDecoded['exception']['message'], |
|
109
|
|
|
$report['error_message']); |
|
110
|
|
|
$this->assertEquals($bugReportDecoded['exception']['name'], |
|
111
|
|
|
$report['error_name']); |
|
112
|
|
|
$this->assertEquals($bugReportDecoded['pma_version'], |
|
113
|
|
|
$report['pma_version']); |
|
114
|
|
|
$this->configRequest(array('input' => array())); |
|
115
|
|
|
$this->post('/incidents/create'); |
|
116
|
|
|
$result = json_decode($this->_response->body(), true); |
|
117
|
|
|
$this->assertEquals(false, $result['success']); |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
// Test invalid Notification email configuration |
|
122
|
|
|
Configure::write('NotificationEmailsTo', ''); |
|
123
|
|
|
|
|
124
|
|
|
$bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_php.json'); |
|
125
|
|
|
$bugReportDecoded = json_decode($bugReport, true); |
|
|
|
|
|
|
126
|
|
|
$this->configRequest(array('input' => $bugReport)); |
|
127
|
|
|
$this->post('/incidents/create'); |
|
128
|
|
|
|
|
129
|
|
|
$report = $this->Reports->find('all', |
|
130
|
|
|
array('order' => 'Reports.created desc'))->all()->first(); |
|
131
|
|
|
$subject = 'A new report has been submitted ' |
|
|
|
|
|
|
132
|
|
|
. 'on the Error Reporting Server: ' |
|
133
|
|
|
. $report['id']; |
|
134
|
|
|
|
|
135
|
|
|
$emailContent = Configure::read('test_transport_email'); |
|
136
|
|
|
|
|
137
|
|
|
// Since no email sent |
|
138
|
|
|
$this->assertEquals(NULL, $emailContent); |
|
139
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: