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