public function testIsExtended() { $this->assertTrue($this->bag->isExtended()); $tmp = tmpdir(); try { $bag = new BagIt($tmp, false, false); $this->assertFalse($bag->isExtended()); } catch (Exception $e) { rrmdir($tmp); throw $e; } rrmdir($tmp); $tmp = tmpdir(); try { mkdir($tmp); file_put_contents($tmp . "/bag-info.txt", "Source-organization: University of Virginia Alderman Library\n" . "Contact-name: Eric Rochester\n" . "Bag-size: very, very small\n"); $bag = new BagIt($tmp, false, false); $this->assertFalse($bag->isExtended()); } catch (Exception $e) { rrmdir($tmp); throw $e; } rrmdir($tmp); }
/** * This is the use case for consuming a bag from someone else. The user * does these actions: * * <ol> * <li>Open the bag;</li> * <li>Validate the downloaded contents;</li> * <li>Fetch on-line items in the bag;</li> * <li>Validate the bag's contents; and</li> * <li>Copy items from the bag onto the local disk.</li> * </ol> */ public function testBagConsumer() { $srcbag = __DIR__ . '/TestBag.tgz'; // 1. Open the bag; $bag = new BagIt($srcbag); $this->queueRm($bag->bagDirectory); $this->assertTrue($bag->isValid()); $this->assertTrue($bag->isExtended()); $bagInfo = $bag->getBagInfo(); $this->assertEquals('0.96', $bagInfo['version']); $this->assertEquals('UTF-8', $bagInfo['encoding']); $this->assertEquals('sha1', $bagInfo['hash']); $this->assertEquals('sha1', $bag->getHashEncoding()); $this->assertEquals(7, count($bag->getBagContents())); $this->assertEquals(0, count($bag->getBagErrors())); // 2. Validate the downloaded contents; $bag->validate(); $this->assertEquals(0, count($bag->getBagErrors())); // 3. Fetch on-line items in the bag; $bag->fetch->download(); $bag->update(); $bag->validate(); $this->assertEquals(8, count($bag->getBagContents())); // 4. Validate the bag's contents; and $this->assertEquals(0, count($bag->getBagErrors())); // 5. Copy items from the bag onto the local disk. $tmpdir = tmpdir(); mkdir($tmpdir); $this->queueRm($tmpdir); foreach ($bag->getBagContents() as $bagFile) { $basename = basename($bagFile); copy($bagFile, "{$tmpdir}/{$basename}"); } $this->assertEquals(count($bag->getBagContents()) + 2, count(scandir($tmpdir))); $this->assertEquals(count($bag->manifest->getData()) + 2, count(scandir($tmpdir))); }