From db335668a03be13becaa4a7a957b99e2e63940eb Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Tue, 9 Apr 2024 18:18:41 +0200 Subject: [PATCH] Add tests for name element --- tests/Mods/ModsReaderTest.php | 64 ++++++++++++++++++++++++++++++++--- tests/resources/mods_book.xml | 2 +- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/tests/Mods/ModsReaderTest.php b/tests/Mods/ModsReaderTest.php index e368f55..4071d3e 100644 --- a/tests/Mods/ModsReaderTest.php +++ b/tests/Mods/ModsReaderTest.php @@ -482,9 +482,46 @@ 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() @@ -492,8 +529,27 @@ 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() diff --git a/tests/resources/mods_book.xml b/tests/resources/mods_book.xml index 77a97f9..8b5cab9 100644 --- a/tests/resources/mods_book.xml +++ b/tests/resources/mods_book.xml @@ -9,7 +9,7 @@ Alterman, Eric. - creator + creator cre