@@ -476,6 +476,29 @@ public function testCreateEditDatapackageDescriptor()
476476 $ zip ->close ();
477477 unlink ($ filename );
478478 $ tempdir = $ tempdir .DIRECTORY_SEPARATOR ;
479+
480+ //after saving to disk, the paths are updated
481+ $ expectedDatapackageDescriptor = (object ) [
482+ 'name ' => 'my-datapackage-name ' ,
483+ 'resources ' => [
484+ (object ) [
485+ 'name ' => 'my-default-resource ' ,
486+ 'path ' => ["resource-0-data-0 " , "resource-0-data-1 " ],
487+ ],
488+ (object ) [
489+ 'name ' => 'my-renamed-tabular-resource ' ,
490+ 'path ' => "resource-1.csv " ,
491+ 'profile ' => 'tabular-data-resource ' ,
492+ 'schema ' => (object ) [
493+ 'fields ' => [
494+ (object ) ['name ' => 'id ' , 'type ' => 'integer ' ],
495+ (object ) ['name ' => 'name ' , 'type ' => 'string ' ],
496+ ],
497+ ],
498+ ],
499+ ],
500+ ];
501+
479502 $ this ->assertEquals ($ expectedDatapackageDescriptor , json_decode (file_get_contents ($ tempdir .'datapackage.json ' )));
480503 $ this ->assertEquals ('foo ' , file_get_contents ($ tempdir .'resource-0-data-0 ' ));
481504 $ this ->assertEquals ("testing 改善 \n" , file_get_contents ($ tempdir .'resource-0-data-1 ' ));
@@ -484,6 +507,39 @@ public function testCreateEditDatapackageDescriptor()
484507 Utils::removeDir ($ tempdir );
485508 }
486509
510+ public function testSaveAndLoadZip ()
511+ {
512+ //create example csv
513+ file_put_contents ('/tmp/example.csv ' , "name,email \nJohn Doe,john@example.com " );
514+
515+ //create a new datapackage object
516+ $ package = Package::create (['name ' => 'csv-example ' ,'profile ' => 'tabular-data-package ' ]);
517+
518+ //add a csv file
519+ $ package ->addResource ('example.csv ' , [
520+ "profile " => "tabular-data-resource " ,
521+ "schema " => ["fields " => [["name " => "name " , "type " => "string " ],["name " => "email " , "type " => "string " ]]],
522+ "path " => '/tmp/example.csv '
523+ ]);
524+
525+ //save the datapackage
526+ if (is_file ('datapackage.zip ' )) {
527+ unlink ('datapackage.zip ' );
528+ }
529+ $ package ->save ("datapackage.zip " );
530+
531+ //delete example csv
532+ unlink ('/tmp/example.csv ' );
533+
534+ //load the new package
535+ $ package2 = Package::load ('datapackage.zip ' );
536+
537+ //assert you get expected content back out
538+ $ this ->assertEquals ([['name ' => 'John Doe ' , 'email ' => 'john@example.com ' ]], $ package2 ->resource ('example.csv ' )->read ());
539+
540+ unlink ('datapackage.zip ' );
541+ }
542+
487543 public function testLoadDatapackageZip ()
488544 {
489545 $ package = Package::load (dirname (__FILE__ ).'/fixtures/datapackage_zip.zip ' );
@@ -626,21 +682,21 @@ public function testCsvDialect()
626682 'CommitteeTypeDesc ' => 'ועדה משותפת ' ,
627683 'Email ' => null ,
628684 'StartDate ' => Carbon::__set_state (array (
629- 'date ' => '2004-08-12 00:00:00.000000 ' ,
630- 'timezone_type ' => 3 ,
631- 'timezone ' => 'UTC ' ,
632- )),
685+ 'date ' => '2004-08-12 00:00:00.000000 ' ,
686+ 'timezone_type ' => 3 ,
687+ 'timezone ' => 'UTC ' ,
688+ )),
633689 'FinishDate ' => null ,
634690 'AdditionalTypeID ' => null ,
635691 'AdditionalTypeDesc ' => null ,
636692 'ParentCommitteeID ' => null ,
637693 'CommitteeParentName ' => null ,
638694 'IsCurrent ' => true ,
639695 'LastUpdatedDate ' => Carbon::__set_state (array (
640- 'date ' => '2015-03-20 12:02:57.000000 ' ,
641- 'timezone_type ' => 3 ,
642- 'timezone ' => 'UTC ' ,
643- )),
696+ 'date ' => '2015-03-20 12:02:57.000000 ' ,
697+ 'timezone_type ' => 3 ,
698+ 'timezone ' => 'UTC ' ,
699+ )),
644700 ), $ row );
645701 }
646702 ++$ rowNum ;
0 commit comments