コード例 #1
0
 /**
  * This is a use case for creating and populating a new bag. The user
  * does these actions:
  *
  * <ol>
  * <li>Create a new bag;</li>
  * <li>Add files to the bag;</li>
  * <li>Add fetch entries;</li>
  * <li>Update the bag; and</li>
  * <li>Package the bag.</li>
  * </ol>
  */
 public function testBagProducer()
 {
     $tmpdir = tmpdir();
     mkdir($tmpdir);
     $this->queueRm($tmpdir);
     $tmpbag = "{$tmpdir}/BagProducer";
     // 1. Create a new bag;
     $bag = new BagIt($tmpbag);
     $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("{$tmpbag}/data", $bag->getDataDirectory());
     $this->assertEquals('sha1', $bag->getHashEncoding());
     $this->assertEquals(0, count($bag->getBagContents()));
     $this->assertEquals(0, count($bag->getBagErrors()));
     // 2. Add files to the bag;
     $srcdir = __DIR__ . '/TestBag/data';
     $bag->addFile("{$srcdir}/README.txt", 'data/README.txt');
     $bag->addFile("{$srcdir}/imgs/uvalib.png", 'data/payloads/uvalib.png');
     // This needs to add data/ to the beginning of the file.
     $bag->addFile("{$srcdir}/imgs/fibtriangle-110x110.jpg", 'payloads/fibtri.jpg');
     // 3. Add fetch entries;
     $bag->fetch->add('http://www.scholarslab.org/', 'data/index.html');
     // 4. Update the bag; and
     $bag->update();
     // 5. Package the bag.
     $pkgfile = "{$tmpdir}/BagProducer.tgz";
     $bag->package($pkgfile);
     // Finally, we need to validate the contents of the package.
     $dest = new BagIt($pkgfile);
     $this->queueRm($dest->bagDirectory);
     // First, verify that the data files are correct.
     $this->assertEquals("BagIt-Version: 0.96\n" . "Tag-File-Character-Encoding: UTF-8\n", file_get_contents($dest->bagitFile));
     // Second, verify that everything was uncompressed OK.
     $dest->validate();
     $this->assertEquals(0, count($dest->bagErrors));
     // Now, check that the file was fetched.
     $dest->fetch->download();
     $this->assertFileExists("{$dest->bagDirectory}/data/index.html");
     // Also, check that fibtri.jpg was added in the data/ directory.
     $this->assertFalse(file_exists("{$dest->bagDirectory}/payloads/fibtri.jpg"));
     $this->assertFileExists("{$dest->bagDirectory}/data/payloads/fibtri.jpg");
 }
コード例 #2
0
ファイル: testbagit.php プロジェクト: Dragonpurse/mediamosa
 public function testConstructorFetch()
 {
     $tmp = tmpdir();
     try {
         mkdir($tmp);
         file_put_contents($tmp . "/fetch.txt", "http://www.google.com - google/index.html\n" . "http://www.yahoo.com - yahoo/index.html\n");
         $bag = new BagIt($tmp, false, true, false);
         $this->assertFalse(is_file($bag->getDataDirectory() . '/google/index.html'));
         $this->assertFalse(is_file($bag->getDataDirectory() . '/yahoo/index.html'));
     } catch (Exception $e) {
         rrmdir($tmp);
         throw $e;
     }
     rrmdir($tmp);
     $tmp = tmpdir();
     try {
         mkdir($tmp);
         file_put_contents($tmp . "/fetch.txt", "http://www.google.com - data/google/index.html\n" . "http://www.yahoo.com - data/yahoo/index.html\n");
         $bag = new BagIt($tmp, false, true, true);
         $this->assertFileExists($bag->getDataDirectory() . '/google/index.html');
         $this->assertFileExists($bag->getDataDirectory() . '/yahoo/index.html');
     } catch (Exception $e) {
         rrmdir($tmp);
         throw $e;
     }
     rrmdir($tmp);
 }