1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\FlexiPeeHP; |
4
|
|
|
|
5
|
|
|
use FlexiPeeHP\FlexiBeeRO; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-05-04 at 10:08:36. |
9
|
|
|
*/ |
10
|
|
|
class FlexiBeeROTest extends \Test\Ease\BrickTest |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var FlexiBeeRO |
14
|
|
|
*/ |
15
|
|
|
protected $object; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Sets up the fixture, for example, opens a network connection. |
19
|
|
|
* This method is called before a test is executed. |
20
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::__construct |
21
|
|
|
*/ |
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->object = new FlexiBeeRO(); |
25
|
|
|
$this->object->prefix = ''; |
26
|
|
|
$this->object->company = ''; |
27
|
|
|
$this->object->debug = true; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Tears down the fixture, for example, closes a network connection. |
32
|
|
|
* This method is called after a test is executed. |
33
|
|
|
*/ |
34
|
|
|
protected function tearDown() |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testConstructor() |
40
|
|
|
{ |
41
|
|
|
$classname = get_class($this->object); |
42
|
|
|
$evidence = $this->object->getEvidence(); |
43
|
|
|
|
44
|
|
|
// Get mock, without the constructor being called |
45
|
|
|
$mock = $this->getMockBuilder($classname) |
46
|
|
|
->disableOriginalConstructor() |
47
|
|
|
->getMockForAbstractClass(); |
48
|
|
|
$mock->__construct(''); |
49
|
|
|
|
50
|
|
|
if (!isset(\FlexiPeeHP\EvidenceList::$name[$evidence])) { |
51
|
|
|
$evidence = 'adresar'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$mock->__construct('', |
55
|
|
|
[ |
56
|
|
|
'company' => 'Firma_s_r_o_', |
57
|
|
|
'url' => 'https://flexibee.firma.cz/', |
58
|
|
|
'user' => 'rest', |
59
|
|
|
'password' => '-dj3x21xaA_', |
60
|
|
|
'debug' => true, |
61
|
|
|
'prefix' => 'c', |
62
|
|
|
'evidence' => $evidence]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::curlInit |
67
|
|
|
*/ |
68
|
|
|
public function testCurlInit() |
69
|
|
|
{ |
70
|
|
|
$this->object->curlInit(); |
71
|
|
|
$this->assertTrue(is_resource($this->object->curl)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::processInit |
76
|
|
|
*/ |
77
|
|
|
public function testProcessInit() |
78
|
|
|
{ |
79
|
|
|
$this->object->processInit(['id' => 1]); |
80
|
|
|
$this->assertEquals(1, $this->object->getDataValue('id')); |
81
|
|
|
if (!is_null($this->object->evidence) && $this->object->evidence != 'test') { |
82
|
|
|
$firstID = $this->object->getColumnsFromFlexibee('id', |
|
|
|
|
83
|
|
|
['limit' => 1]); |
84
|
|
|
|
85
|
|
|
if (count($firstID)) { |
86
|
|
|
|
87
|
|
|
$this->object->processInit((int) current($firstID)); |
88
|
|
|
$this->assertNotEmpty($this->object->__toString()); |
89
|
|
|
|
90
|
|
|
if (isset($firstID[0]['kod'])) { |
91
|
|
|
$this->object->processInit('code:'.$firstID[0]['kod']); |
92
|
|
|
$this->assertNotEmpty($this->object->__toString()); |
93
|
|
|
} |
94
|
|
|
} else { |
95
|
|
|
$this->markTestSkipped(sprintf('Evidence %s doed not contain first record', |
96
|
|
|
$this->object->getEvidence())); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @covers FlexiPeeHP\Flexi/home/vitex/Projects/Spoje.Net/flexipeehp/testing/src/FlexiPeeHP/FlexiBeeROTest.php:86BeeRO::setUp |
103
|
|
|
*/ |
104
|
|
|
public function testSetUp() |
105
|
|
|
{ |
106
|
|
|
$this->object->setUp( |
107
|
|
|
[ |
108
|
|
|
'company' => 'cmp', |
109
|
|
|
'url' => 'url', |
110
|
|
|
'user' => 'usr', |
111
|
|
|
'password' => 'pwd', |
112
|
|
|
'prefix' => 'c', |
113
|
|
|
'debug' => true, |
114
|
|
|
'evidence' => 'smlouva' |
115
|
|
|
] |
116
|
|
|
); |
117
|
|
|
$this->assertEquals('cmp', $this->object->company); |
118
|
|
|
$this->assertEquals('url', $this->object->url); |
119
|
|
|
$this->assertEquals('usr', $this->object->user); |
120
|
|
|
$this->assertEquals('/c/', $this->object->prefix); |
121
|
|
|
$this->assertEquals('pwd', $this->object->password); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::setPrefix |
126
|
|
|
* @expectedException \Exception |
127
|
|
|
*/ |
128
|
|
|
public function testSetPrefix() |
129
|
|
|
{ |
130
|
|
|
$this->object->setPrefix('c'); |
131
|
|
|
$this->assertEquals('/c/', $this->object->prefix); |
132
|
|
|
$this->object->setPrefix(null); |
133
|
|
|
$this->assertEquals('', $this->object->prefix); |
134
|
|
|
$this->object->setPrefix('fail'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::setFormat |
139
|
|
|
*/ |
140
|
|
|
public function testSetFormat() |
141
|
|
|
{ |
142
|
|
|
$this->object->setFormat('xml'); |
143
|
|
|
$this->assertEquals('xml', $this->object->format); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* We can set only evidence defined in EvidenceList class |
148
|
|
|
* |
149
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::setEvidence |
150
|
|
|
* @expectedException \Exception |
151
|
|
|
*/ |
152
|
|
|
public function testSetEvidence() |
153
|
|
|
{ |
154
|
|
|
$this->object->setEvidence('adresar'); |
155
|
|
|
$this->assertEquals('adresar', $this->object->evidence); |
156
|
|
|
$this->object->setPrefix('c'); |
157
|
|
|
$this->object->setEvidence('fail'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::setCompany |
162
|
|
|
*/ |
163
|
|
|
public function testSetCompany() |
164
|
|
|
{ |
165
|
|
|
$this->object->setCompany('test_s_r_o_'); |
166
|
|
|
$this->assertEquals('test_s_r_o_', $this->object->company); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::object2array |
171
|
|
|
*/ |
172
|
|
|
public function testObject2array() |
173
|
|
|
{ |
174
|
|
|
$this->assertNull($this->object->object2array(new \stdClass())); |
175
|
|
|
$this->assertEquals( |
176
|
|
|
[ |
177
|
|
|
'item' => 1, |
178
|
|
|
'arrItem' => ['a', 'b' => 'c'] |
179
|
|
|
] |
180
|
|
|
, $this->object->object2array(new \Test\ObjectForTesting())); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::objectToID |
185
|
|
|
*/ |
186
|
|
|
public function testObjectToID() |
187
|
|
|
{ |
188
|
|
|
$id = \Ease\Sand::randomNumber(1, 9999); |
189
|
|
|
$this->object->setMyKey($id); |
|
|
|
|
190
|
|
|
$this->assertEquals([$id], $this->object->objectToID([$this->object])); |
191
|
|
|
|
192
|
|
|
$this->object->setDataValue('kod', 'TEST'); |
193
|
|
|
$this->assertEquals('code:TEST', |
194
|
|
|
$this->object->objectToID($this->object)); |
195
|
|
|
|
196
|
|
|
$this->assertEquals('TEST', $this->object->objectToID('TEST')); |
|
|
|
|
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::performRequest |
201
|
|
|
*/ |
202
|
|
|
public function testPerformRequest() |
203
|
|
|
{ |
204
|
|
|
$evidence = $this->object->getEvidence(); |
205
|
|
|
switch ($evidence) { |
206
|
|
|
case null: |
207
|
|
|
case '': |
208
|
|
|
case 'test': |
209
|
|
|
case 'c': |
210
|
|
|
$this->markTestSkipped('Evidence not set'); |
211
|
|
|
break; |
212
|
|
|
|
213
|
|
|
default: |
214
|
|
|
$json = $this->object->performRequest($evidence.'.json'); |
215
|
|
|
if (array_key_exists('message', $json)) { |
216
|
|
|
$this->assertArrayHasKey('@version', $json); |
217
|
|
|
} else { |
218
|
|
|
$this->assertArrayHasKey($evidence, $json); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
$xml = $this->object->performRequest(null, 'GET', 'xml'); |
222
|
|
|
$this->assertArrayHasKey('companies', $xml); |
223
|
|
|
|
224
|
|
|
break; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
//404 Test |
228
|
|
|
$this->assertNull($this->object->performRequest('error404.json')); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::setAction |
233
|
|
|
*/ |
234
|
|
|
public function testSetAction() |
235
|
|
|
{ |
236
|
|
|
if (empty($this->object->evidence) || ($this->object->evidence == 'c')) { |
237
|
|
|
$this->markTestSkipped('no evidence set'); |
238
|
|
|
} else { |
239
|
|
|
$this->assertTrue($this->object->setAction('new')); |
240
|
|
|
$this->object->actionsAvailable = []; |
241
|
|
|
$this->assertFalse($this->object->setAction('none')); |
242
|
|
|
$this->object->actionsAvailable = ['copy']; |
243
|
|
|
$this->assertFalse($this->object->setAction('none')); |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getEvidence |
249
|
|
|
*/ |
250
|
|
|
public function testGetEvidence() |
251
|
|
|
{ |
252
|
|
|
$this->assertEquals($this->object->evidence, |
253
|
|
|
$this->object->getEvidence()); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getCompany |
258
|
|
|
*/ |
259
|
|
|
public function testGetCompany() |
260
|
|
|
{ |
261
|
|
|
$this->assertEquals($this->object->company, $this->object->getCompany()); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getResponseEvidence |
266
|
|
|
*/ |
267
|
|
|
public function testGetResponseEvidence() |
268
|
|
|
{ |
269
|
|
|
$this->assertEquals($this->object->getEvidence(), |
270
|
|
|
$this->object->getResponseEvidence()); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId |
275
|
|
|
* @depends testInsertToFlexiBee |
276
|
|
|
*/ |
277
|
|
|
public function testGetLastInsertedId() |
278
|
|
|
{ |
279
|
|
|
$this->assertNotEmpty($this->object->getLastInsertedId()); |
|
|
|
|
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::xml2array |
284
|
|
|
*/ |
285
|
|
|
public function testXml2array() |
286
|
|
|
{ |
287
|
|
|
$xml = '<card xmlns="http://businesscard.org"> |
288
|
|
|
<name>John Doe</name> |
289
|
|
|
<title>CEO, Widget Inc.</title> |
290
|
|
|
<email>[email protected]</email> |
291
|
|
|
<phone>(202) 456-1414</phone> |
292
|
|
|
<logo url="widget.gif"/> |
293
|
|
|
<a><b>c</b></a> |
294
|
|
|
</card>'; |
295
|
|
|
|
296
|
|
|
$data = ['name' => 'John Doe', 'title' => 'CEO, Widget Inc.', 'email' => '[email protected]', |
297
|
|
|
'phone' => '(202) 456-1414', 'logo' => '', 'a' => [['b' => 'c']]]; |
298
|
|
|
|
299
|
|
|
|
300
|
|
|
$this->assertEquals($data, $this->object->xml2array($xml)); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::disconnect |
305
|
|
|
* |
306
|
|
|
* @depends testPerformRequest |
307
|
|
|
* @depends testLoadFlexiData |
308
|
|
|
* @depends testGetFlexiRow |
309
|
|
|
* @depends testGetFlexiData |
310
|
|
|
* @depends testLoadFromFlexiBee |
311
|
|
|
* @depends testInsertToFlexiBee |
312
|
|
|
* @depends testIdExists |
313
|
|
|
* @depends testRecordExists |
314
|
|
|
* @depends testGetColumnsFromFlexibee |
315
|
|
|
* @depends testSearchString |
316
|
|
|
*/ |
317
|
|
|
public function testDisconnect() |
318
|
|
|
{ |
319
|
|
|
$this->object->disconnect(); |
320
|
|
|
$this->assertNull($this->object->curl); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::__destruct |
325
|
|
|
* @depends testDisconnect |
326
|
|
|
*/ |
327
|
|
|
public function testdestruct() |
328
|
|
|
{ |
329
|
|
|
$this->markTestSkipped(); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow |
334
|
|
|
*/ |
335
|
|
|
public function testGetFlexiRow() |
336
|
|
|
{ |
337
|
|
|
$this->object->getFlexiRow(0); |
338
|
|
|
$this->object->getFlexiRow(1); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getFlexiData |
343
|
|
|
*/ |
344
|
|
|
public function testGetFlexiData() |
345
|
|
|
{ |
346
|
|
|
$evidence = $this->object->getEvidence(); |
347
|
|
|
|
348
|
|
|
switch ($evidence) { |
349
|
|
|
case null: |
350
|
|
|
$this->markTestSkipped('Unsupported evidence'); |
351
|
|
|
break; |
352
|
|
|
case 'c': |
353
|
|
|
$this->object->evidence = 'c'; |
354
|
|
|
$this->object->prefix = ''; |
355
|
|
|
$this->object->company = ''; |
356
|
|
|
$this->object->nameSpace = 'companies'; |
357
|
|
|
$flexidata = $this->object->getFlexiData(); |
358
|
|
|
$this->assertArrayHasKey('company', $flexidata); |
359
|
|
|
break; |
360
|
|
|
|
361
|
|
|
default: |
362
|
|
|
$flexidata = $this->object->getFlexiData(); |
363
|
|
View Code Duplication |
if (is_array($flexidata) && !count($flexidata)) { |
|
|
|
|
364
|
|
|
$this->markTestSkipped('Empty evidence'); |
365
|
|
|
} else { |
366
|
|
|
$this->assertArrayHasKey(0, $flexidata); |
367
|
|
|
$this->assertArrayHasKey('id', $flexidata[0]); |
368
|
|
|
$filtrered = $this->object->getFlexiData(null, |
369
|
|
|
"id = ".$flexidata[0]['id']); |
370
|
|
|
$this->assertArrayHasKey(0, $filtrered); |
371
|
|
|
$this->assertArrayHasKey('id', $filtrered[0]); |
372
|
|
|
} |
373
|
|
|
break; |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee |
379
|
|
|
*/ |
380
|
|
|
public function testLoadFromFlexiBee() |
381
|
|
|
{ |
382
|
|
|
$this->object->loadFromFlexiBee(); |
383
|
|
|
$this->object->loadFromFlexiBee(222); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::jsonizeData |
388
|
|
|
*/ |
389
|
|
|
public function testJsonizeData() |
390
|
|
|
{ |
391
|
|
|
$this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"}}}', |
392
|
|
|
$this->object->jsonizeData(['key' => 'value'])); |
393
|
|
|
|
394
|
|
|
if (!empty($this->object->evidence) && ($this->object->evidence != 'c')) { |
395
|
|
|
$this->object->setAction('copy'); |
396
|
|
|
$this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"},"'.$this->object->evidence.'@action":"copy"}}', |
397
|
|
|
$this->object->jsonizeData(['key' => 'value'])); |
398
|
|
|
} |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::idExists |
403
|
|
|
*/ |
404
|
|
|
public function testIdExists() |
405
|
|
|
{ |
406
|
|
|
// Remove the following lines when you implement this test. |
407
|
|
|
$this->markTestIncomplete( |
408
|
|
|
'This test has not been implemented yet.' |
409
|
|
|
); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getRecordID |
414
|
|
|
* @todo Implement testGetRecordID(). |
415
|
|
|
*/ |
416
|
|
|
public function testGetRecordID() |
417
|
|
|
{ |
418
|
|
|
// Remove the following lines when you implement this test. |
419
|
|
|
$this->markTestIncomplete( |
420
|
|
|
'This test has not been implemented yet.' |
421
|
|
|
); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::recordExists |
426
|
|
|
*/ |
427
|
|
|
public function testRecordExists() |
428
|
|
|
{ |
429
|
|
|
$evidence = $this->object->getEvidence(); |
430
|
|
|
|
431
|
|
|
switch ($evidence) { |
432
|
|
|
case null: |
433
|
|
|
case 'c': |
434
|
|
|
$this->markTestSkipped('Unsupported evidence'); |
435
|
|
|
break; |
436
|
|
|
|
437
|
|
|
default: |
438
|
|
|
$flexidata = $this->object->getFlexiData(null, ['limit' => 1]); |
439
|
|
|
if (is_array($flexidata) && !count($flexidata)) { |
440
|
|
|
$this->markTestSkipped('Empty evidence'); |
441
|
|
|
} else { |
442
|
|
|
if (isset($flexidata['success']) && ($flexidata['success'] == 'false')) { |
443
|
|
|
$this->markTestSkipped($flexidata['message']); |
444
|
|
|
} else { |
445
|
|
|
$this->object->setData(['id' => (int) $flexidata[0]['id']]); |
446
|
|
|
$this->assertTrue($this->object->recordExists(), |
447
|
|
|
'First record exists test failed'); |
448
|
|
|
$this->assertFalse($this->object->recordExists(['id' => 0]), |
449
|
|
|
'Record ID 0 exists'); |
450
|
|
|
$this->assertFalse($this->object->recordExists(['unexistent' => 1]), |
451
|
|
|
'Unexistent Record exist ?'); |
452
|
|
|
} |
453
|
|
|
} |
454
|
|
|
break; |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee |
460
|
|
|
*/ |
461
|
|
|
public function testGetColumnsFromFlexibee() |
462
|
|
|
{ |
463
|
|
|
// Remove the following lines when you implement this test. |
464
|
|
|
$this->markTestIncomplete( |
465
|
|
|
'This test has not been implemented yet.' |
466
|
|
|
); |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getExternalID |
471
|
|
|
* @todo Implement testGetExternalID(). |
472
|
|
|
*/ |
473
|
|
|
public function testGetExternalID() |
474
|
|
|
{ |
475
|
|
|
// Remove the following lines when you implement this test. |
476
|
|
|
$this->markTestIncomplete( |
477
|
|
|
'This test has not been implemented yet.' |
478
|
|
|
); |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getGlobalVersion |
483
|
|
|
* @todo Implement testGetGlobalVersion(). |
484
|
|
|
*/ |
485
|
|
|
public function testGetGlobalVersion() |
486
|
|
|
{ |
487
|
|
|
// Remove the following lines when you implement this test. |
488
|
|
|
$this->markTestIncomplete( |
489
|
|
|
'This test has not been implemented yet.' |
490
|
|
|
); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getResponseFormat |
495
|
|
|
* @todo Implement testGetResponseFormat(). |
496
|
|
|
*/ |
497
|
|
|
public function testGetResponseFormat() |
498
|
|
|
{ |
499
|
|
|
// Remove the following lines when you implement this test. |
500
|
|
|
$this->markTestIncomplete( |
501
|
|
|
'This test has not been implemented yet.' |
502
|
|
|
); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getKod |
507
|
|
|
*/ |
508
|
|
|
public function testGetKod() |
509
|
|
|
{ |
510
|
|
|
$testString = []; |
511
|
|
|
$this->assertEquals('CODE', |
512
|
|
|
$this->object->getKod([$this->object->myKeyColumn => 'code'])); |
513
|
|
|
|
514
|
|
|
$testString[$this->object->nameColumn] = 'Fish clamp - Úchytka pro instalaci samonosných kabelů ' |
515
|
|
|
.'(3.5 mm)'; |
516
|
|
|
$code0 = $this->object->getKod($testString); |
517
|
|
|
$this->assertEquals('FISHCLAMPUCHYTKAPR', $code0); |
518
|
|
|
$code1 = $this->object->getKod($testString, |
519
|
|
|
false); |
520
|
|
|
$this->assertEquals('FISHCLAMPUCHYTKAPR', $code1); |
521
|
|
|
$code2 = $this->object->getKod($testString); |
522
|
|
|
$this->assertEquals('FISHCLAMPUCHYTKAPR1', $code2); |
523
|
|
|
$this->object->setData($testString); |
524
|
|
|
$code3 = $this->object->getKod(); |
525
|
|
|
$this->assertEquals('FISHCLAMPUCHYTKAPR2', $code3); |
526
|
|
|
|
527
|
|
|
$this->assertEquals('TEST', |
528
|
|
|
$this->object->getKod([$this->object->nameColumn => 'test'])); |
529
|
|
|
|
530
|
|
|
$this->assertEquals('TEST1', $this->object->getKod('test')); |
531
|
|
|
|
532
|
|
|
$this->assertEquals('TEST2', $this->object->getKod(['kod' => 'test'])); |
533
|
|
|
$this->assertEquals('NOTSET', $this->object->getKod(['kod' => ''])); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
/** |
537
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::logResult |
538
|
|
|
*/ |
539
|
|
|
public function testLogResult() |
540
|
|
|
{ |
541
|
|
|
$this->object->cleanMessages(); |
542
|
|
|
$success = json_decode('{"winstrom":{"@version":"1.0","success":"true",' |
543
|
|
|
.'"stats":{"created":"0","updated":"1","deleted":"0","skipped":"0"' |
544
|
|
|
.',"failed":"0"},"results":[{"id":"1","request-id":"ext:SōkoMan.item' |
545
|
|
|
.':5271","ref":"/c/spoje_net_s_r_o_1/skladovy-pohyb/1.json"}]}}'); |
546
|
|
|
$this->object->logResult(current($this->object->object2array($success)), |
547
|
|
|
'http://test'); |
548
|
|
|
|
549
|
|
|
$this->assertArrayHasKey('info', $this->object->getStatusMessages(true)); |
550
|
|
|
|
551
|
|
|
$error = json_decode('{"winstrom":{"@version":"1.0","success":"false",' |
552
|
|
|
.'"stats":{"created":"0","updated":"0","deleted":"0","skipped":"0"' |
553
|
|
|
.',"failed":"0"},"results":[{"errors":[{"message":"cz.winstrom.' |
554
|
|
|
.'service.WSBusinessException: Zadaný kód není unikátní.\nZadaný' |
555
|
|
|
.' kód není unikátní."}]}]}}'); |
556
|
|
|
$this->object->lastResponseCode = 500; |
557
|
|
|
$this->object->logResult(current($this->object->object2array($error))); |
558
|
|
|
$this->assertArrayHasKey('error', $this->object->getStatusMessages(true)); |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
/** |
562
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::flexiUrl |
563
|
|
|
*/ |
564
|
|
|
public function testFlexiUrl() |
565
|
|
|
{ |
566
|
|
|
$this->assertEquals("a eq '1' and b eq 'foo'", |
567
|
|
|
$this->object->flexiUrl(['a' => 1, 'b' => 'foo'], 'and')); |
568
|
|
|
$this->assertEquals("a eq '1' or b eq 'bar'", |
569
|
|
|
$this->object->flexiUrl(['a' => 1, 'b' => 'bar'], 'or')); |
570
|
|
|
$this->assertEquals("a eq true or b eq false", |
571
|
|
|
$this->object->flexiUrl(['a' => true, 'b' => false], 'or')); |
572
|
|
|
$this->assertEquals("a is null and b is not null", |
573
|
|
|
$this->object->flexiUrl(['a' => null, 'b' => '!null'], 'and')); |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
/** |
577
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::unifyResponseFormat |
578
|
|
|
*/ |
579
|
|
|
public function testunifyResponseFormat() |
580
|
|
|
{ |
581
|
|
|
$this->assertNull($this->object->unifyResponseFormat(null)); |
|
|
|
|
582
|
|
|
//One Row Test |
583
|
|
|
|
584
|
|
|
$responseEvidence = $this->object->getResponseEvidence(); |
585
|
|
|
if (empty($responseEvidence)) { |
586
|
|
|
$responseEvidence = $this->object->evidence = 'test'; |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
$test1raw = [$responseEvidence => |
590
|
|
|
['id' => 1, 'name' => 'value'] |
591
|
|
|
]; |
592
|
|
|
|
593
|
|
|
$test1expected = [$responseEvidence => |
594
|
|
|
[ |
595
|
|
|
['id' => 1, 'name' => 'value'] |
596
|
|
|
] |
597
|
|
|
]; |
598
|
|
|
|
599
|
|
|
$this->assertEquals($test1expected, |
600
|
|
|
$this->object->unifyResponseFormat($test1raw)); |
601
|
|
|
|
602
|
|
|
//Two Row Test |
603
|
|
|
$test2Raw = [$this->object->getResponseEvidence() => |
604
|
|
|
[ |
605
|
|
|
['id' => 1, 'name' => 'value'], |
606
|
|
|
['id' => 2, 'name' => 'value2'] |
607
|
|
|
] |
608
|
|
|
]; |
609
|
|
|
|
610
|
|
|
$test2expected = [$this->object->getResponseEvidence() => |
611
|
|
|
[ |
612
|
|
|
['id' => 1, 'name' => 'value'], |
613
|
|
|
['id' => 2, 'name' => 'value2'] |
614
|
|
|
] |
615
|
|
|
]; |
616
|
|
|
|
617
|
|
|
$this->assertEquals($test2expected, |
618
|
|
|
$this->object->unifyResponseFormat($test2Raw)); |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
/** |
622
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::__toString |
623
|
|
|
*/ |
624
|
|
|
public function testtoString() |
625
|
|
|
{ |
626
|
|
|
|
627
|
|
|
$identifer = 'ext:test:123'; |
628
|
|
|
$this->object->setDataValue('id', $identifer); |
629
|
|
|
$this->assertEquals($identifer, (string) $this->object); |
630
|
|
|
|
631
|
|
|
$code = 'test'; |
632
|
|
|
$this->object->setDataValue('kod', $code); |
633
|
|
|
$this->assertEquals('code:'.$code, (string) $this->object); |
634
|
|
|
|
635
|
|
|
$this->object->dataReset(); |
636
|
|
|
$this->assertEquals('', $this->object->__toString()); |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::draw |
641
|
|
|
*/ |
642
|
|
|
public function testDraw($whatWant = NULL) |
643
|
|
|
{ |
644
|
|
|
$this->object->setDataValue('kod', 'test'); |
645
|
|
|
$this->assertEquals('code:test', $this->object->draw()); |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getColumnsInfo |
650
|
|
|
*/ |
651
|
|
View Code Duplication |
public function testgetColumnsInfo() |
|
|
|
|
652
|
|
|
{ |
653
|
|
|
switch ($this->object->getEvidence()) { |
654
|
|
|
case '': |
655
|
|
|
case 'c': |
656
|
|
|
case 'hooks': |
657
|
|
|
case 'changes': |
658
|
|
|
case 'nastaveni': |
659
|
|
|
$this->assertNull($this->object->getColumnsInfo()); |
660
|
|
|
$this->assertNotEmpty($this->object->getColumnsInfo('faktura-vydana'), |
661
|
|
|
'Cannot obtain structure for na evidence'); |
662
|
|
|
break; |
663
|
|
|
default: |
664
|
|
|
$this->assertNotEmpty($this->object->getColumnsInfo(), |
665
|
|
|
'Cannot obtain structure for '.$this->object->getEvidence()); |
666
|
|
|
break; |
667
|
|
|
} |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getActionsInfo |
672
|
|
|
*/ |
673
|
|
View Code Duplication |
public function testgetActionsInfo() |
|
|
|
|
674
|
|
|
{ |
675
|
|
|
switch ($this->object->getEvidence()) { |
676
|
|
|
case '': |
677
|
|
|
case 'c': |
678
|
|
|
case 'hooks': |
679
|
|
|
case 'changes': |
680
|
|
|
case 'nastaveni': |
681
|
|
|
$this->assertNull($this->object->getActionsInfo()); |
682
|
|
|
$this->assertNotEmpty($this->object->getActionsInfo('faktura-vydana'), |
683
|
|
|
'Cannot obtain actions for na evidence'); |
684
|
|
|
break; |
685
|
|
|
default: |
686
|
|
|
$this->assertNotEmpty($this->object->getActionsInfo(), |
687
|
|
|
'Cannot obtain actions for '.$this->object->getEvidence()); |
688
|
|
|
break; |
689
|
|
|
} |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getRelationsInfo |
694
|
|
|
*/ |
695
|
|
View Code Duplication |
public function testgetRelationsInfo() |
|
|
|
|
696
|
|
|
{ |
697
|
|
|
switch ($this->object->getEvidence()) { |
698
|
|
|
case '': |
699
|
|
|
case 'c': |
700
|
|
|
case 'hooks': |
701
|
|
|
case 'changes': |
702
|
|
|
case 'nastaveni': |
703
|
|
|
$this->assertNull($this->object->getRelationsInfo()); |
704
|
|
|
$this->assertNotEmpty($this->object->getRelationsInfo('faktura-vydana'), |
705
|
|
|
'Cannot obtain relations for na evidence'); |
706
|
|
|
break; |
707
|
|
|
default: |
708
|
|
|
$this->assertNotEmpty($this->object->getRelationsInfo(), |
709
|
|
|
'Cannot obtain relations for '.$this->object->getEvidence()); |
710
|
|
|
break; |
711
|
|
|
} |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getEvidenceUrl |
716
|
|
|
*/ |
717
|
|
|
public function testgetEvidenceUrl() |
718
|
|
|
{ |
719
|
|
|
$this->assertNotEmpty($this->object->getEvidenceUrl()); |
720
|
|
|
$this->assertNotEmpty($this->object->getEvidenceUrl('/properties')); |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
/** |
724
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::evidenceToClassName |
725
|
|
|
*/ |
726
|
|
|
public function testevidenceToClassName() |
727
|
|
|
{ |
728
|
|
|
$this->assertEquals('FakturaVydana', |
729
|
|
|
$this->object->evidenceToClassName('faktura-vydana')); |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
/** |
733
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getEvidenceInfo |
734
|
|
|
* @todo Implement testGetEvidenceInfo(). |
735
|
|
|
*/ |
736
|
|
|
public function testGetEvidenceInfo() |
737
|
|
|
{ |
738
|
|
|
// Remove the following lines when you implement this test. |
739
|
|
|
$this->markTestIncomplete( |
740
|
|
|
'This test has not been implemented yet.' |
741
|
|
|
); |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
/** |
745
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getEvidenceName |
746
|
|
|
* @todo Implement testGetEvidenceName(). |
747
|
|
|
*/ |
748
|
|
|
public function testGetEvidenceName() |
749
|
|
|
{ |
750
|
|
|
// Remove the following lines when you implement this test. |
751
|
|
|
$this->markTestIncomplete( |
752
|
|
|
'This test has not been implemented yet.' |
753
|
|
|
); |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
/** |
757
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::performAction |
758
|
|
|
* @todo Implement testPerformAction(). |
759
|
|
|
*/ |
760
|
|
|
public function testPerformAction() |
761
|
|
|
{ |
762
|
|
|
// Remove the following lines when you implement this test. |
763
|
|
|
$this->markTestIncomplete( |
764
|
|
|
'This test has not been implemented yet.' |
765
|
|
|
); |
766
|
|
|
} |
767
|
|
|
|
768
|
|
|
/** |
769
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::saveResponseToFile |
770
|
|
|
* @todo Implement testSaveResponseToFile(). |
771
|
|
|
*/ |
772
|
|
|
public function testSaveResponseToFile() |
773
|
|
|
{ |
774
|
|
|
// Remove the following lines when you implement this test. |
775
|
|
|
$this->markTestIncomplete( |
776
|
|
|
'This test has not been implemented yet.' |
777
|
|
|
); |
778
|
|
|
} |
779
|
|
|
|
780
|
|
|
/** |
781
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getVazby |
782
|
|
|
* @todo Implement testGetVazby(). |
783
|
|
|
*/ |
784
|
|
|
public function testGetVazby() |
785
|
|
|
{ |
786
|
|
|
// Remove the following lines when you implement this test. |
787
|
|
|
$this->markTestIncomplete( |
788
|
|
|
'This test has not been implemented yet.' |
789
|
|
|
); |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
} |
793
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: