-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read BagIt Profile identifiers from bag-info.txt and validate
Additional tests Handle long lines without a space to break at
- Loading branch information
Showing
4 changed files
with
155 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
namespace whikloj\BagItTools\Test\Profiles; | ||
|
||
use whikloj\BagItTools\Bag; | ||
use whikloj\BagItTools\Profiles\BagItProfile; | ||
use whikloj\BagItTools\Exceptions\BagItException; | ||
use whikloj\BagItTools\Profiles\ProfileFactory; | ||
use whikloj\BagItTools\Test\BagItWebserverFramework; | ||
|
||
|
@@ -54,10 +54,19 @@ public static function setUpBeforeClass(): void | |
'content' => $profileJson, | ||
'path' => 'bagit-test-profile.json', | ||
], | ||
'test-profile-bag.json' => [ | ||
'filename' => self::TEST_RESOURCES . '/profiles/test-profile-bag.json', | ||
], | ||
]; | ||
parent::setUpBeforeClass(); | ||
} | ||
|
||
/** | ||
* @group Profiles | ||
* @covers \whikloj\BagItTools\Bag::addBagProfileByURL | ||
* @covers \whikloj\BagItTools\Bag::addBagProfileInternal | ||
* @covers \whikloj\BagItTools\Profiles\BagItProfile::validateBag | ||
*/ | ||
public function testAddProfileToBagUri(): void | ||
{ | ||
$profile = ProfileFactory::generateProfileFromUri(self::$remote_urls[0]); | ||
|
@@ -100,4 +109,69 @@ public function testAddSameProfileTwiceByUri(): void | |
$bag->removeBagProfile("http://www.library.yale.edu/mssa/bagitprofiles/disk_images.json"); | ||
$this->assertCount(0, $bag->getBagProfiles()); | ||
} | ||
|
||
/** | ||
* @group Profiles | ||
* @covers \whikloj\BagItTools\Profiles\BagItProfile::validateBag | ||
*/ | ||
public function testBagDoesntSupportSerialization(): void | ||
{ | ||
$bag = Bag::create($this->tmpdir); | ||
$bag->addBagInfoTag('BagIt-Profile-Identifier', trim(self::$remote_urls[1])); | ||
$bag->addBagInfoTag('Contact-Name', 'Some Person'); | ||
$bag->addBagInfoTag('Contact-Phone', '555-555-5555'); | ||
$bag->addBagInfoTag('Contact-Email', '[email protected]'); | ||
$bag->addBagInfoTag('Contact-Address', '1234 Some Street, Some City, Some State, 12345'); | ||
$bag->addBagInfoTag('Source-Organization', 'BagItTools'); | ||
$tmpfile = $this->getTempName(); | ||
file_put_contents($tmpfile, "CUSTOM-TAG-ID: 1234\nCUSTOM-TAG-ORG: 5678\n"); | ||
$bag->addTagFile($tmpfile, 'tagFiles/special-tags.txt'); | ||
$bag->createFile( | ||
"This is an example test file in the TestProfileBag. It is used to test the\n" . | ||
"validation of a profile.", | ||
"example-file.txt" | ||
); | ||
$bag->addAlgorithm('sha1'); | ||
$tmpPackage = $this->getTempName() . ".tgz"; | ||
$bag->package($tmpPackage); | ||
$this->assertFileExists($tmpPackage); | ||
|
||
$new_bag = Bag::load($tmpPackage); | ||
$this->assertFalse($new_bag->isValid()); | ||
$this->assertCount(1, $new_bag->getErrors()); | ||
$error = $new_bag->getErrors()[0]; | ||
$this->assertEquals( | ||
[ | ||
"file" => "http://example.org/example/test-profile-bag.json", | ||
"message" => "Profile allows for serialization MIME type (application/zip) but the bag has MIME " . | ||
"type (application/gzip)" | ||
], | ||
$error | ||
); | ||
} | ||
|
||
/** | ||
* @group Profiles | ||
* @covers \whikloj\BagItTools\Profiles\BagItProfile::validateBag | ||
*/ | ||
public function testProfileMissingRequiredTag(): void | ||
{ | ||
$bag = Bag::create($this->tmpdir); | ||
$bag->addBagInfoTag('BagIt-Profile-Identifier', trim(self::$remote_urls[1])); | ||
$bag->addBagInfoTag('Contact-Name', 'Some Person'); | ||
$bag->addBagInfoTag('Source-Organization', 'BagItTools'); | ||
$tmpfile = $this->getTempName(); | ||
file_put_contents($tmpfile, "CUSTOM-TAG-ID: 1234\nCUSTOM-TAG-ORG: 5678\n"); | ||
$bag->addTagFile($tmpfile, 'tagFiles/special-tags.txt'); | ||
$bag->createFile( | ||
"This is an example test file in the TestProfileBag. It is used to test the\n" . | ||
"validation of a profile.", | ||
"example-file.txt" | ||
); | ||
$bag->addAlgorithm('sha1'); | ||
$tmpPackage = $this->getTempName() . ".zip"; | ||
$this->expectException(BagItException::class); | ||
$this->expectExceptionMessage("Bag is not valid, cannot package."); | ||
$bag->package($tmpPackage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"BagIt-Profile-Info":{ | ||
"BagIt-Profile-Identifier":"http://example.org/example/test-profile-bag.json", | ||
"BagIt-Profile-Version": "1.4.0", | ||
"Source-Organization":"BagItTools", | ||
"Contact-Name":"BagItTools Developers", | ||
"External-Description":"BagIt Profile for testing loading of a bag with a profile", | ||
"Version":"1.2" | ||
}, | ||
"Bag-Info": { | ||
"Contact-Name": { | ||
"required": true | ||
}, | ||
"Contact-Email": { | ||
"required": true | ||
}, | ||
"Source-Organization": { | ||
"required": true, | ||
"values": [ | ||
"BagItTools" | ||
] | ||
} | ||
}, | ||
"Manifests-Required":[ | ||
"sha1" | ||
], | ||
"Accept-Serialization":[ | ||
"application/zip" | ||
], | ||
"Tag-Files-Required":[ | ||
"bagit.txt", | ||
"bag-info.txt", | ||
"tagFiles/special-tags.txt" | ||
] | ||
} |