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