1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Test\TestCase\Controller; |
4
|
|
|
|
5
|
|
|
use Cake\ORM\TableRegistry; |
6
|
|
|
use Cake\TestSuite\IntegrationTestTrait; |
7
|
|
|
use Cake\TestSuite\TestCase; |
8
|
|
|
|
9
|
|
|
use function json_decode; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* NotificationsController Test Case. |
13
|
|
|
*/ |
14
|
|
|
class NotificationsControllerTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
use IntegrationTestTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Fixtures. |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
public $fixtures = [ |
24
|
|
|
'app.Notifications', |
25
|
|
|
'app.Developers', |
26
|
|
|
'app.Reports', |
27
|
|
|
'app.Incidents', |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
public function setUp(): void |
31
|
|
|
{ |
32
|
|
|
$this->Notifications = TableRegistry::getTableLocator()->get('Notifications'); |
33
|
|
|
$this->session(['Developer.id' => 1, 'read_only' => true]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testIndex(): void |
37
|
|
|
{ |
38
|
|
|
$this->get('notifications'); |
39
|
|
|
|
40
|
|
|
// 'read_only' users are not allowed to view notifications page |
41
|
|
|
$this->assertRedirect(['controller' => '', 'action' => 'index']); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testMassAction(): void |
45
|
|
|
{ |
46
|
|
|
$this->session(['Developer.id' => 1, 'read_only' => false]); |
47
|
|
|
|
48
|
|
|
/* Test case 1 */ |
49
|
|
|
$this->post( |
50
|
|
|
'/notifications/mass_action', |
51
|
|
|
[ |
52
|
|
|
'notifs' => [ |
53
|
|
|
'1', |
54
|
|
|
'3', |
55
|
|
|
], |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$notifications = $this->Notifications->find('all', ['fields' => ['Notifications.id']]); |
60
|
|
|
$this->assertInstanceOf('Cake\ORM\Query', $notifications); |
61
|
|
|
$actual = $notifications->enableHydration(false)->toArray(); |
62
|
|
|
$expected = [ |
63
|
|
|
['id' => '2'], |
64
|
|
|
]; |
65
|
|
|
$this->assertEquals($actual, $expected); |
66
|
|
|
|
67
|
|
|
/* Test case 2 */ |
68
|
|
|
$this->post( |
69
|
|
|
'/notifications/mass_action', |
70
|
|
|
['mark_all' => 1] |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$notifications = $this->Notifications->find('all', ['fields' => ['Notifications.id']]); |
74
|
|
|
$this->assertInstanceOf('Cake\ORM\Query', $notifications); |
75
|
|
|
$actual = $notifications->enableHydration(false)->toArray(); |
76
|
|
|
$expected = []; |
77
|
|
|
$this->assertEquals($actual, $expected); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testDataTables(): void |
81
|
|
|
{ |
82
|
|
|
$this->session(['Developer.id' => 1, 'read_only' => false]); |
83
|
|
|
|
84
|
|
|
$this->get('notifications/data_tables?sEcho=1&iDisplayLength=25'); |
85
|
|
|
|
86
|
|
|
$expected = [ |
87
|
|
|
'iTotalRecords' => 2, |
88
|
|
|
'iTotalDisplayRecords' => 2, |
89
|
|
|
'sEcho' => 1, |
90
|
|
|
'aaData' => [ |
91
|
|
|
[ |
92
|
|
|
'<input type="checkbox" name="notifs[]" value="1"/>', |
93
|
|
|
'<a href="/reports/view/1">1</a>', |
94
|
|
|
'error2', |
95
|
|
|
'Lorem ipsum dolor sit amet', |
96
|
|
|
'4.0', |
97
|
|
|
'js', |
98
|
|
|
'2014-01-01T07:05:09+00:00', |
99
|
|
|
], |
100
|
|
|
[ |
101
|
|
|
'<input type="checkbox" name="notifs[]" value="2"/>', |
102
|
|
|
'<a href="/reports/view/4">4</a>', |
103
|
|
|
'error1', |
104
|
|
|
'Lorem ipsum dolor sit amet', |
105
|
|
|
'3.8', |
106
|
|
|
'js', |
107
|
|
|
'2014-01-02T07:05:09+00:00', |
108
|
|
|
], |
109
|
|
|
], |
110
|
|
|
]; |
111
|
|
|
|
112
|
|
|
$this->assertResponseOk(); |
113
|
|
|
$this->assertEquals($expected, json_decode($this->_response->getBody(), true)); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|