1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\FlexiPeeHP; |
4
|
|
|
|
5
|
|
|
use FlexiPeeHP\FlexiBeeRW; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-05-04 at 10:08:36. |
9
|
|
|
*/ |
10
|
|
|
class FlexiBeeRWTest extends FlexiBeeROTest |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Poznámka vkládaná do záznamů vytvářených během testů |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
public $poznam = 'Generováno UnitTestem PHP Knihovny https://github.com/Spoje-NET/FlexiPeeHP'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
public $insertableData = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var FlexiBeeRW |
26
|
|
|
*/ |
27
|
|
|
protected $object; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Gives You data able to insert into current evidence |
31
|
|
|
* |
32
|
|
|
* @param string $code custom record code |
33
|
|
|
* |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
public function getDataForInsert($code = 'UnitTest') |
37
|
|
|
{ |
38
|
|
|
$dataForInsert = []; |
39
|
|
|
$structure = $this->object->getColumnsInfo(); |
40
|
|
|
if (count($structure)) { |
41
|
|
|
if (array_key_exists('typDokl', $structure)) { |
42
|
|
|
if ($structure['typDokl']['type'] == 'relation') { |
43
|
|
|
$relatedEvidence = basename($structure['typDokl']['url']); |
44
|
|
|
$loader = new \FlexiPeeHP\FlexiBeeRO(null, |
45
|
|
|
['evidence' => $relatedEvidence]); |
46
|
|
|
$typDoklRaw = $loader->getColumnsFromFlexibee([ |
47
|
|
|
'kod'], ['limit' => 1]); |
48
|
|
|
$dataForInsert['typDokl'] = \FlexiPeeHP\FlexiBeeRO::code($typDoklRaw[0]['kod']); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
if (array_key_exists('poznam', $structure)) { |
52
|
|
|
$dataForInsert['poznam'] = $this->poznam.' '.$code; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (array_key_exists('nazev', $structure)) { |
56
|
|
|
$dataForInsert['nazev'] = $code.' '.$this->poznam.' '; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (array_key_exists('kod', $structure)) { |
60
|
|
|
$dataForInsert['kod'] = \FlexiPeeHP\FlexiBeeRO::uncode($this->object->getKod($code)); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
return $dataForInsert; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Sets up the fixture, for example, opens a network connection. |
68
|
|
|
* This method is called before a test is executed. |
69
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::__construct |
70
|
|
|
*/ |
71
|
|
|
protected function setUp() |
72
|
|
|
{ |
73
|
|
|
$this->object = new FlexiBeeRW(null, |
74
|
|
|
['atomic' => false, 'debug' => false]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Tears down the fixture, for example, closes a network connection. |
79
|
|
|
* This method is called after a test is executed. |
80
|
|
|
*/ |
81
|
|
|
protected function tearDown() |
82
|
|
|
{ |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::performAction |
88
|
|
|
* @expectedException \Exception |
89
|
|
|
*/ |
90
|
|
|
public function testPerformAction() |
91
|
|
|
{ |
92
|
|
|
$actions = $this->object->getActionsInfo(); |
93
|
|
|
|
94
|
|
|
if (count($actions)) { |
95
|
|
|
if (array_key_exists('new', $actions)) { |
96
|
|
|
$this->object->performAction('new', 'ext'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if (array_key_exists('storno', $actions)) { |
100
|
|
|
$this->object->insertToFlexiBee($this->getDataForInsert('StornoTest_'.time())); |
101
|
|
|
$this->object->performAction('storno', 'int'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
$this->object->performAction('nonexitst'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::timestampToFlexiDate |
109
|
|
|
*/ |
110
|
|
|
public function testTimestampToFlexiDate() |
111
|
|
|
{ |
112
|
|
|
$this->assertNull($this->object->timestampToFlexiDate()); |
113
|
|
|
$this->assertEquals('2016-09-16', |
114
|
|
|
$this->object->timestampToFlexiDate('1474040506')); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::timestampToFlexiDateTime |
119
|
|
|
*/ |
120
|
|
|
public function testTimestampToFlexiDateTime() |
121
|
|
|
{ |
122
|
|
|
$this->assertNull($this->object->timestampToFlexiDateTime()); |
123
|
|
|
$flexiDateTime = $this->object->timestampToFlexiDateTime('1474040506'); |
124
|
|
|
$this->assertEquals('2016-09-16', substr($flexiDateTime, 0, 10)); |
125
|
|
|
$this->assertEquals(':41:46', substr($flexiDateTime, -6)); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::objectToID |
130
|
|
|
*/ |
131
|
|
|
public function testObjectToID() |
132
|
|
|
{ |
133
|
|
|
$id = \Ease\Sand::randomNumber(1, 9999); |
134
|
|
|
$this->object->setMyKey($id); |
|
|
|
|
135
|
|
|
$this->assertEquals([$id], $this->object->objectToID([$this->object])); |
136
|
|
|
parent::testObjectToID(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::getRecordID |
141
|
|
|
*/ |
142
|
|
|
public function testGetRecordID() |
143
|
|
|
{ |
144
|
|
|
parent::testGetRecordID(); |
145
|
|
|
$structure = $this->object->getEvidenceInfo(); |
146
|
|
|
if (count($structure) && array_key_exists('kod', $structure)) { |
147
|
|
|
$this->object->setData(['kod' => 'KOD']); |
148
|
|
|
$this->assertEquals('code:KOD', $this->object->getRecordID()); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::controlMandatoryColumns |
154
|
|
|
*/ |
155
|
|
|
public function testControlMandatoryColumns() |
156
|
|
|
{ |
157
|
|
|
$this->object->controlMandatoryColumns(); |
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::controlReadOnlyColumns |
162
|
|
|
*/ |
163
|
|
|
public function testControlReadOnlyColumns() |
164
|
|
|
{ |
165
|
|
|
$this->object->controlReadOnlyColumns(['id' => 1]); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::addArrayToBranch |
170
|
|
|
*/ |
171
|
|
|
public function testAddArrayToBranch() |
172
|
|
|
{ |
173
|
|
|
$this->object->addArrayToBranch(['nazev' => 'test'], 'podEvidence'); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::addObjectToBranch |
178
|
|
|
*/ |
179
|
|
|
public function testAddObjectToBranch() |
180
|
|
|
{ |
181
|
|
|
$this->object->addObjectToBranch(new \FlexiPeeHP\FakturaVydanaPolozka(['nazev' => 'test'])); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::vazbaAdd |
186
|
|
|
*/ |
187
|
|
|
public function testVazbaAdd() |
188
|
|
|
{ |
189
|
|
|
$this->object->vazbaAdd(\Ease\Sand::randomNumber()); |
|
|
|
|
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::vazbaDel |
194
|
|
|
*/ |
195
|
|
|
public function testVazbaDel() |
196
|
|
|
{ |
197
|
|
|
$this->object->vazbaDel(\Ease\Sand::randomNumber()); |
|
|
|
|
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::getJsonizedData |
202
|
|
|
*/ |
203
|
|
|
public function testGetJsonizedData() |
204
|
|
|
{ |
205
|
|
|
$this->object->setData(['id' => time(), 'nazev' => \Ease\Sand::randomString(), |
206
|
|
|
'stitky' => ['TEST', 'TESTING']]); |
207
|
|
|
$this->object->getJsonizedData(); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::refresh |
212
|
|
|
*/ |
213
|
|
|
public function testRefresh() |
214
|
|
|
{ |
215
|
|
|
$this->object->setMyKey('ext:test:'.\Ease\Sand::randomNumber()); |
216
|
|
|
$this->object->refresh(); |
|
|
|
|
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::insertToFlexiBee |
221
|
|
|
*/ |
222
|
|
|
public function testInsertToFlexiBee() |
223
|
|
|
{ |
224
|
|
|
$this->object->insertToFlexiBee(['id' => 'ext:test:'.time()]); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::parseResponse |
229
|
|
|
*/ |
230
|
|
|
public function testParseResponse() |
231
|
|
|
{ |
232
|
|
|
$responseDecoded = array( |
233
|
|
|
'@version' => '1.0', |
234
|
|
|
'success' => 'true', |
235
|
|
|
'stats' => |
236
|
|
|
array( |
237
|
|
|
'created' => '1', |
238
|
|
|
'updated' => '5', |
239
|
|
|
'deleted' => '0', |
240
|
|
|
'skipped' => '0', |
241
|
|
|
'failed' => '0', |
242
|
|
|
), |
243
|
|
|
'results' => |
244
|
|
|
array( |
245
|
|
|
0 => |
246
|
|
|
array( |
247
|
|
|
'id' => '792', |
248
|
|
|
'request-id' => 'EXT:APP:100', |
249
|
|
|
'ref' => '/c/flexipeehp/adresar/792', |
250
|
|
|
), |
251
|
|
|
1 => |
252
|
|
|
array( |
253
|
|
|
'id' => '793', |
254
|
|
|
'request-id' => 'EXT:APP:200', |
255
|
|
|
'ref' => '/c/flexipeehp/adresar/793', |
256
|
|
|
), |
257
|
|
|
2 => |
258
|
|
|
array( |
259
|
|
|
'id' => '794', |
260
|
|
|
'request-id' => 'EXT:APP:300', |
261
|
|
|
'ref' => '/c/flexipeehp/adresar/794', |
262
|
|
|
), |
263
|
|
|
3 => |
264
|
|
|
array( |
265
|
|
|
'id' => '795', |
266
|
|
|
'request-id' => 'EXT:APP:400', |
267
|
|
|
'ref' => '/c/flexipeehp/adresar/795', |
268
|
|
|
), |
269
|
|
|
4 => |
270
|
|
|
array( |
271
|
|
|
'id' => '830', |
272
|
|
|
'request-id' => 'EXT:APP:500', |
273
|
|
|
'ref' => '/c/flexipeehp/banka/830', |
274
|
|
|
), |
275
|
|
|
5 => |
276
|
|
|
array( |
277
|
|
|
'id' => '28', |
278
|
|
|
'ref' => '/c/flexipeehp/adresar-bankovni-ucet/28', |
279
|
|
|
), |
280
|
|
|
), |
281
|
|
|
) |
282
|
|
|
; |
283
|
|
|
$this->object->parseResponse($responseDecoded, 201); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::assignResultIDs |
288
|
|
|
*/ |
289
|
|
|
public function testAssignResultIDs() |
290
|
|
|
{ |
291
|
|
|
$ids = array( |
292
|
|
|
'adresar' => |
293
|
|
|
array( |
294
|
|
|
'EXT:APP:100' => '792', |
295
|
|
|
'EXT:APP:200' => '793', |
296
|
|
|
'EXT:APP:300' => '794', |
297
|
|
|
'EXT:APP:400' => '795', |
298
|
|
|
), |
299
|
|
|
'banka' => |
300
|
|
|
array( |
301
|
|
|
'EXT:APP:500' => '830', |
302
|
|
|
), |
303
|
|
|
'adresar-bankovni-ucet' => |
304
|
|
|
array( |
305
|
|
|
'' => '27', |
306
|
|
|
), |
307
|
|
|
); |
308
|
|
|
$this->object->assignResultIDs($ids); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::extractResultIDs |
313
|
|
|
*/ |
314
|
|
|
public function testExtractResultIDs() |
315
|
|
|
{ |
316
|
|
|
$resultInfo = array( |
317
|
|
|
0 => |
318
|
|
|
array( |
319
|
|
|
'id' => '792', |
320
|
|
|
'request-id' => 'EXT:APP:100', |
321
|
|
|
'ref' => '/c/flexipeehp/adresar/792', |
322
|
|
|
), |
323
|
|
|
1 => |
324
|
|
|
array( |
325
|
|
|
'id' => '793', |
326
|
|
|
'request-id' => 'EXT:APP:200', |
327
|
|
|
'ref' => '/c/flexipeehp/adresar/793', |
328
|
|
|
), |
329
|
|
|
2 => |
330
|
|
|
array( |
331
|
|
|
'id' => '794', |
332
|
|
|
'request-id' => 'EXT:APP:300', |
333
|
|
|
'ref' => '/c/flexipeehp/adresar/794', |
334
|
|
|
), |
335
|
|
|
3 => |
336
|
|
|
array( |
337
|
|
|
'id' => '795', |
338
|
|
|
'request-id' => 'EXT:APP:400', |
339
|
|
|
'ref' => '/c/flexipeehp/adresar/795', |
340
|
|
|
), |
341
|
|
|
4 => |
342
|
|
|
array( |
343
|
|
|
'id' => '830', |
344
|
|
|
'request-id' => 'EXT:APP:500', |
345
|
|
|
'ref' => '/c/flexipeehp/banka/830', |
346
|
|
|
), |
347
|
|
|
5 => |
348
|
|
|
array( |
349
|
|
|
'id' => '26', |
350
|
|
|
'ref' => '/c/flexipeehp/adresar-bankovni-ucet/26', |
351
|
|
|
), |
352
|
|
|
); |
353
|
|
|
$this->object->extractResultIDs($resultInfo); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::getLastInsertedId |
358
|
|
|
*/ |
359
|
|
|
public function testGetLastInsertedId() |
360
|
|
|
{ |
361
|
|
|
$this->object->getLastInsertedId(); |
|
|
|
|
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::deleteFromFlexiBee |
366
|
|
|
*/ |
367
|
|
|
public function testDeleteFromFlexiBee() |
368
|
|
|
{ |
369
|
|
|
$this->object->deleteFromFlexiBee(); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::takeData |
374
|
|
|
*/ |
375
|
|
|
public function testTakeData() |
376
|
|
|
{ |
377
|
|
|
$this->object->takeData(['id' => \Ease\Sand::randomNumber()]); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @after |
382
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::getDataForJSON |
383
|
|
|
*/ |
384
|
|
|
public function testGetDataForJSON() |
385
|
|
|
{ |
386
|
|
|
$this->object->setData(['name' => 'test']); |
387
|
|
|
$this->object->getDataForJSON(); |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::addExternalID |
392
|
|
|
*/ |
393
|
|
|
public function testAddExternalID() |
394
|
|
|
{ |
395
|
|
|
if (empty($this->object->getEvidence())) { |
396
|
|
|
$this->object->setEvidence('banka'); |
397
|
|
|
} |
398
|
|
|
$this->object->addExternalID('ext:test:'.\Ease\Sand::randomNumber()); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::changeExternalID |
403
|
|
|
*/ |
404
|
|
|
public function testChangeExternalID() |
405
|
|
|
{ |
406
|
|
|
$this->object->changeExternalID('test', \Ease\Sand::randomNumber(), |
|
|
|
|
407
|
|
|
\Ease\Sand::randomNumber()); |
|
|
|
|
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* @covers FlexiPeeHP\FlexiBeeRW::sync |
412
|
|
|
*/ |
413
|
|
|
public function testSync() |
414
|
|
|
{ |
415
|
|
|
$code = \Ease\Sand::randomString(); |
416
|
|
|
$this->assertFalse($this->object->sync(['kod' => $code.'X'])); |
417
|
|
|
if ($this->object->getEvidence()) { |
418
|
|
|
$syncResult = $this->object->sync($this->getDataForInsert($code)); |
419
|
|
|
$this->assertTrue($syncResult); |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
|
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.