1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Test\TestCase\Model\Table; |
4
|
|
|
|
5
|
|
|
use Cake\ORM\Query; |
6
|
|
|
use Cake\ORM\ResultSet; |
7
|
|
|
use Cake\ORM\TableRegistry; |
8
|
|
|
use Cake\TestSuite\TestCase; |
9
|
|
|
|
10
|
|
|
use function count; |
11
|
|
|
|
12
|
|
|
class ReportsTableTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Fixtures. |
16
|
|
|
* |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
public $fixtures = [ |
20
|
|
|
'app.Notifications', |
21
|
|
|
'app.Developers', |
22
|
|
|
'app.Reports', |
23
|
|
|
'app.Incidents', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
public function setUp(): void |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
$this->Reports = TableRegistry::getTableLocator()->get('Reports'); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetIncidents(): void |
33
|
|
|
{ |
34
|
|
|
$this->Reports->id = 4; |
35
|
|
|
$incidents = $this->Reports->getIncidents(); |
36
|
|
|
$this->assertInstanceOf('Cake\ORM\Query', $incidents); |
37
|
|
|
$result = $incidents->enableHydration(false)->toArray(); |
38
|
|
|
$this->assertEquals(count($result), 2); |
39
|
|
|
|
40
|
|
|
//$this->Reports->saveField("related_to", null); TODO: fix related to issue |
41
|
|
|
//$incidents = $this->Report->getIncidents(); |
42
|
|
|
//$this->assertEquals(count($incidents), 2); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
//TODO: will do after related to fix |
46
|
|
|
//public function testGetRelatedReports() { |
47
|
|
|
// $this->Reports->id = 2; |
48
|
|
|
// $reports = $this->Reports->getRelatedReports(); |
49
|
|
|
// $this->assertEquals(count($reports), 0); |
50
|
|
|
// |
51
|
|
|
// $this->Report->read(null, 4); |
52
|
|
|
// $reports = $this->Report->getRelatedReports(); |
53
|
|
|
// $this->assertEquals(count($reports), 1); |
54
|
|
|
//} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Test for getIncidentsWithDescription |
58
|
|
|
*/ |
59
|
|
|
public function testGetIncidentsWithDescription(): void |
60
|
|
|
{ |
61
|
|
|
$this->Reports->id = 4; |
62
|
|
|
$incidents = $this->Reports->getIncidentsWithDescription(); |
63
|
|
|
$this->assertInstanceOf('Cake\ORM\Query', $incidents); |
64
|
|
|
$result = $incidents->enableHydration(false)->toArray(); |
65
|
|
|
$this->assertEquals(count($result), 1); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGetIncidentsWithDifferentStacktrace(): void |
69
|
|
|
{ |
70
|
|
|
$this->Reports->id = 4; |
71
|
|
|
$incidents = $this->Reports->getIncidentsWithDifferentStacktrace(); |
72
|
|
|
$this->assertInstanceOf('Cake\ORM\Query', $incidents); |
73
|
|
|
$result = $incidents->enableHydration(false)->toArray(); |
74
|
|
|
$this->assertEquals(count($result), 1); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// TODO: will do after related to fix |
78
|
|
|
// public function testRemoveFromRelatedGroup() { |
79
|
|
|
// $this->Report->read(null, 1); |
80
|
|
|
// $this->Report->removeFromRelatedGroup(); |
81
|
|
|
// $incidents = $this->Report->getIncidents(); |
82
|
|
|
// $this->assertEquals(count($incidents), 1); |
83
|
|
|
// } |
84
|
|
|
|
85
|
|
|
// TODO: will do after realted to fix |
86
|
|
|
//public function testAddToRelatedGroup() { |
87
|
|
|
// $this->Report->read(null, 2); |
88
|
|
|
// $this->Report->addToRelatedGroup(4); |
89
|
|
|
// |
90
|
|
|
// $this->Report->read(null, 2); |
91
|
|
|
// $incidents = $this->Report->getIncidents(); |
92
|
|
|
// $this->assertEquals(count($incidents), 3); |
93
|
|
|
// |
94
|
|
|
// $this->Report->saveField("related_to", null); |
95
|
|
|
// $this->Report->addToRelatedGroup(1); |
96
|
|
|
// $this->Report->read(null, 2); |
97
|
|
|
// $incidents = $this->Report->getIncidents(); |
98
|
|
|
// $this->assertEquals(count($incidents), 3); |
99
|
|
|
//} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Test for getRelatedByField |
103
|
|
|
*/ |
104
|
|
|
public function testGetRelatedByField(): void |
105
|
|
|
{ |
106
|
|
|
$this->Reports->id = 1; |
107
|
|
|
$result = $this->Reports->getRelatedByField('php_version'); |
108
|
|
|
$this->assertInstanceOf(Query::class, $result); |
109
|
|
|
$result = $result->enableHydration(false)->toArray(); |
110
|
|
|
$expected = [ |
111
|
|
|
[ |
112
|
|
|
'php_version' => '5.5', |
113
|
|
|
'count' => '1', |
114
|
|
|
], |
115
|
|
|
]; |
116
|
|
|
$this->assertEquals($expected, $result); |
117
|
|
|
$this->Reports->id = 4; |
118
|
|
|
$result = $this->Reports->getRelatedByField('php_version', 1); |
119
|
|
|
$this->assertInstanceOf(Query::class, $result); |
120
|
|
|
$result = $result->enableHydration(false)->toArray(); |
121
|
|
|
$expected = [ |
122
|
|
|
[ |
123
|
|
|
'php_version' => '5.3', |
124
|
|
|
'count' => '2', |
125
|
|
|
], |
126
|
|
|
]; |
127
|
|
|
$this->assertEquals($expected, $result); |
128
|
|
|
$this->Reports->id = 1; |
129
|
|
|
$result = $this->Reports->getRelatedByField( |
130
|
|
|
'php_version', |
131
|
|
|
10, |
132
|
|
|
false, |
133
|
|
|
true, |
134
|
|
|
'2013-08-29 18:10:01' |
135
|
|
|
); |
136
|
|
|
$this->assertInstanceOf(Query::class, $result); |
137
|
|
|
$result = $result->enableHydration(false)->toArray(); |
138
|
|
|
$expected = [ |
139
|
|
|
[ |
140
|
|
|
'php_version' => '5.5', |
141
|
|
|
'count' => '1', |
142
|
|
|
], |
143
|
|
|
]; |
144
|
|
|
$this->assertEquals($expected, $result); |
145
|
|
|
|
146
|
|
|
$result = $this->Reports->getRelatedByField('php_version', 10, false, false); |
147
|
|
|
$this->assertInstanceOf(Query::class, $result); |
148
|
|
|
$result = $result->enableHydration(false)->toArray(); |
149
|
|
|
$expected = [ |
150
|
|
|
[ |
151
|
|
|
'php_version' => '5.5', |
152
|
|
|
'count' => '1', |
153
|
|
|
], |
154
|
|
|
[ |
155
|
|
|
'php_version' => '5.3', |
156
|
|
|
'count' => '4', |
157
|
|
|
], |
158
|
|
|
]; |
159
|
|
|
$this->assertEquals($expected, $result); |
160
|
|
|
$result = $this->Reports->getRelatedByField('php_version', 10, true); |
161
|
|
|
$this->assertInstanceOf(ResultSet::class, $result[0]); |
162
|
|
|
$result[0] = $result[0]->toArray(); |
163
|
|
|
$result[0][0] = $result[0][0]->toArray(); |
164
|
|
|
$expected = [ |
165
|
|
|
[ |
166
|
|
|
[ |
167
|
|
|
'php_version' => '5.5', |
168
|
|
|
'count' => '1', |
169
|
|
|
], |
170
|
|
|
], |
171
|
|
|
1, |
172
|
|
|
]; |
173
|
|
|
$this->assertEquals($expected, $result); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|