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->evidence = 'c'; |
26
|
|
|
$this->object->prefix = ''; |
27
|
|
|
$this->object->company = ''; |
28
|
|
|
$this->object->nameSpace = 'companies'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Tears down the fixture, for example, closes a network connection. |
33
|
|
|
* This method is called after a test is executed. |
34
|
|
|
*/ |
35
|
|
|
protected function tearDown() |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::curlInit |
42
|
|
|
*/ |
43
|
|
|
public function testCurlInit() |
44
|
|
|
{ |
45
|
|
|
$this->object->curlInit(); |
46
|
|
|
$this->assertTrue(is_resource($this->object->curl)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::processInit |
51
|
|
|
*/ |
52
|
|
|
public function testProcessInit() |
53
|
|
|
{ |
54
|
|
|
$this->object->processInit(['id' => 1]); |
55
|
|
|
$this->assertEquals(1, $this->object->getDataValue('id')); |
56
|
|
|
if (!is_null($this->object->evidence) && $this->object->evidence != 'test') { |
57
|
|
|
$firstID = $this->object->getColumnsFromFlexibee('id', |
|
|
|
|
58
|
|
|
['limit' => 1]); |
59
|
|
|
$this->object->processInit((int) current($firstID)); |
60
|
|
|
$this->assertNotEmpty($this->object->__toString()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::setEvidence |
66
|
|
|
*/ |
67
|
|
|
public function testSetEvidence() |
68
|
|
|
{ |
69
|
|
|
$this->object->setEvidence('nastaveni'); |
70
|
|
|
$this->assertEquals('nastaveni', $this->object->evidence); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::object2array |
75
|
|
|
*/ |
76
|
|
|
public function testObject2array() |
77
|
|
|
{ |
78
|
|
|
$this->assertNull($this->object->object2array(new \stdClass())); |
79
|
|
|
$this->assertEquals( |
80
|
|
|
[ |
81
|
|
|
'item' => 1, |
82
|
|
|
'arrItem' => ['a', 'b' => 'c'] |
83
|
|
|
] |
84
|
|
|
, $this->object->object2array(new \Test\ObjectForTesting())); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::objectToID |
89
|
|
|
*/ |
90
|
|
|
public function testObjectToID() |
91
|
|
|
{ |
92
|
|
|
$id = \Ease\Sand::randomNumber(1, 9999); |
93
|
|
|
$this->object->setMyKey($id); |
|
|
|
|
94
|
|
|
$this->assertEquals([$id], $this->object->objectToID([$this->object])); |
95
|
|
|
|
96
|
|
|
$this->object->setDataValue('kod', 'TEST'); |
97
|
|
|
$this->assertEquals('code:TEST', |
98
|
|
|
$this->object->objectToID($this->object)); |
99
|
|
|
|
100
|
|
|
$this->assertEquals('TEST', $this->object->objectToID('TEST')); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::performRequest |
105
|
|
|
*/ |
106
|
|
|
public function testPerformRequest() |
107
|
|
|
{ |
108
|
|
|
$evidence = $this->object->getEvidence(); |
109
|
|
|
switch ($evidence) { |
110
|
|
|
case null: |
111
|
|
|
case '': |
112
|
|
|
case 'test': |
113
|
|
|
case 'c': |
114
|
|
|
$this->object->evidence = 'c'; |
115
|
|
|
$this->object->prefix = ''; |
116
|
|
|
$this->object->company = ''; |
117
|
|
|
$this->object->nameSpace = 'companies'; |
118
|
|
|
$json = $this->object->performRequest(); |
119
|
|
|
$this->assertArrayHasKey('company', $json); |
120
|
|
|
|
121
|
|
|
$xml = $this->object->performRequest(null, 'GET', 'xml'); |
122
|
|
|
$this->assertArrayHasKey('company', $xml); |
123
|
|
|
break; |
124
|
|
|
|
125
|
|
|
default: |
126
|
|
|
$json = $this->object->performRequest($evidence.'.json'); |
127
|
|
|
if (array_key_exists('message', $json)) { |
128
|
|
|
$this->assertArrayHasKey('@version', $json); |
129
|
|
|
} else { |
130
|
|
|
$this->assertArrayHasKey($evidence, $json); |
131
|
|
|
} |
132
|
|
|
break; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
$err = $this->object->performRequest('error.json'); |
137
|
|
|
$this->assertArrayHasKey('success', $err); |
138
|
|
|
$this->assertEquals('false', $err['success']); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::setAction |
143
|
|
|
*/ |
144
|
|
|
public function testSetAction() |
145
|
|
|
{ |
146
|
|
|
$this->assertTrue($this->object->setAction('none')); |
147
|
|
|
$this->object->actionsAvailable = []; |
148
|
|
|
$this->assertFalse($this->object->setAction('none')); |
149
|
|
|
$this->object->actionsAvailable = ['copy']; |
150
|
|
|
$this->assertFalse($this->object->setAction('none')); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId |
155
|
|
|
* @depends testInsertToFlexiBee |
156
|
|
|
*/ |
157
|
|
|
public function testGetLastInsertedId() |
158
|
|
|
{ |
159
|
|
|
$this->assertNotEmpty($this->object->getLastInsertedId()); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::xml2array |
164
|
|
|
*/ |
165
|
|
|
public function testXml2array() |
166
|
|
|
{ |
167
|
|
|
$xml = '<card xmlns="http://businesscard.org"> |
168
|
|
|
<name>John Doe</name> |
169
|
|
|
<title>CEO, Widget Inc.</title> |
170
|
|
|
<email>[email protected]</email> |
171
|
|
|
<phone>(202) 456-1414</phone> |
172
|
|
|
<logo url="widget.gif"/> |
173
|
|
|
<a><b>c</b></a> |
174
|
|
|
</card>'; |
175
|
|
|
|
176
|
|
|
$data = ['name' => 'John Doe', 'title' => 'CEO, Widget Inc.', 'email' => '[email protected]', |
177
|
|
|
'phone' => '(202) 456-1414', 'logo' => '', 'a' => [['b' => 'c']]]; |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
$this->assertEquals($data, $this->object->xml2array($xml)); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::disconnect |
185
|
|
|
* |
186
|
|
|
* @depends testPerformRequest |
187
|
|
|
* @depends testLoadFlexiData |
188
|
|
|
* @depends testGetFlexiRow |
189
|
|
|
* @depends testGetFlexiData |
190
|
|
|
* @depends testLoadFromFlexiBee |
191
|
|
|
* @depends testInsertToFlexiBee |
192
|
|
|
* @depends testIdExists |
193
|
|
|
* @depends testRecordExists |
194
|
|
|
* @depends testGetColumnsFromFlexibee |
195
|
|
|
* @depends testSearchString |
196
|
|
|
*/ |
197
|
|
|
public function testDisconnect() |
198
|
|
|
{ |
199
|
|
|
$this->object->disconnect(); |
200
|
|
|
$this->assertNull($this->object->curl); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::__destruct |
205
|
|
|
* @depends testDisconnect |
206
|
|
|
*/ |
207
|
|
|
public function testdestruct() |
208
|
|
|
{ |
209
|
|
|
$this->markTestSkipped(); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow |
214
|
|
|
*/ |
215
|
|
|
public function testGetFlexiRow() |
216
|
|
|
{ |
217
|
|
|
$this->object->getFlexiRow(0); |
218
|
|
|
$this->object->getFlexiRow(1); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getFlexiData |
223
|
|
|
*/ |
224
|
|
|
public function testGetFlexiData() |
225
|
|
|
{ |
226
|
|
|
$evidence = $this->object->getEvidence(); |
227
|
|
|
|
228
|
|
|
switch ($evidence) { |
229
|
|
|
case null: |
230
|
|
|
$this->markTestSkipped('Unsupported evidence'); |
231
|
|
|
break; |
232
|
|
|
case 'c': |
233
|
|
|
$this->object->evidence = 'c'; |
234
|
|
|
$this->object->prefix = ''; |
235
|
|
|
$this->object->company = ''; |
236
|
|
|
$this->object->nameSpace = 'companies'; |
237
|
|
|
$flexidata = $this->object->getFlexiData(); |
238
|
|
|
$this->assertArrayHasKey('company', $flexidata); |
239
|
|
|
break; |
240
|
|
|
|
241
|
|
|
default: |
242
|
|
|
$flexidata = $this->object->getFlexiData(); |
243
|
|
|
if (is_array($flexidata) && !count($flexidata)) { |
244
|
|
|
$this->markTestSkipped('Empty evidence'); |
245
|
|
View Code Duplication |
} else { |
|
|
|
|
246
|
|
|
$this->assertArrayHasKey(0, $flexidata); |
247
|
|
|
$this->assertArrayHasKey('id', $flexidata[0]); |
248
|
|
|
$filtrered = $this->object->getFlexiData(null, |
249
|
|
|
key($flexidata[0])." = ".current($flexidata[0])); |
250
|
|
|
$this->assertArrayHasKey(0, $filtrered); |
251
|
|
|
$this->assertArrayHasKey('id', $filtrered[0]); |
252
|
|
|
} |
253
|
|
|
break; |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee |
259
|
|
|
*/ |
260
|
|
|
public function testLoadFromFlexiBee() |
261
|
|
|
{ |
262
|
|
|
$this->object->loadFromFlexiBee(); |
263
|
|
|
$this->object->loadFromFlexiBee(222); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::jsonizeData |
268
|
|
|
*/ |
269
|
|
|
public function testJsonizeData() |
270
|
|
|
{ |
271
|
|
|
$this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"}}}', |
272
|
|
|
$this->object->jsonizeData(['key' => 'value'])); |
273
|
|
|
$this->object->setAction('copy'); |
274
|
|
|
$this->assertEquals('{"'.$this->object->nameSpace.'":{"@version":"1.0","'.$this->object->evidence.'":{"key":"value"},"'.$this->object->evidence.'@action":"copy"}}', |
275
|
|
|
$this->object->jsonizeData(['key' => 'value'])); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::idExists |
280
|
|
|
*/ |
281
|
|
|
public function testIdExists() |
282
|
|
|
{ |
283
|
|
|
// Remove the following lines when you implement this test. |
284
|
|
|
$this->markTestIncomplete( |
285
|
|
|
'This test has not been implemented yet.' |
286
|
|
|
); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::recordExists |
291
|
|
|
*/ |
292
|
|
|
public function testRecordExists() |
293
|
|
|
{ |
294
|
|
|
$evidence = $this->object->getEvidence(); |
295
|
|
|
|
296
|
|
|
switch ($evidence) { |
297
|
|
|
case null: |
298
|
|
|
case 'c': |
299
|
|
|
$this->markTestSkipped('Unsupported evidence'); |
300
|
|
|
break; |
301
|
|
|
|
302
|
|
|
default: |
303
|
|
|
$flexidata = $this->object->getFlexiData(null, ['limit' => 1]); |
304
|
|
|
if (is_array($flexidata) && !count($flexidata)) { |
305
|
|
|
$this->markTestSkipped('Empty evidence'); |
306
|
|
|
} else { |
307
|
|
|
$this->object->setData(['id' => (int) $flexidata[0]['id']]); |
308
|
|
|
$this->assertTrue($this->object->recordExists()); |
309
|
|
|
$this->assertFalse($this->object->recordExists(['id' => 0])); |
310
|
|
|
$this->assertFalse($this->object->recordExists(['unexistent' => 1])); |
311
|
|
|
} |
312
|
|
|
break; |
313
|
|
|
} |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee |
318
|
|
|
*/ |
319
|
|
|
public function testGetColumnsFromFlexibee() |
320
|
|
|
{ |
321
|
|
|
// Remove the following lines when you implement this test. |
322
|
|
|
$this->markTestIncomplete( |
323
|
|
|
'This test has not been implemented yet.' |
324
|
|
|
); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::getKod |
329
|
|
|
*/ |
330
|
|
|
public function testGetKod() |
331
|
|
|
{ |
332
|
|
|
|
333
|
|
|
$this->assertEquals('CODE', |
334
|
|
|
$this->object->getKod([$this->object->myKeyColumn => 'code'])); |
335
|
|
|
|
336
|
|
|
$testString[$this->object->nameColumn] = 'Fish clamp - Úchytka pro instalaci samonosných kabelů ' |
|
|
|
|
337
|
|
|
.'(3.5 mm)'; |
338
|
|
|
$code0 = $this->object->getKod($testString); |
339
|
|
|
$this->assertEquals('FISHCLAMPUCHYTKAPR', $code0); |
340
|
|
|
$code1 = $this->object->getKod($testString, |
341
|
|
|
false); |
342
|
|
|
$this->assertEquals('FISHCLAMPUCHYTKAPR', $code1); |
343
|
|
|
$code2 = $this->object->getKod($testString); |
344
|
|
|
$this->assertEquals('FISHCLAMPUCHYTKAPR1', $code2); |
345
|
|
|
$this->object->setData($testString); |
346
|
|
|
$code3 = $this->object->getKod(); |
347
|
|
|
$this->assertEquals('FISHCLAMPUCHYTKAPR2', $code3); |
348
|
|
|
|
349
|
|
|
$this->assertEquals('TEST', |
350
|
|
|
$this->object->getKod([$this->object->nameColumn => 'test'])); |
351
|
|
|
|
352
|
|
|
$this->assertEquals('TEST1', $this->object->getKod('test')); |
353
|
|
|
|
354
|
|
|
$this->assertEquals('TEST2', $this->object->getKod(['kod' => 'test'])); |
355
|
|
|
$this->assertEquals('NOTSET', $this->object->getKod(['kod' => ''])); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::logResult |
360
|
|
|
*/ |
361
|
|
|
public function testLogResult() |
362
|
|
|
{ |
363
|
|
|
$this->object->cleanMessages(); |
364
|
|
|
$success = json_decode('{"winstrom":{"@version":"1.0","success":"true",' |
365
|
|
|
.'"stats":{"created":"0","updated":"1","deleted":"0","skipped":"0"' |
366
|
|
|
.',"failed":"0"},"results":[{"id":"1","request-id":"ext:SōkoMan.item' |
367
|
|
|
.':5271","ref":"/c/spoje_net_s_r_o_1/skladovy-pohyb/1.json"}]}}'); |
368
|
|
|
$this->object->logResult(current($this->object->object2array($success)), |
369
|
|
|
'http://test'); |
370
|
|
|
|
371
|
|
|
$this->assertArrayHasKey('info', $this->object->getStatusMessages(true)); |
372
|
|
|
|
373
|
|
|
$error = json_decode('{"winstrom":{"@version":"1.0","success":"false",' |
374
|
|
|
.'"stats":{"created":"0","updated":"0","deleted":"0","skipped":"0"' |
375
|
|
|
.',"failed":"0"},"results":[{"errors":[{"message":"cz.winstrom.' |
376
|
|
|
.'service.WSBusinessException: Zadaný kód není unikátní.\nZadaný' |
377
|
|
|
.' kód není unikátní."}]}]}}'); |
378
|
|
|
$this->object->lastResponseCode = 500; |
379
|
|
|
$this->object->logResult(current($this->object->object2array($error))); |
380
|
|
|
$this->assertArrayHasKey('error', $this->object->getStatusMessages(true)); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::flexiUrl |
385
|
|
|
*/ |
386
|
|
|
public function testFlexiUrl() |
387
|
|
|
{ |
388
|
|
|
$this->assertEquals("a eq 1 and b eq 'foo'", |
389
|
|
|
$this->object->flexiUrl(['a' => 1, 'b' => 'foo'], 'and')); |
390
|
|
|
$this->assertEquals("a eq 1 or b eq 'bar'", |
391
|
|
|
$this->object->flexiUrl(['a' => 1, 'b' => 'bar'], 'or')); |
392
|
|
|
$this->assertEquals("a eq true or b eq false", |
393
|
|
|
$this->object->flexiUrl(['a' => true, 'b' => false], 'or')); |
394
|
|
|
$this->assertEquals("a is null and b is not null", |
395
|
|
|
$this->object->flexiUrl(['a' => null, 'b' => '!null'], 'and')); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::__toString |
400
|
|
|
*/ |
401
|
|
|
public function testtoString() |
402
|
|
|
{ |
403
|
|
|
|
404
|
|
|
$identifer = 'ext:test:123'; |
405
|
|
|
$this->object->setDataValue('id', $identifer); |
406
|
|
|
$this->assertEquals($identifer, (string) $this->object); |
407
|
|
|
|
408
|
|
|
$code = 'test'; |
409
|
|
|
$this->object->setDataValue('kod', $code); |
410
|
|
|
$this->assertEquals('code:'.$code, (string) $this->object); |
411
|
|
|
|
412
|
|
|
$this->object->dataReset(); |
413
|
|
|
$this->assertNull($this->object->__toString()); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* @covers FlexiPeeHP\FlexiBeeRO::draw |
418
|
|
|
*/ |
419
|
|
|
public function testDraw($whatWant = NULL) |
420
|
|
|
{ |
421
|
|
|
$this->object->setDataValue('kod', 'test'); |
422
|
|
|
$this->assertEquals('code:test', $this->object->draw()); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
} |
426
|
|
|
|
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: