1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ApplicationTest\Service; |
4
|
|
|
|
5
|
|
|
use Zend\Stdlib\ArrayUtils; |
6
|
|
|
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; |
7
|
|
|
use Application\Service\BotParser; |
8
|
|
|
|
9
|
|
|
class BotParserTest extends AbstractHttpControllerTestCase |
10
|
|
|
{ |
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
// The module configuration should still be applicable for tests. |
14
|
|
|
// You can override configuration here with test case specific values, |
15
|
|
|
// such as sample view templates, path stacks, module_listener_options, |
16
|
|
|
// etc. |
17
|
|
|
$configOverrides = []; |
18
|
|
|
|
19
|
|
|
$this->setApplicationConfig(ArrayUtils::merge( |
20
|
|
|
include __DIR__ . '/../../../../config/application.config.php', |
21
|
|
|
$configOverrides |
22
|
|
|
)); |
23
|
|
|
|
24
|
|
|
parent::setUp(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testPositionQuest() |
28
|
|
|
{ |
29
|
|
|
$testcase = 'questinfo-position.txt'; |
30
|
|
|
$config = [ |
31
|
|
|
'bot_quest' => __DIR__ . '/../testcases/' . $testcase, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
$parser = new BotParser($config); |
35
|
|
|
$db = $parser->getQuestData(); |
36
|
|
|
|
37
|
|
|
// Title |
38
|
|
|
$this->assertEquals( |
39
|
|
|
'lay waste to the Towers of Ankh-Allor, wherein lies the terrible sorceror Croocq', |
40
|
|
|
$db['title'] |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
// Type |
44
|
|
|
$this->assertEquals(2, $db['type']); |
45
|
|
|
|
46
|
|
|
// Current stage |
47
|
|
|
$this->assertEquals(1, $db['objective']); |
48
|
|
|
|
49
|
|
|
// Number of stages |
50
|
|
|
$this->assertEquals(2, count($db['stages'])); |
51
|
|
|
|
52
|
|
|
// Stage 1 |
53
|
|
|
$this->assertEquals([ |
54
|
|
|
'x_pos' => 225, |
55
|
|
|
'y_pos' => 315, |
56
|
|
|
'color' => '#d30000', |
57
|
|
|
], $db['stages'][0]); |
58
|
|
|
|
59
|
|
|
// Stage 2 |
60
|
|
|
$this->assertEquals([ |
61
|
|
|
'x_pos' => 280, |
62
|
|
|
'y_pos' => 360, |
63
|
|
|
'color' => '#d30000', |
64
|
|
|
], $db['stages'][1]); |
65
|
|
|
|
66
|
|
|
// Number of players |
67
|
|
|
$this->assertEquals(4, count($db['players'])); |
68
|
|
|
|
69
|
|
|
// Player 1 |
70
|
|
|
$this->assertEquals([ |
71
|
|
|
'nick' => 'Orange', |
72
|
|
|
'x_pos' => 195, |
73
|
|
|
'y_pos' => 315, |
74
|
|
|
'color' => '#0080e1', |
75
|
|
|
], $db['players'][0]); |
76
|
|
|
|
77
|
|
|
// Player 2 |
78
|
|
|
$this->assertEquals([ |
79
|
|
|
'nick' => 'pi', |
80
|
|
|
'x_pos' => 225, |
81
|
|
|
'y_pos' => 270, |
82
|
|
|
'color' => '#0080e1', |
83
|
|
|
], $db['players'][1]); |
84
|
|
|
|
85
|
|
|
// Player 3 |
86
|
|
|
$this->assertEquals([ |
87
|
|
|
'nick' => 'BernardoRafael', |
88
|
|
|
'x_pos' => 225, |
89
|
|
|
'y_pos' => 315, |
90
|
|
|
'color' => '#0080e1', |
91
|
|
|
], $db['players'][2]); |
92
|
|
|
|
93
|
|
|
// Player 4 |
94
|
|
|
$this->assertEquals([ |
95
|
|
|
'nick' => 'pirilampo', |
96
|
|
|
'x_pos' => 225, |
97
|
|
|
'y_pos' => 315, |
98
|
|
|
'color' => '#0080e1', |
99
|
|
|
], $db['players'][3]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testTimeQuest() |
103
|
|
|
{ |
104
|
|
|
$testcase = 'questinfo-time.txt'; |
105
|
|
|
$config = [ |
106
|
|
|
'bot_quest' => __DIR__ . '/../testcases/' . $testcase, |
107
|
|
|
]; |
108
|
|
|
|
109
|
|
|
$parser = new BotParser($config); |
110
|
|
|
$db = $parser->getQuestData(); |
111
|
|
|
|
112
|
|
|
// Title |
113
|
|
|
$this->assertEquals( |
114
|
|
|
'locate the herbs and brew the elixir to rid the realm of the Normonic Plague', |
115
|
|
|
$db['title'] |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
// Type |
119
|
|
|
$this->assertEquals(1, $db['type']); |
120
|
|
|
|
121
|
|
|
// Current stage |
122
|
|
|
$this->assertEquals(1531325222, $db['objective_num']); |
123
|
|
|
|
124
|
|
|
// Number of players |
125
|
|
|
$this->assertEquals(4, count($db['players'])); |
126
|
|
|
|
127
|
|
|
$this->assertEquals('RichardStallman', $db['players'][0]['nick']); |
128
|
|
|
$this->assertEquals('xhip', $db['players'][1]['nick']); |
129
|
|
|
$this->assertEquals('Infernvs', $db['players'][2]['nick']); |
130
|
|
|
$this->assertEquals('.hack', $db['players'][3]['nick']); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testScoreboard() |
134
|
|
|
{ |
135
|
|
|
$testcase = 'irpg-scoreboard.db'; |
136
|
|
|
$config = [ |
137
|
|
|
'bot_db' => __DIR__ . '/../testcases/' . $testcase, |
138
|
|
|
]; |
139
|
|
|
|
140
|
|
|
$parser = new BotParser($config); |
141
|
|
|
$scoreboard = $parser->getScoreboard(); |
142
|
|
|
|
143
|
|
|
// Test the sorting method |
144
|
|
|
// flcl and fALSO have the same level, but flcl should be first |
145
|
|
|
// because he has a lower ttl |
146
|
|
|
$this->assertEquals('flcl', $scoreboard[0]['nick']); |
147
|
|
|
$this->assertEquals('fALSO', $scoreboard[1]['nick']); |
148
|
|
|
|
149
|
|
|
// Number of players |
150
|
|
|
$this->assertEquals(12, count($scoreboard)); |
151
|
|
|
|
152
|
|
|
// Full data of the first player |
153
|
|
|
$this->assertEquals([ |
154
|
|
|
'nick' => 'flcl', |
155
|
|
|
'level' => 43, |
156
|
|
|
'class' => 'gordo', |
157
|
|
|
'ttl' => '3 days 1 hour', |
158
|
|
|
'ttl_num' => 264103, |
159
|
|
|
'status' => true |
160
|
|
|
], $scoreboard[0]); |
161
|
|
|
|
162
|
|
|
// Full data of the last player |
163
|
|
|
$this->assertEquals([ |
164
|
|
|
'nick' => 'MalMen', |
165
|
|
|
'level' => 26, |
166
|
|
|
'class' => 'amen', |
167
|
|
|
'ttl' => '1 hour 40 minutes', |
168
|
|
|
'ttl_num' => 6031, |
169
|
|
|
'status' => true |
170
|
|
|
], $scoreboard[11]); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function testDatabase() |
174
|
|
|
{ |
175
|
|
|
$testcase = 'irpg-scoreboard.db'; |
176
|
|
|
$config = [ |
177
|
|
|
'bot_db' => __DIR__ . '/../testcases/' . $testcase, |
178
|
|
|
]; |
179
|
|
|
|
180
|
|
|
$parser = new BotParser($config); |
181
|
|
|
|
182
|
|
|
$db = $parser->getDatabase(); |
183
|
|
|
|
184
|
|
|
// Number of players |
185
|
|
|
$this->assertEquals(12, count($db)); |
186
|
|
|
|
187
|
|
|
// Test for invalid player |
188
|
|
|
$this->assertEquals(0, $parser->getDatabase('ZBR123')); |
189
|
|
|
|
190
|
|
|
$expectedUser = [ |
191
|
|
|
'nick' => 'fALSO', |
192
|
|
|
'level' => 43, |
193
|
|
|
'admin' => 'No', |
194
|
|
|
'class' => 'GLORIOSO', |
195
|
|
|
'ttl' => [ |
196
|
|
|
'display' => '3 days 12 hours', |
197
|
|
|
'numeric' => 304376, |
198
|
|
|
], |
199
|
|
|
'nick_host' => 'secret!secret@secret', |
200
|
|
|
'online' => 'Yes', |
201
|
|
|
'idled' => [ |
202
|
|
|
'display' => '2 weeks 5 days', |
203
|
|
|
'numeric' => 1675484, |
204
|
|
|
], |
205
|
|
|
'x_pos' => 259, |
206
|
|
|
'y_pos' => 390, |
207
|
|
|
'msg_pen' => [ |
208
|
|
|
'display' => '10 minutes 3 seconds', |
209
|
|
|
'numeric' => 603, |
210
|
|
|
], |
211
|
|
|
'nick_pen' => [ |
212
|
|
|
'display' => 'None', |
213
|
|
|
'numeric' => 0, |
214
|
|
|
], |
215
|
|
|
'part_pen' => [ |
216
|
|
|
'display' => 'None', |
217
|
|
|
'numeric' => 0, |
218
|
|
|
], |
219
|
|
|
'kick_pen' => [ |
220
|
|
|
'display' => 'None', |
221
|
|
|
'numeric' => 0, |
222
|
|
|
], |
223
|
|
|
'quit_pen' => [ |
224
|
|
|
'display' => 'None', |
225
|
|
|
'numeric' => 0, |
226
|
|
|
], |
227
|
|
|
'quest_pen' => [ |
228
|
|
|
'display' => 'None', |
229
|
|
|
'numeric' => 0, |
230
|
|
|
], |
231
|
|
|
'logout_pen' => [ |
232
|
|
|
'display' => 'None', |
233
|
|
|
'numeric' => 0, |
234
|
|
|
], |
235
|
|
|
'total_pen' => [ |
236
|
|
|
'display' => '10 minutes 3 seconds', |
237
|
|
|
'numeric' => 603, |
238
|
|
|
], |
239
|
|
|
'created' => [ |
240
|
|
|
'display' => '2018-06-20 22:58:00', |
241
|
|
|
'numeric' => 1529535480, |
242
|
|
|
], |
243
|
|
|
'last_login' => [ |
244
|
|
|
'display' => '2018-06-28 13:35:35', |
245
|
|
|
'numeric' => 1530192935, |
246
|
|
|
], |
247
|
|
|
'amulet' => [ |
248
|
|
|
'display' => '43', |
249
|
|
|
'numeric' => 43, |
250
|
|
|
'unique' => NULL, |
251
|
|
|
], |
252
|
|
|
'charm' => [ |
253
|
|
|
'display' => '40', |
254
|
|
|
'numeric' => 40, |
255
|
|
|
'unique' => NULL, |
256
|
|
|
], |
257
|
|
|
'helm' => [ |
258
|
|
|
'display' => '23', |
259
|
|
|
'numeric' => 23, |
260
|
|
|
'unique' => NULL, |
261
|
|
|
], |
262
|
|
|
'boots' => [ |
263
|
|
|
'display' => '27', |
264
|
|
|
'numeric' => 27, |
265
|
|
|
'unique' => NULL, |
266
|
|
|
], |
267
|
|
|
'gloves' => [ |
268
|
|
|
'display' => '30', |
269
|
|
|
'numeric' => 30, |
270
|
|
|
'unique' => NULL, |
271
|
|
|
], |
272
|
|
|
'ring' => [ |
273
|
|
|
'display' => '52h', |
274
|
|
|
'numeric' => 52, |
275
|
|
|
'unique' => 'Juliet\'s Glorious Ring of Sparkliness', |
276
|
|
|
], |
277
|
|
|
'leggings' => [ |
278
|
|
|
'display' => '21', |
279
|
|
|
'numeric' => 21, |
280
|
|
|
'unique' => NULL, |
281
|
|
|
], |
282
|
|
|
'shield' => [ |
283
|
|
|
'display' => '43', |
284
|
|
|
'numeric' => 43, |
285
|
|
|
'unique' => NULL, |
286
|
|
|
], |
287
|
|
|
'tunic' => [ |
288
|
|
|
'display' => '55', |
289
|
|
|
'numeric' => 55, |
290
|
|
|
'unique' => NULL, |
291
|
|
|
], |
292
|
|
|
'weapon' => [ |
293
|
|
|
'display' => '46', |
294
|
|
|
'numeric' => 46, |
295
|
|
|
'unique' => NULL, |
296
|
|
|
], |
297
|
|
|
'sum' => 380, |
298
|
|
|
'alignment' => 'Neutral', |
299
|
|
|
]; |
300
|
|
|
|
301
|
|
|
$this->assertEquals($expectedUser, $parser->getDatabase('fALSO')); |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
|