|
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
|
|
|
|
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: