Skip to content

Commit

Permalink
Add tests for name element
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Apr 9, 2024
1 parent fc5a2a4 commit 542cd37
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
64 changes: 60 additions & 4 deletions tests/Mods/ModsReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,74 @@ public function testGetNamesForBookDocument()
$names = $this->bookReader->getNames();
self::assertNotEmpty($names);
self::assertEquals(2, count($names));

// TODO: implement reading of name elements
self::assertNotEmpty($names[0]->getType());
self::assertEquals('personal', $names[0]->getType());
self::assertNotEmpty($names[0]->getUsage());
self::assertEquals('primary', $names[0]->getUsage());
self::assertNotEmpty($names[0]->getValue());
self::assertNotEmpty($names[0]->getNameParts());
self::assertEquals('Alterman, Eric.', $names[0]->getNameParts()[0]->getValue());
$roles = $names[0]->getRoles();
self::assertNotEmpty($roles);
self::assertNotEmpty($roles[0]->getRoleTerms());
self::assertEquals('text', $roles[0]->getRoleTerms()[0]->getType());
self::assertEquals('marcrelator', $roles[0]->getRoleTerms()[0]->getAuthority());
self::assertEquals('creator', $roles[0]->getRoleTerms()[0]->getValue());
}

public function testGetNamesByQueryForBookDocument()
{
$names = $this->bookReader->getNames('[@type="personal" and not(@usage="primary")]');
self::assertNotEmpty($names);
self::assertEquals(1, count($names));
self::assertNotEmpty($names[0]->getType());
self::assertEquals('personal', $names[0]->getType());
self::assertEmpty($names[0]->getUsage());
self::assertNotEmpty($names[0]->getValue());
self::assertNotEmpty($names[0]->getNameParts());
self::assertEquals(2, count($names[0]->getNameParts()));
self::assertEquals('given', $names[0]->getNameParts()[0]->getType());
self::assertEquals('Aron', $names[0]->getNameParts()[0]->getValue());
$roles = $names[0]->getRoles();
self::assertNotEmpty($roles);
self::assertNotEmpty($roles[0]->getRoleTerms());
self::assertEquals('text', $roles[0]->getRoleTerms()[0]->getType());
self::assertEquals('marcrelator', $roles[0]->getRoleTerms()[0]->getAuthority());
self::assertEquals('author', $roles[0]->getRoleTerms()[0]->getValue());
}

public function testGetNoNamesByQueryForBookDocument()
{
$names = $this->bookReader->getNames('[@type="corporate"]');
self::assertEmpty($names);
}

public function testGetNamesForSerialDocument()
{
$names = $this->serialReader->getNames();
self::assertNotEmpty($names);
self::assertEquals(1, count($names));

// TODO: implement reading of name elements
self::assertNotEmpty($names[0]->getValue());
self::assertNotEmpty($names[0]->getNameParts());
self::assertEquals(1, count($names[0]->getNameParts()));
self::assertEquals('International Consortium for the Advancement of Academic Publication.', $names[0]->getNameParts()[0]->getValue());
}

public function testGetNamesByQueryForSerialDocument()
{
$names = $this->serialReader->getNames('[@type="corporate"]');
self::assertNotEmpty($names);
self::assertEquals(1, count($names));
self::assertNotEmpty($names[0]->getValue());
self::assertNotEmpty($names[0]->getNameParts());
self::assertEquals(1, count($names[0]->getNameParts()));
self::assertEquals('International Consortium for the Advancement of Academic Publication.', $names[0]->getNameParts()[0]->getValue());
}

public function testGetNoNamesByQueryForSerialDocument()
{
$names = $this->serialReader->getNames('[@type="personal"]');
self::assertEmpty($names);
}

public function testGetNotesForBookDocument()
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/mods_book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<name type="personal" usage="primary">
<namePart>Alterman, Eric.</namePart>
<role>
<roleTerm type="text" authroity="marcrelator">creator</roleTerm>
<roleTerm type="text" authority="marcrelator">creator</roleTerm>
<roleTerm type="code" authority="marcrelator">cre</roleTerm>
<roleTerm valueURI="http://id.loc.gov/vocabulary/relators/cre"/>
</role>
Expand Down

0 comments on commit 542cd37

Please sign in to comment.