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