3 require_once
'lib/bagit.php';
4 require_once
'lib/bagit_utils.php';
6 class BagItTest extends PHPUnit_Framework_TestCase
11 private function _createBagItTxt($dirname)
15 "BagIt-Version: 1.3\n" .
16 "Tag-File-Character-Encoding: ISO-8859-1\n"
22 $this->tmpdir = tmpdir();
23 $this->bag =
new BagIt($this->tmpdir);
28 rrmdir($this->tmpdir);
33 $this->assertEquals($this->tmpdir, $this->bag->bagDirectory);
38 $this->assertTrue($this->bag->extended);
44 touch($tmp2 .
"/bag-info.txt");
46 $this->assertFalse(
$bag->extended);
58 $this->assertEquals(0, $this->bag->bagVersion[
'major']);
59 $this->assertEquals(96, $this->bag->bagVersion[
'minor']);
65 $this->_createBagItTxt($tmp2);
67 $this->assertEquals(1,
$bag->bagVersion[
'major']);
68 $this->assertEquals(3,
$bag->bagVersion[
'minor']);
80 $this->assertEquals(
'UTF-8', $this->bag->tagFileEncoding);
86 $this->_createBagItTxt($tmp2);
88 $this->assertEquals(
'ISO-8859-1',
$bag->tagFileEncoding);
101 $this->tmpdir .
"/bagit.txt",
102 $this->bag->bagitFile
104 $this->assertFileExists($this->bag->bagitFile);
106 "BagIt-Version: 0.96\n" .
107 "Tag-File-Character-Encoding: UTF-8\n",
108 file_get_contents($this->bag->bagitFile)
114 $this->assertInstanceOf(
'BagItManifest', $this->bag->manifest);
119 $this->assertInstanceOf(
'BagItManifest', $this->bag->tagManifest);
124 $this->assertInstanceOf(
'BagItFetch', $this->bag->fetch);
130 $this->tmpdir .
"/bag-info.txt",
131 $this->bag->bagInfoFile
133 $this->assertFileExists($this->bag->bagInfoFile);
141 $bag =
new BagIt($tmp2, FALSE, FALSE, FALSE, array(
142 'source-organization' =>
'University of Virginia',
143 'contact-name' =>
'Someone'
145 $this->assertTrue(
$bag->extended);
146 $this->assertNotNull(
$bag->bagInfoData);
147 $this->assertTrue(
$bag->hasBagInfoData(
"source-organization"));
148 $this->assertTrue(
$bag->hasBagInfoData(
"contact-name"));
149 $this->assertFalse(
$bag->hasBagInfoData(
"bag-date"));
161 $this->assertEquals(0, count($this->bag->bagInfoData));
167 $this->_createBagItTxt($tmp2);
169 $tmp2 .
"/bag-info.txt",
170 "Source-organization: University of Virginia Alderman Library\n" .
171 "Contact-name: Eric Rochester\n" .
172 "Bag-size: very, very small\n"
175 $this->assertNotNull(
$bag->bagInfoData);
176 $this->assertCount(3,
$bag->bagInfoData);
177 $this->assertTrue(
$bag->hasBagInfoData(
"Source-organization"));
178 $this->assertTrue(
$bag->hasBagInfoData(
"Contact-name"));
179 $this->assertTrue(
$bag->hasBagInfoData(
"Bag-size"));
180 $this->assertFalse(
$bag->hasBagInfoData(
"bag-size"));
181 $this->assertFalse(
$bag->hasBagInfoData(
"BAG-SIZE"));
182 $this->assertFalse(
$bag->hasBagInfoData(
"bag-date"));
194 $this->assertEquals(0, count($this->bag->bagInfoData));
200 $this->_createBagItTxt($tmp2);
202 $tmp2 .
"/bag-info.txt",
203 "Source-organization: University of Virginia Alderman Library\n" .
204 "Contact-name: Eric Rochester\n" .
205 "Bag-size: very, very small\n" .
207 "DC-Author: Myself\n" .
208 "DC-Author: The other\n" .
212 $this->assertNotNull(
$bag->bagInfoData);
213 $this->assertCount(4,
$bag->bagInfoData);
215 $this->assertTrue(
$bag->hasBagInfoData(
'DC-Author'));
217 array(
'Me',
'Myself',
'The other and more' ),
218 $bag->getBagInfoData(
'DC-Author')
231 $this->assertEquals(0, count($this->bag->bagInfoData));
238 $tmp2 .
"/bag-info.txt",
239 "Source-organization: University of Virginia Alderman Library\n" .
240 "Contact-name: Eric Rochester\n" .
241 "Bag-size: very, very small\n" .
243 "DC-Author: Myself\n" .
244 "DC-Author: The other\n"
248 $bag->setBagInfoData(
'First',
'This is the first tag value.');
249 $bag->setBagInfoData(
'Second',
'This is the second tag value.');
250 $bag->setBagInfoData(
'Second',
'This is the third tag value.');
251 $bag->setBagInfoData(
'Third',
'This is the fourth tag value.');
252 $bag->setBagInfoData(
'Third',
'This is the fifth tag value.');
253 $bag->setBagInfoData(
'Third',
'This is the sixth tag value.');
256 'This is the first tag value.',
257 $bag->getBagInfoData(
'First')
260 array(
'This is the second tag value.',
'This is the third tag value.' ),
261 $bag->getBagInfoData(
'Second')
265 'This is the fourth tag value.',
266 'This is the fifth tag value.',
267 'This is the sixth tag value.'
269 $bag->getBagInfoData(
'Third')
283 $this->assertEquals(0, count($this->bag->bagInfoData));
290 $tmp2 .
"/bag-info.txt",
291 "Source-organization: University of Virginia Alderman Library\n" .
292 "Contact-name: Eric Rochester\n" .
293 "Bag-size: very, very small\n" .
295 "DC-Author: Myself\n" .
296 "DC-Author: The other\n"
300 $bag->setBagInfoData(
'First',
'This is the first tag value.');
301 $bag->setBagInfoData(
'Second',
'This is the second tag value.');
302 $bag->setBagInfoData(
'Second',
'This is the third tag value.');
303 $bag->setBagInfoData(
'Third',
'This is the fourth tag value.');
304 $bag->setBagInfoData(
'Third',
'This is the fifth tag value.');
305 $bag->setBagInfoData(
'Third',
'This is the sixth tag value.');
308 'This is the first tag value.',
309 $bag->getBagInfoData(
'First')
312 array(
'This is the second tag value.',
'This is the third tag value.' ),
313 $bag->getBagInfoData(
'Second')
317 'This is the fourth tag value.',
318 'This is the fifth tag value.',
319 'This is the sixth tag value.'
321 $bag->getBagInfoData(
'Third')
324 $bag->clearBagInfoData(
'Third');
325 $this->assertNotNull(
$bag->getBagInfoData(
'First'));
326 $this->assertNotNull(
$bag->getBagInfoData(
'Second'));
327 $this->assertNull(
$bag->getBagInfoData(
'Third'));
340 $this->assertEquals(0, count($this->bag->bagInfoData));
347 $this->_createBagItTxt($tmp2);
349 $tmp2 .
"/bag-info.txt",
350 "Source-organization: University of Virginia Alderman Library\n" .
351 "Contact-name: Eric Rochester\n" .
352 "Bag-size: very, very small\n" .
354 "DC-Author: Myself\n" .
355 "DC-Author: The other\n"
359 $bag->setBagInfoData(
'First',
'This is the first tag value.');
360 $bag->setBagInfoData(
'Second',
'This is the second tag value.');
361 $bag->setBagInfoData(
'Second',
'This is the third tag value.');
362 $bag->setBagInfoData(
'Third',
'This is the fourth tag value.');
363 $bag->setBagInfoData(
'Third',
'This is the fifth tag value.');
364 $bag->setBagInfoData(
'Third',
'This is the sixth tag value.');
369 "Source-organization: University of Virginia Alderman Library\n" .
370 "Contact-name: Eric Rochester\n" .
371 "Bag-size: very, very small\n" .
373 "DC-Author: Myself\n" .
374 "DC-Author: The other\n" .
375 "First: This is the first tag value.\n" .
376 "Second: This is the second tag value.\n" .
377 "Second: This is the third tag value.\n" .
378 "Third: This is the fourth tag value.\n" .
379 "Third: This is the fifth tag value.\n" .
380 "Third: This is the sixth tag value.\n",
381 file_get_contents(
"$tmp2/bag-info.txt")
395 $this->assertEquals(0, count($this->bag->bagInfoData));
404 "$tmp2/bag-info.txt",
405 "Source-organization: University of Virginia Alderman Library\n" .
406 "Contact-name: Eric Rochester\n" .
407 "Bag-size: very, very small\n"
410 $this->assertNotNull(
$bag->bagInfoData);
412 $bag->setBagInfoData(
'First',
'This is the first tag value.');
413 $bag->setBagInfoData(
'Second',
'This is the second tag value.');
416 $bag->package(
"$tmp2.tgz");
419 $bag2 =
new BagIt(
"$tmp2.tgz");
420 $tmp2 = $bag2->bagDirectory;
422 $this->assertTrue($bag2->hasBagInfoData(
'First'));
424 'This is the first tag value.',
425 $bag2->getBagInfoData(
'First')
427 $this->assertTrue($bag2->hasBagInfoData(
'Second'));
429 'This is the second tag value.',
430 $bag2->getBagInfoData(
'Second')
435 if (file_exists($tmp2)) {
438 if (file_exists(
"$tmp2.tgz")) {
448 $this->assertEquals(0, count($this->bag->bagInfoData));
456 $this->_createBagItTxt($tmp2);
458 "$tmp2/bag-info.txt",
459 "Source-organization: University of Virginia Alderman Library\n" .
460 "Contact-name: Eric Rochester\n" .
461 "Bag-size: very, very small\n"
464 $this->assertNotNull(
$bag->bagInfoData);
466 $bag->setBagInfoData(
'First',
'This is the first tag value.');
467 $bag->setBagInfoData(
'Second',
'This is the second tag value.');
472 "Source-organization: University of Virginia Alderman Library\n" .
473 "Contact-name: Eric Rochester\n" .
474 "Bag-size: very, very small\n" .
475 "First: This is the first tag value.\n" .
476 "Second: This is the second tag value.\n",
477 file_get_contents(
"$tmp2/bag-info.txt")
482 if (file_exists($tmp2)) {
485 if (file_exists(
"$tmp2.tgz")) {
494 $this->bag->bagInfoData =
null;
495 $this->assertNull($this->bag->bagInfoData);
496 $this->bag->hasBagInfoData(
'hi');
497 $this->assertFalse(is_null($this->bag->bagInfoData));
498 $this->assertCount(0, $this->bag->bagInfoData);
509 $this->_createBagItTxt($tmp2);
511 "$tmp2/bag-info.txt",
512 "Source-organization: University of Virginia Alderman Library\n" .
513 "Contact-name: Eric Rochester\n" .
514 "Bag-size: very, very small\n"
518 $this->assertTrue(
$bag->hasBagInfoData(
'Source-organization'));
519 $this->assertFalse(
$bag->hasBagInfoData(
'source-organization'));
520 $this->assertFalse(
$bag->hasBagInfoData(
'SOURCE-ORGANIZATION'));
521 $this->assertFalse(
$bag->hasBagInfoData(
'Source-Organization'));
522 $this->assertFalse(
$bag->hasBagInfoData(
'SoUrCe-oRgAnIzAtIoN'));
524 $this->assertTrue(
$bag->hasBagInfoData(
'Contact-name'));
525 $this->assertFalse(
$bag->hasBagInfoData(
'contact-name'));
526 $this->assertFalse(
$bag->hasBagInfoData(
'CONTACT-NAME'));
527 $this->assertFalse(
$bag->hasBagInfoData(
'Contact-Name'));
528 $this->assertFalse(
$bag->hasBagInfoData(
'CoNtAcT-NaMe'));
530 $this->assertTrue(
$bag->hasBagInfoData(
'Bag-size'));
531 $this->assertFalse(
$bag->hasBagInfoData(
'bag-size'));
532 $this->assertFalse(
$bag->hasBagInfoData(
'BAG-SIZE'));
533 $this->assertFalse(
$bag->hasBagInfoData(
'Bag-Size'));
534 $this->assertFalse(
$bag->hasBagInfoData(
'BaG-SiZe'));
536 $this->assertFalse(
$bag->hasBagInfoData(
'copyright-date'));
537 $this->assertFalse(
$bag->hasBagInfoData(
'other-metadata'));
538 $this->assertFalse(
$bag->hasBagInfoData(
'thrown-away-the-key'));
542 if (file_exists($tmp2)) {
558 $this->_createBagItTxt($tmp2);
560 "$tmp2/bag-info.txt",
561 "Source-organization: University of Virginia Alderman Library\n" .
562 "Contact-name: Eric Rochester\n" .
563 "Bag-size: very, very small\n"
567 $this->assertEquals(
'University of Virginia Alderman Library',
$bag->getBagInfoData(
'Source-organization'));
568 $this->assertNotEquals(
'University of Virginia Alderman Library',
$bag->getBagInfoData(
'source-organization'));
569 $this->assertNotEquals(
'University of Virginia Alderman Library',
$bag->getBagInfoData(
'SOURCE-ORGANIZATION'));
570 $this->assertNotEquals(
'University of Virginia Alderman Library',
$bag->getBagInfoData(
'Source-Organization'));
571 $this->assertNotEquals(
'University of Virginia Alderman Library',
$bag->getBagInfoData(
'SoUrCe-oRgAnIzAtIoN'));
573 $this->assertEquals(
'Eric Rochester',
$bag->getBagInfoData(
'Contact-name'));
574 $this->assertNotEquals(
'Eric Rochester',
$bag->getBagInfoData(
'contact-name'));
575 $this->assertNotEquals(
'Eric Rochester',
$bag->getBagInfoData(
'CONTACT-NAME'));
576 $this->assertNotEquals(
'Eric Rochester',
$bag->getBagInfoData(
'Contact-Name'));
577 $this->assertNotEquals(
'Eric Rochester',
$bag->getBagInfoData(
'CoNtAcT-NaMe'));
579 $this->assertEquals(
'very, very small',
$bag->getBagInfoData(
'Bag-size'));
580 $this->assertNotEquals(
'very, very small',
$bag->getBagInfoData(
'bag-size'));
581 $this->assertNotEquals(
'very, very small',
$bag->getBagInfoData(
'BAG-SIZE'));
582 $this->assertNotEquals(
'very, very small',
$bag->getBagInfoData(
'Bag-Size'));
583 $this->assertNotEquals(
'very, very small',
$bag->getBagInfoData(
'BaG-SiZe'));
585 $this->assertNull(
$bag->getBagInfoData(
'copyright-date'));
586 $this->assertNull(
$bag->getBagInfoData(
'other-metadata'));
587 $this->assertNull(
$bag->getBagInfoData(
'thrown-away-the-key'));
591 if (file_exists($tmp2)) {
601 $this->assertCount(0, $this->bag->bagInfoData);
602 $this->bag->setBagInfoData(
'hi',
'some value');
604 $this->assertTrue($this->bag->hasBagInfoData(
'hi'));
605 $this->assertFalse($this->bag->hasBagInfoData(
'HI'));
606 $this->assertFalse($this->bag->hasBagInfoData(
'Hi'));
607 $this->assertFalse($this->bag->hasBagInfoData(
'hI'));
609 $this->assertEquals(
'some value', $this->bag->getBagInfoData(
'hi'));
610 $this->assertCount(1, $this->bag->bagInfoData);
615 $this->assertNull($this->bag->bagCompression);
620 $this->assertInternalType(
'array', $this->bag->bagErrors);
621 $this->assertEquals(0, count($this->bag->bagErrors));
626 $this->assertTrue($this->bag->isValid());
627 $this->assertEquals(0, count($this->bag->bagErrors));
633 $this->_createBagItTxt($tmp);
635 $this->assertFalse(
$bag->isValid());
636 $this->assertGreaterThan(0, count(
$bag->bagErrors));
648 $this->assertFileExists($this->tmpdir .
'/bag-info.txt');
649 $this->assertFileNotExists($this->tmpdir .
'/fetch.txt');
650 $this->assertFileExists($this->tmpdir .
'/tagmanifest-sha1.txt');
656 $this->assertFalse(is_file($tmp .
'/bag-info.txt'));
657 $this->assertFalse(is_file($tmp .
'/fetch.txt'));
658 $this->assertFalse(is_file($tmp .
'/tagmanifest-sha1.txt'));
676 "http://www.google.com - google/index.html\n" .
677 "http://www.yahoo.com - yahoo/index.html\n"
679 $bag =
new BagIt($tmp,
false,
true,
false);
681 is_file(
$bag->getDataDirectory() .
'/google/index.html')
684 is_file(
$bag->getDataDirectory() .
'/yahoo/index.html')
700 "http://www.google.com - data/google/index.html\n" .
701 "http://www.yahoo.com - data/yahoo/index.html\n"
703 $bag =
new BagIt($tmp,
false,
true,
true);
704 $this->assertFileExists(
$bag->getDataDirectory() .
'/google/index.html');
705 $this->assertFileExists(
$bag->getDataDirectory() .
'/yahoo/index.html');
717 $this->assertEquals(0, $this->bag->bagVersion[
'major']);
725 "BagIt-Version: a.b\n" .
726 "Tag-File-Character-Encoding: ISO-8859-1\n"
729 $this->assertFalse(
$bag->isValid());
730 $bagErrors =
$bag->getBagErrors();
731 $this->assertTrue(seenAtKey($bagErrors, 0,
'bagit'));
741 private function _testSampleBag(
$bag)
743 $this->assertTrue(
$bag->isValid());
746 $stripLen = strlen(
$bag->bagDirectory) + 1;
747 $files =
$bag->getBagContents();
748 for ($i=0, $lsLen=count($files); $i<$lsLen; $i++)
750 $files[$i] = substr($files[$i], $stripLen);
752 $this->assertContains(
'data/imgs/109x109xcoins1-150x150.jpg', $files);
753 $this->assertContains(
'data/imgs/109x109xprosody.png', $files);
754 $this->assertContains(
'data/imgs/110x108xmetaphor1.png', $files);
755 $this->assertContains(
'data/imgs/fellows1-150x150.png', $files);
756 $this->assertContains(
'data/imgs/fibtriangle-110x110.jpg', $files);
757 $this->assertContains(
'data/imgs/uvalib.png', $files);
758 $this->assertContains(
'data/README.txt', $files);
761 $this->assertEquals(
'547b21e9c710f562d448a6cd7d32f8257b04e561',
$bag->manifest->data[
'data/imgs/109x109xcoins1-150x150.jpg']);
762 $this->assertEquals(
'fba552acae866d24fb143fef0ddb24efc49b097a',
$bag->manifest->data[
'data/imgs/109x109xprosody.png']);
763 $this->assertEquals(
'4beed314513ad81e1f5fad42672a3b1bd3a018ea',
$bag->manifest->data[
'data/imgs/110x108xmetaphor1.png']);
764 $this->assertEquals(
'4372383348c55775966bb1deeeb2b758b197e2a1',
$bag->manifest->data[
'data/imgs/fellows1-150x150.png']);
765 $this->assertEquals(
'b8593e2b3c2fa3756d2b206a90c7259967ff6650',
$bag->manifest->data[
'data/imgs/fibtriangle-110x110.jpg']);
766 $this->assertEquals(
'aec60202453733a976433833c9d408a449f136b3',
$bag->manifest->data[
'data/imgs/uvalib.png']);
767 $this->assertEquals(
'0de174b95ebacc2d91b0839cb2874b2e8f604b98',
$bag->manifest->data[
'data/README.txt']);
770 $data =
$bag->fetch->getData();
771 $this->assertEquals(
'http://www.scholarslab.org', $data[0][
'url']);
772 $this->assertEquals(
'data/index.html', $data[0][
'filename']);
777 $bagDir = __DIR__ .
'/TestBag';
780 $this->assertNull(
$bag->bagCompression);
781 $this->_testSampleBag(
$bag);
786 $bagZip = __DIR__ .
'/TestBag.zip';
789 $this->assertEquals(
'zip',
$bag->bagCompression);
790 $this->_testSampleBag(
$bag);
795 $bagTar = __DIR__ .
'/TestBag.tgz';
798 $this->assertEquals(
'tgz',
$bag->bagCompression);
799 $this->_testSampleBag(
$bag);
804 $this->assertTrue($this->bag->isValid());
809 $this->assertTrue($this->bag->isExtended());
815 $this->assertFalse(
$bag->isExtended());
829 $tmp .
"/bag-info.txt",
830 "Source-organization: University of Virginia Alderman Library\n" .
831 "Contact-name: Eric Rochester\n" .
832 "Bag-size: very, very small\n"
835 $this->assertFalse(
$bag->isExtended());
847 $bagInfo = $this->bag->getBagInfo();
849 $this->assertInternalType(
'array', $bagInfo);
851 $this->assertArrayHasKey(
'version', $bagInfo);
852 $this->assertArrayHasKey(
'encoding', $bagInfo);
853 $this->assertArrayHasKey(
'hash', $bagInfo);
855 $this->assertEquals(
'0.96', $bagInfo[
'version']);
856 $this->assertEquals(
'UTF-8', $bagInfo[
'encoding']);
857 $this->assertEquals(
'sha1', $bagInfo[
'hash']);
862 $dataDir = $this->bag->getDataDirectory();
863 $this->assertStringStartsWith($this->tmpdir, $dataDir);
868 $hash = $this->bag->getHashEncoding();
869 $this->assertEquals(
'sha1', $hash);
874 $this->bag->setHashEncoding(
'md5');
875 $this->assertEquals(
'md5', $this->bag->getHashEncoding());
880 $this->bag->setHashEncoding(
'md5');
881 $this->bag->setHashEncoding(
'sha1');
882 $this->assertEquals(
'sha1', $this->bag->getHashEncoding());
890 $this->bag->setHashEncoding(
'err');
895 $this->bag->setHashEncoding(
'md5');
896 $this->assertEquals(
'md5', $this->bag->manifest->getHashEncoding());
897 $this->assertEquals(
'md5', $this->bag->tagManifest->getHashEncoding());
902 $bagContents = $this->bag->getBagContents();
904 $this->assertInternalType(
'array', $bagContents);
905 $this->assertEquals(0, count($bagContents));
913 $tmp .
"/data/something.txt",
914 "Source-organization: University of Virginia Alderman Library\n" .
915 "Contact-name: Eric Rochester\n" .
916 "Bag-size: very, very small\n"
920 $bagContents =
$bag->getBagContents();
921 $this->assertEquals(1, count($bagContents));
922 $this->assertEquals($tmp .
'/data/something.txt', $bagContents[0]);
934 $bagErrors = $this->bag->getBagErrors();
935 $this->assertInternalType(
'array', $bagErrors);
936 $this->assertEquals(0, count($bagErrors));
938 rrmdir($this->bag->getDataDirectory());
939 $this->bag->validate();
940 $this->assertGreaterThan(0, count($this->bag->getBagErrors()));
945 rrmdir($this->bag->getDataDirectory());
946 $bagErrors = $this->bag->getBagErrors(
true);
947 $this->assertInternalType(
'array', $bagErrors);
948 $this->assertGreaterThan(0, count($bagErrors));
953 unlink($this->bag->bagitFile);
955 $this->bag->validate();
956 $bagErrors = $this->bag->getBagErrors();
958 $this->assertFalse($this->bag->isValid());
959 $this->assertTrue(seenAtKey($bagErrors, 0,
'bagit.txt'));
969 $tmp .
"/manifest-sha1.txt",
970 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa data/missing.txt\n"
972 mkdir($tmp .
'/data');
973 touch($tmp .
'/data/missing.txt');
976 $bagErrors =
$bag->getBagErrors();
978 $this->assertFalse(
$bag->isValid());
979 $this->assertTrue(seenAtKey($bagErrors, 0,
'data/missing.txt'));
980 $this->assertTrue(seenAtKey($bagErrors, 1,
'Checksum mismatch.'));
998 $this->assertFileExists($tmp .
'/bagit.txt');
999 $this->assertFileExists($tmp .
'/manifest-sha1.txt');
1000 $this->assertTrue(is_dir($tmp .
'/data'));
1003 catch (Exception $e)
1017 mkdir($tmp .
'/data');
1018 touch($tmp .
'/data/has space');
1019 touch($tmp .
'/data/PRN');
1020 touch($tmp .
'/data/backup~');
1021 touch($tmp .
'/data/.hidden');
1022 touch($tmp .
'/data/quoted "yep" quoted');
1027 $this->assertFalse(is_file($tmp .
'/data/has space'));
1028 $this->assertFileExists($tmp .
'/data/has_space');
1030 $this->assertFalse(is_file($tmp .
'/data/PRN'));
1031 $this->assertEquals(1, count(glob($tmp .
'/data/prn_*')));
1033 $this->assertFalse(is_file($tmp .
'/data/backup~'));
1035 $this->assertFalse(is_file($tmp .
'/data/quoted "yep" quoted'));
1036 $this->assertFileExists($tmp .
'/data/quoted_yep_quoted');
1039 catch (Exception $e)
1054 $tmp .
"/manifest-sha1.txt",
1055 "abababababababababababababababababababab data/missing.txt\n"
1057 mkdir($tmp .
'/data');
1059 $tmp .
'/data/missing.txt',
1060 "This space intentionally left blank.\n"
1065 $this->assertEquals(
1066 "a5c44171ca6618c6ee24c3f3f3019df8df09a2e0 data/missing.txt\n",
1067 file_get_contents($tmp .
'/manifest-sha1.txt')
1069 $this->assertEquals(
1070 'a5c44171ca6618c6ee24c3f3f3019df8df09a2e0',
1071 $bag->manifest->data[
'data/missing.txt']
1075 catch (Exception $e)
1089 mkdir($tmp .
'/data');
1091 $tmp .
'/data/missing.txt',
1092 "This space intentionally left blank.\n"
1097 $this->assertEquals(
1098 "a5c44171ca6618c6ee24c3f3f3019df8df09a2e0 data/missing.txt\n",
1099 file_get_contents($tmp .
'/manifest-sha1.txt')
1101 $this->assertEquals(
1102 'a5c44171ca6618c6ee24c3f3f3019df8df09a2e0',
1103 $bag->manifest->data[
'data/missing.txt']
1107 catch (Exception $e)
1122 $tmp .
"/manifest-sha1.txt",
1123 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd data/missing.txt\n"
1125 mkdir($tmp .
'/data');
1129 $this->assertEquals(
1131 file_get_contents($tmp .
'/manifest-sha1.txt')
1134 array_key_exists(
'data/missing.txt',
$bag->manifest->data)
1138 catch (Exception $e)
1154 $this->assertFileExists($tmp .
'/bag-info.txt');
1155 $this->assertFileExists($tmp .
'/tagmanifest-sha1.txt');
1156 $this->assertFileNotExists($tmp .
'/fetch.txt');
1159 catch (Exception $e)
1169 $srcdir = __DIR__ .
'/TestBag/data';
1171 $this->bag->addFile(
"$srcdir/README.txt",
'data/README.txt');
1173 $datadir = $this->bag->getDataDirectory();
1174 $this->assertFileExists(
"{$datadir}/README.txt");
1175 $this->assertFileEquals(
"$srcdir/README.txt",
"{$datadir}/README.txt");
1177 $this->bag->addFile(
"$srcdir/imgs/uvalib.png",
"data/pics/uvalib.png");
1179 $this->assertFileExists(
"{$datadir}/pics/uvalib.png");
1180 $this->assertFileEquals(
1181 "$srcdir/imgs/uvalib.png",
1182 "{$datadir}/pics/uvalib.png"
1188 $srcdir = __DIR__ .
'/TestBag/data';
1190 $this->bag->addFile(
"$srcdir/README.txt",
'README.txt');
1192 $datadir = $this->bag->getDataDirectory();
1193 $this->assertFileExists(
"{$datadir}/README.txt");
1194 $this->assertFileEquals(
"$srcdir/README.txt",
"{$datadir}/README.txt");
1196 $this->bag->addFile(
"$srcdir/imgs/uvalib.png",
"pics/uvalib.png");
1198 $this->assertFileExists(
"{$datadir}/pics/uvalib.png");
1199 $this->assertFileEquals(
1200 "$srcdir/imgs/uvalib.png",
1201 "{$datadir}/pics/uvalib.png"
1207 $testContent =
"This is some test content.";
1209 $this->bag->createFile($testContent,
"data/testCreateFile.txt");
1210 $datadir = $this->bag->getDataDirectory();
1211 $this->assertFileExists(
"{$datadir}/testCreateFile.txt");
1212 $content = file_get_contents(
"{$datadir}/testCreateFile.txt");
1213 $this->assertEquals($content, $testContent);
1218 $testContent =
"This is some test content.";
1220 $this->bag->createFile($testContent,
"testCreateFile.txt");
1221 $datadir = $this->bag->getDataDirectory();
1222 $this->assertFileExists(
"{$datadir}/testCreateFile.txt");
1223 $content = file_get_contents(
"{$datadir}/testCreateFile.txt");
1224 $this->assertEquals($content, $testContent);
1232 $testContent =
"This is some test content.";
1234 $this->bag->createFile($testContent,
"testCreateFile.txt");
1235 $this->bag->createFile(
'',
"testCreateFile.txt");
1245 $srcdir = __DIR__ .
'/TestBag/data';
1246 $this->bag->addFile(
"$srcdir/missing.txt",
'data/missing.txt');
1255 mkdir($tmp .
'/data');
1257 $tmp .
'/data/missing.txt',
1258 'This space intentionally left blank.\n'
1261 $tmp .
"/fetch.txt",
1262 "http://www.google.com - data/google/index.html\n" .
1263 "http://www.yahoo.com - data/yahoo/index.html\n"
1269 $bag->package($tmp .
'/../bagtmp1.zip',
'zip');
1270 $this->assertFileExists($tmp .
'/../bagtmp1.zip');
1272 $bag->package($tmp .
'/../bagtmp2',
'zip');
1273 $this->assertFileExists($tmp .
'/../bagtmp2.zip');
1278 catch (Exception $e)
1292 mkdir($tmp .
'/data');
1294 $tmp .
'/data/missing.txt',
1295 'This space intentionally left blank.\n'
1298 $tmp .
"/fetch.txt",
1299 "http://www.google.com - data/google/index.html\n" .
1300 "http://www.yahoo.com - data/yahoo/index.html\n"
1306 $bag->package($tmp .
'/../bagtmp1.tgz',
'tgz');
1307 $this->assertFileExists($tmp .
'/../bagtmp1.tgz');
1308 rename(
"{$tmp}/../bagtmp1.tgz",
"/tmp/bagtmp1.tgz");
1310 $bag->package($tmp .
'/../bagtmp2',
'tgz');
1311 $this->assertFileExists($tmp .
'/../bagtmp2.tgz');
1312 rename(
"{$tmp}/../bagtmp2.tgz",
"/tmp/bagtmp2.tgz");
1317 catch (Exception $e)
1333 $this->assertFileExists(
"$tmp/bagit.txt");
1334 $this->assertFileExists(
"$tmp/manifest-sha1.txt");
1335 $this->assertFileExists(
"$tmp/bag-info.txt");
1336 $this->assertFileNotExists(
"$tmp/fetch.txt");
1337 $this->assertFileExists(
"$tmp/tagmanifest-sha1.txt");
1339 catch (Exception $e)