3 require_once
'lib/bagit.php';
12 private function queueRm($dirname)
14 array_push($this->to_rm, $dirname);
19 $this->to_rm = array();
24 foreach ($this->to_rm as $dirname)
46 $this->queueRm($tmpdir);
48 $tmpbag =
"$tmpdir/BagProducer";
51 $bag =
new BagIt($tmpbag);
53 $this->assertTrue($bag->isValid());
54 $this->assertTrue($bag->isExtended());
56 $bagInfo = $bag->getBagInfo();
57 $this->assertEquals(
'0.96', $bagInfo[
'version']);
58 $this->assertEquals(
'UTF-8', $bagInfo[
'encoding']);
59 $this->assertEquals(
'sha1', $bagInfo[
'hash']);
61 $this->assertEquals(
"$tmpbag/data", $bag->getDataDirectory());
62 $this->assertEquals(
'sha1', $bag->getHashEncoding());
63 $this->assertEquals(0, count($bag->getBagContents()));
64 $this->assertEquals(0, count($bag->getBagErrors()));
67 $srcdir = __DIR__ .
'/TestBag/data';
68 $bag->addFile(
"$srcdir/README.txt",
'data/README.txt');
69 $bag->addFile(
"$srcdir/imgs/uvalib.png",
'data/payloads/uvalib.png');
72 "$srcdir/imgs/fibtriangle-110x110.jpg",
77 $bag->fetch->add(
'http://www.scholarslab.org/',
'data/index.html');
83 $pkgfile =
"$tmpdir/BagProducer.tgz";
84 $bag->package($pkgfile);
87 $dest =
new BagIt($pkgfile);
88 $this->queueRm($dest->bagDirectory);
92 "BagIt-Version: 0.96\n" .
93 "Tag-File-Character-Encoding: UTF-8\n",
94 file_get_contents($dest->bagitFile)
99 $this->assertEquals(0, count($dest->bagErrors));
102 $dest->fetch->download();
103 $this->assertFileExists(
"{$dest->bagDirectory}/data/index.html");
107 file_exists(
"{$dest->bagDirectory}/payloads/fibtri.jpg")
109 $this->assertFileExists(
"{$dest->bagDirectory}/data/payloads/fibtri.jpg");
127 $srcbag = __DIR__ .
'/TestBag.tgz';
130 $bag =
new BagIt($srcbag);
131 $this->queueRm($bag->bagDirectory);
133 $this->assertTrue($bag->isValid());
134 $this->assertTrue($bag->isExtended());
136 $bagInfo = $bag->getBagInfo();
137 $this->assertEquals(
'0.96', $bagInfo[
'version']);
138 $this->assertEquals(
'UTF-8', $bagInfo[
'encoding']);
139 $this->assertEquals(
'sha1', $bagInfo[
'hash']);
141 $this->assertEquals(
'sha1', $bag->getHashEncoding());
142 $this->assertEquals(7, count($bag->getBagContents()));
143 $this->assertEquals(0, count($bag->getBagErrors()));
147 $this->assertEquals(0, count($bag->getBagErrors()));
150 $bag->fetch->download();
153 $this->assertEquals(8, count($bag->getBagContents()));
156 $this->assertEquals(0, count($bag->getBagErrors()));
161 $this->queueRm($tmpdir);
163 foreach ($bag->getBagContents() as $bagFile)
165 $basename = basename($bagFile);
166 copy($bagFile,
"$tmpdir/$basename");
170 count($bag->getBagContents()) + 2,
171 count(scandir($tmpdir))
174 count($bag->manifest->getData()) + 2,
175 count(scandir($tmpdir))