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