|
1
|
|
|
<?php |
|
2
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Tests for Clean Old Notifications Shell. |
|
6
|
|
|
* |
|
7
|
|
|
* phpMyAdmin Error reporting server |
|
8
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
|
9
|
|
|
* |
|
10
|
|
|
* Licensed under The MIT License |
|
11
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
12
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
13
|
|
|
* |
|
14
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
|
15
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
|
16
|
|
|
* |
|
17
|
|
|
* @see https://www.phpmyadmin.net/ |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace App\Test\TestCase\Shell; |
|
21
|
|
|
|
|
22
|
|
|
use App\Shell\CleanOldNotifsShell; |
|
23
|
|
|
use Cake\TestSuite\TestCase; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* App\Shell\CleanOldNotifsShell Test Case |
|
27
|
|
|
*/ |
|
28
|
|
|
class CleanOldNotifsShellTest extends TestCase |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* ConsoleIo mock |
|
33
|
|
|
* |
|
34
|
|
|
* @var \Cake\Console\ConsoleIo|\PHPUnit_Framework_MockObject_MockObject |
|
35
|
|
|
*/ |
|
36
|
|
|
public $io; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Test subject |
|
40
|
|
|
* |
|
41
|
|
|
* @var \App\Shell\CleanOldNotifsShell |
|
42
|
|
|
*/ |
|
43
|
|
|
public $CleanOldNotifs; |
|
44
|
|
|
|
|
45
|
|
|
public $fixtures = array( |
|
46
|
|
|
'app.notifications', |
|
47
|
|
|
'app.developers' |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* setUp method |
|
52
|
|
|
* |
|
53
|
|
|
* @return void |
|
54
|
|
|
*/ |
|
55
|
|
|
public function setUp() |
|
56
|
|
|
{ |
|
57
|
|
|
parent::setUp(); |
|
58
|
|
|
$this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock(); |
|
59
|
|
|
$this->CleanOldNotifs = new CleanOldNotifsShell($this->io); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* tearDown method |
|
64
|
|
|
* |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
public function tearDown() |
|
68
|
|
|
{ |
|
69
|
|
|
unset($this->CleanOldNotifs); |
|
70
|
|
|
|
|
71
|
|
|
parent::tearDown(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Test main method |
|
76
|
|
|
* |
|
77
|
|
|
* @return void |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testMain() |
|
80
|
|
|
{ |
|
81
|
|
|
// Call intialize method to load the models |
|
82
|
|
|
$this->CleanOldNotifs->initialize(); |
|
83
|
|
|
|
|
84
|
|
|
$conditions = array( |
|
85
|
|
|
'developer_id' => 1 |
|
86
|
|
|
); |
|
87
|
|
|
$currentNotificationCount |
|
88
|
|
|
= $this->CleanOldNotifs->Notifications->find('all')->where($conditions)->count(); |
|
89
|
|
|
$this->assertEquals(2, $currentNotificationCount); |
|
90
|
|
|
|
|
91
|
|
|
// Run shell command |
|
92
|
|
|
$this->CleanOldNotifs->main(); |
|
93
|
|
|
|
|
94
|
|
|
$newNotificationCount |
|
95
|
|
|
= $this->CleanOldNotifs->Notifications->find('all')->where($conditions)->count(); |
|
96
|
|
|
$this->assertEquals(0, $newNotificationCount); |
|
97
|
|
|
|
|
98
|
|
|
// Run shell command to generate zero notifications error |
|
99
|
|
|
$this->CleanOldNotifs->main(); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|