Completed
Push — master ( 6d849d...f9dc97 )
by Michal
02:55 queued 57s
created

NotificationsControllerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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');
0 ignored issues
show
Bug introduced by
The property Notifications does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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