1
|
|
|
<?php |
2
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Tests for Stats 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\StatsShell; |
23
|
|
|
use Cake\TestSuite\TestCase; |
24
|
|
|
use Cake\Cache\Cache; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* App\Shell\StatsShell Test Case |
28
|
|
|
*/ |
29
|
|
|
class StatsShellTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* ConsoleIo mock |
34
|
|
|
* |
35
|
|
|
* @var \Cake\Console\ConsoleIo|\PHPUnit_Framework_MockObject_MockObject |
36
|
|
|
*/ |
37
|
|
|
public $io; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Test subject |
41
|
|
|
* |
42
|
|
|
* @var \App\Shell\StatsShell |
43
|
|
|
*/ |
44
|
|
|
public $Stats; |
45
|
|
|
|
46
|
|
|
public $fixtures = array( |
47
|
|
|
'app.incidents' |
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->Stats = new StatsShell($this->io); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* tearDown method |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
public function tearDown() |
68
|
|
|
{ |
69
|
|
|
unset($this->Stats); |
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->Stats->initialize(); |
83
|
|
|
|
84
|
|
|
// Clear the existing cache |
85
|
|
|
Cache::clear(false); |
86
|
|
|
|
87
|
|
|
// Run the shell command |
88
|
|
|
$this->Stats->main(); |
89
|
|
|
|
90
|
|
|
foreach ($this->Stats->Incidents->filterTimes as $filter_string => $filter) { |
91
|
|
|
foreach ($this->Stats->Incidents->summarizableFields as $field) { |
92
|
|
|
|
93
|
|
|
// Make sure all the fields are covered |
94
|
|
|
$this->assertNotEquals( |
95
|
|
|
false, |
96
|
|
|
Cache::read($field . '_' . $filter_string) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// Make sure download stats value stored |
101
|
|
|
$this->assertNotEquals( |
102
|
|
|
false, |
103
|
|
|
Cache::read('downloadStats_' . $filter_string) |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|