@@ -302,6 +302,242 @@ public function testExportFlat()
302
302
303
303
$ this ->assertFalse ($ cursor ->getNextBatch ());
304
304
}
305
+
306
+ /**
307
+ * Test export with include restriction
308
+ */
309
+ public function testExportRestrictInclude ()
310
+ {
311
+ if (! $ this ->hasExportApi ) {
312
+ return ;
313
+ }
314
+ for ($ i = 0 ; $ i < 200 ; ++$ i ) {
315
+ $ this ->documentHandler ->save ($ this ->collection , array ("value1 " => $ i , "value2 " => "test " . $ i ));
316
+ }
317
+
318
+ $ export = new Export ($ this ->connection , $ this ->collection , array (
319
+ "batchSize " => 50 ,
320
+ "_flat " => true ,
321
+ "restrict " => array ("type " => "include " , "fields " => array ("_key " , "value2 " ))
322
+ ));
323
+ $ cursor = $ export ->execute ();
324
+
325
+ $ this ->assertEquals (1 , $ cursor ->getFetches ());
326
+ $ this ->assertNotNull ($ cursor ->getId ());
327
+
328
+ $ this ->assertEquals (200 , $ cursor ->getCount ());
329
+ $ this ->assertEquals (1 , $ cursor ->getFetches ());
330
+
331
+ $ all = array ();
332
+ while ($ more = $ cursor ->getNextBatch ()) {
333
+ $ all = array_merge ($ all , $ more );
334
+ }
335
+ $ this ->assertEquals (200 , count ($ all ));
336
+
337
+ foreach ($ all as $ doc ) {
338
+ $ this ->assertTrue (is_array ($ doc ));
339
+ $ this ->assertEquals (2 , count ($ doc ));
340
+ $ this ->assertFalse (isset ($ doc ["_id " ]));
341
+ $ this ->assertTrue (isset ($ doc ["_key " ]));
342
+ $ this ->assertFalse (isset ($ doc ["_rev " ]));
343
+ $ this ->assertFalse (isset ($ doc ["value1 " ]));
344
+ $ this ->assertTrue (isset ($ doc ["value2 " ]));
345
+ }
346
+
347
+ $ this ->assertFalse ($ cursor ->getNextBatch ());
348
+ }
349
+
350
+ /**
351
+ * Test export with include restriction
352
+ */
353
+ public function testExportRestrictIncludeNonExisting ()
354
+ {
355
+ if (! $ this ->hasExportApi ) {
356
+ return ;
357
+ }
358
+ for ($ i = 0 ; $ i < 200 ; ++$ i ) {
359
+ $ this ->documentHandler ->save ($ this ->collection , array ("value1 " => $ i , "value2 " => "test " . $ i ));
360
+ }
361
+
362
+ $ export = new Export ($ this ->connection , $ this ->collection , array (
363
+ "batchSize " => 50 ,
364
+ "_flat " => true ,
365
+ "restrict " => array ("type " => "include " , "fields " => array ("foobar " , "baz " ))
366
+ ));
367
+ $ cursor = $ export ->execute ();
368
+
369
+ $ this ->assertEquals (1 , $ cursor ->getFetches ());
370
+ $ this ->assertNotNull ($ cursor ->getId ());
371
+
372
+ $ this ->assertEquals (200 , $ cursor ->getCount ());
373
+ $ this ->assertEquals (1 , $ cursor ->getFetches ());
374
+
375
+ $ all = array ();
376
+ while ($ more = $ cursor ->getNextBatch ()) {
377
+ $ all = array_merge ($ all , $ more );
378
+ }
379
+ $ this ->assertEquals (200 , count ($ all ));
380
+
381
+ foreach ($ all as $ doc ) {
382
+ $ this ->assertTrue (is_array ($ doc ));
383
+ $ this ->assertEquals (array (), $ doc );
384
+ }
385
+
386
+ $ this ->assertFalse ($ cursor ->getNextBatch ());
387
+ }
388
+
389
+ /**
390
+ * Test export with exclude restriction
391
+ */
392
+ public function testExportRestrictExclude ()
393
+ {
394
+ if (! $ this ->hasExportApi ) {
395
+ return ;
396
+ }
397
+ for ($ i = 0 ; $ i < 200 ; ++$ i ) {
398
+ $ this ->documentHandler ->save ($ this ->collection , array ("value1 " => $ i , "value2 " => "test " . $ i ));
399
+ }
400
+
401
+ $ export = new Export ($ this ->connection , $ this ->collection , array (
402
+ "batchSize " => 50 ,
403
+ "_flat " => true ,
404
+ "restrict " => array ("type " => "exclude " , "fields " => array ("_key " , "value2 " ))
405
+ ));
406
+ $ cursor = $ export ->execute ();
407
+
408
+ $ this ->assertEquals (1 , $ cursor ->getFetches ());
409
+ $ this ->assertNotNull ($ cursor ->getId ());
410
+
411
+ $ this ->assertEquals (200 , $ cursor ->getCount ());
412
+ $ this ->assertEquals (1 , $ cursor ->getFetches ());
413
+
414
+ $ all = array ();
415
+ while ($ more = $ cursor ->getNextBatch ()) {
416
+ $ all = array_merge ($ all , $ more );
417
+ }
418
+ $ this ->assertEquals (200 , count ($ all ));
419
+
420
+ foreach ($ all as $ doc ) {
421
+ $ this ->assertTrue (is_array ($ doc ));
422
+ $ this ->assertEquals (3 , count ($ doc ));
423
+ $ this ->assertFalse (isset ($ doc ["_key " ]));
424
+ $ this ->assertTrue (isset ($ doc ["_rev " ]));
425
+ $ this ->assertTrue (isset ($ doc ["_id " ]));
426
+ $ this ->assertTrue (isset ($ doc ["value1 " ]));
427
+ $ this ->assertFalse (isset ($ doc ["value2 " ]));
428
+ }
429
+
430
+ $ this ->assertFalse ($ cursor ->getNextBatch ());
431
+ }
432
+
433
+ /**
434
+ * Test export with non-existing fields restriction
435
+ */
436
+ public function testExportRestrictExcludeNonExisting ()
437
+ {
438
+ if (! $ this ->hasExportApi ) {
439
+ return ;
440
+ }
441
+ for ($ i = 0 ; $ i < 200 ; ++$ i ) {
442
+ $ this ->documentHandler ->save ($ this ->collection , array ("value1 " => $ i , "value2 " => "test " . $ i ));
443
+ }
444
+
445
+ $ export = new Export ($ this ->connection , $ this ->collection , array (
446
+ "batchSize " => 50 ,
447
+ "_flat " => true ,
448
+ "restrict " => array ("type " => "include " , "fields " => array ("_id " , "foobar " , "baz " ))
449
+ ));
450
+ $ cursor = $ export ->execute ();
451
+
452
+ $ this ->assertEquals (1 , $ cursor ->getFetches ());
453
+ $ this ->assertNotNull ($ cursor ->getId ());
454
+
455
+ $ this ->assertEquals (200 , $ cursor ->getCount ());
456
+ $ this ->assertEquals (1 , $ cursor ->getFetches ());
457
+
458
+ $ all = array ();
459
+ while ($ more = $ cursor ->getNextBatch ()) {
460
+ $ all = array_merge ($ all , $ more );
461
+ }
462
+ $ this ->assertEquals (200 , count ($ all ));
463
+
464
+ foreach ($ all as $ doc ) {
465
+ $ this ->assertTrue (is_array ($ doc ));
466
+ $ this ->assertEquals (1 , count ($ doc ));
467
+ $ this ->assertTrue (isset ($ doc ["_id " ]));
468
+ $ this ->assertFalse (isset ($ doc ["foobar " ]));
469
+ }
470
+
471
+ $ this ->assertFalse ($ cursor ->getNextBatch ());
472
+ }
473
+
474
+ /**
475
+ * Test export with invalid restriction definition
476
+ *
477
+ * @expectedException \triagens\ArangoDb\ClientException
478
+ */
479
+ public function testExportRestrictInvalidType ()
480
+ {
481
+ if (! $ this ->hasExportApi ) {
482
+ return ;
483
+ }
484
+
485
+ $ export = new Export ($ this ->connection , $ this ->collection , array (
486
+ "restrict " => array ("type " => "foo " , "fields " => array ("_key " ))
487
+ ));
488
+ $ cursor = $ export ->execute ();
489
+ }
490
+
491
+ /**
492
+ * Test export with invalid restriction definition
493
+ *
494
+ * @expectedException \triagens\ArangoDb\ClientException
495
+ */
496
+ public function testExportRestrictMissingType ()
497
+ {
498
+ if (! $ this ->hasExportApi ) {
499
+ return ;
500
+ }
501
+
502
+ $ export = new Export ($ this ->connection , $ this ->collection , array (
503
+ "restrict " => array ("fields " => array ("_key " ))
504
+ ));
505
+ $ cursor = $ export ->execute ();
506
+ }
507
+
508
+ /**
509
+ * Test export with invalid restriction definition
510
+ *
511
+ * @expectedException \triagens\ArangoDb\ClientException
512
+ */
513
+ public function testExportRestrictInvalidFields ()
514
+ {
515
+ if (! $ this ->hasExportApi ) {
516
+ return ;
517
+ }
518
+
519
+ $ export = new Export ($ this ->connection , $ this ->collection , array (
520
+ "restrict " => array ("type " => "include " , "fields " => "foo " )
521
+ ));
522
+ $ cursor = $ export ->execute ();
523
+ }
524
+
525
+ /**
526
+ * Test export with invalid restriction definition
527
+ *
528
+ * @expectedException \triagens\ArangoDb\ClientException
529
+ */
530
+ public function testExportRestrictMissingFields ()
531
+ {
532
+ if (! $ this ->hasExportApi ) {
533
+ return ;
534
+ }
535
+
536
+ $ export = new Export ($ this ->connection , $ this ->collection , array (
537
+ "restrict " => array ("type " => "include " )
538
+ ));
539
+ $ cursor = $ export ->execute ();
540
+ }
305
541
306
542
public function tearDown ()
307
543
{
0 commit comments