From a8b40d304f55f8c53ea4c74aae9a58593ca28933 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Mon, 17 Jun 2024 12:31:30 +0200 Subject: [PATCH] Add tests for getting first and last element --- tests/Mods/ModsReaderTest.php | 112 +++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/tests/Mods/ModsReaderTest.php b/tests/Mods/ModsReaderTest.php index be1e8a5..bcce398 100644 --- a/tests/Mods/ModsReaderTest.php +++ b/tests/Mods/ModsReaderTest.php @@ -126,12 +126,24 @@ public function testGetAccessConditionsByQueryForBookDocument() self::assertEquals('use and reproduction', $accessConditions[0]->getType()); self::assertEmpty($accessConditions[0]->getDisplayLabel()); self::assertEmpty($accessConditions[0]->getXlinkHref()); + + $firstAccessCondition = $this->bookReader->getFirstAccessCondition('[@type="use and reproduction"]'); + self::assertEquals($accessConditions[0], $firstAccessCondition); + + $lastAccessCondition = $this->bookReader->getLastAccessCondition('[@type="use and reproduction"]'); + self::assertEquals($accessConditions[0], $lastAccessCondition); } public function testGetNoAccessConditionsByQueryForBookDocument() { $accessConditions = $this->bookReader->getAccessConditions('[@type="restriction on access"]'); self::assertEmpty($accessConditions); + + $firstAccessCondition = $this->bookReader->getFirstAccessCondition('[@type="use and reproduction"]'); + self::assertNull($firstAccessCondition); + + $lastAccessCondition = $this->bookReader->getLastAccessCondition('[@type="use and reproduction"]'); + self::assertNull($lastAccessCondition); } public function testGetAccessConditionsForSerialDocument() @@ -181,6 +193,12 @@ public function testGetClassificationsForBookDocument() self::assertEquals('lcc', $classifications[0]->getAuthority()); self::assertEmpty($classifications[0]->getId()); self::assertEmpty($classifications[0]->getUsage()); + + $firstClassification = $this->bookReader->getFirstClassification(); + self::assertEquals($classifications[0], $firstClassification); + + $lastClassification = $this->bookReader->getLastClassification(); + self::assertEquals($classifications[1], $lastClassification); } public function testGetClassificationsByQueryForBookDocument() @@ -198,8 +216,14 @@ public function testGetClassificationsByQueryForBookDocument() public function testGetNoClassificationsByQueryForBookDocument() { - $classifications = $this->bookReader->getAccessConditions('[@generator="xyz"]'); + $classifications = $this->bookReader->getClassifications('[@generator="xyz"]'); self::assertEmpty($classifications); + + $firstClassification = $this->bookReader->getFirstClassification('[@generator="xyz"]'); + self::assertNull($firstClassification); + + $lastClassification = $this->bookReader->getLastClassification('[@generator="xyz"]'); + self::assertNull($lastClassification); } public function testGetClassificationsForSerialDocument() @@ -282,6 +306,12 @@ public function testGetNoGenresByQueryForBookDocument() { $genres = $this->bookReader->getGenres('[@authority="merc"]'); self::assertEmpty($genres); + + $firstGenre = $this->bookReader->getFirstGenre('[@authority="merc"]'); + self::assertNull($firstGenre); + + $lastGenre = $this->bookReader->getLastGenre('[@authority="merc"]'); + self::assertNull($lastGenre); } public function testGetGenresForSerialDocument() @@ -295,6 +325,12 @@ public function testGetGenresForSerialDocument() self::assertEquals('primary', $genres[0]->getUsage()); self::assertEmpty($genres[0]->getDisplayLabel()); self::assertEmpty($genres[0]->getTransliteration()); + + $firstGenre = $this->bookReader->getFirstGenre(); + self::assertEquals($genres[0], $firstGenre); + + $lastGenre = $this->bookReader->getLastGenre(); + self::assertEquals($genres[1], $lastGenre); } public function testGetGenresByQueryForSerialDocument() @@ -327,6 +363,12 @@ public function testGetIdentifiersForBookDocument() self::assertEquals('isbn', $identifiers[0]->getType()); self::assertEmpty($identifiers[0]->getLang()); self::assertFalse($identifiers[0]->isInvalid()); + + $firstIdentifier = $this->bookReader->getFirstIdentifier(); + self::assertEquals($identifiers[0], $firstIdentifier); + + $lastIdentifier = $this->bookReader->getLastIdentifier(); + self::assertEquals($identifiers[1], $lastIdentifier); } public function testGetIdentifiersByQueryForBookDocument() @@ -346,6 +388,12 @@ public function testGetNoIdentifiersByQueryForBookDocument() { $identifiers = $this->bookReader->getIdentifiers('[@type="xyz"]'); self::assertEmpty($identifiers); + + $firstIdentifier = $this->bookReader->getFirstIdentifier('[@type="xyz"]'); + self::assertNull($firstIdentifier); + + $lastIdentifier = $this->bookReader->getLastIdentifier('[@type="xyz"]'); + self::assertNull($lastIdentifier); } public function testGetIdentifiersForSerialDocument() @@ -396,6 +444,12 @@ public function testGetLanguagesForBookDocument() self::assertEquals('code', $languages[0]->getScriptTerms()[0]->getType()); self::assertEquals('iso15924', $languages[0]->getScriptTerms()[0]->getAuthority()); self::assertEquals('Latn', $languages[0]->getScriptTerms()[0]->getValue()); + + $firstLanguage = $this->bookReader->getFirstLanguage(); + self::assertEquals($languages[0], $firstLanguage); + + $lastLanguage = $this->bookReader->getLastLanguage(); + self::assertEquals($languages[1], $lastLanguage); } public function testGetLanguagesByQueryForBookDocument() @@ -421,6 +475,12 @@ public function testGetNoLanguagesByQueryForBookDocument() { $languages = $this->bookReader->getLanguages('[@objectPart="abstract"]'); self::assertEmpty($languages); + + $firstLanguage = $this->bookReader->getFirstLanguage('[@objectPart="abstract"]'); + self::assertNull($firstLanguage); + + $lastLanguage = $this->bookReader->getLastLanguage('[@objectPart="abstract"]'); + self::assertNull($lastLanguage); } public function testGetLanguagesForSerialDocument() @@ -482,6 +542,12 @@ public function testGetLocationsForBookDocument() self::assertEquals('QH511.A1J68', $copyInformation[0]->getShelfLocators()[0]->getValue()); self::assertEquals('1', $copyInformation[0]->getEnumerationAndChronologies()[0]->getUnitType()); self::assertEquals('v.1-v.2 1999-2002', $copyInformation[0]->getEnumerationAndChronologies()[0]->getValue()); + + $firstLocation = $this->bookReader->getFirstLocation(); + self::assertEquals($locations[0], $firstLocation); + + $lastLocation = $this->bookReader->getLastLocation(); + self::assertEquals($locations[1], $lastLocation); } public function testGetLocationsByQueryForBookDocument() @@ -507,6 +573,12 @@ public function testGetNoLocationsByQueryForBookDocument() { $locations = $this->bookReader->getLocations('[@displayLabel="random"]'); self::assertEmpty($locations); + + $firstLocation = $this->bookReader->getFirstLocation('[@displayLabel="random"]'); + self::assertNull($firstLocation); + + $lastLocation = $this->bookReader->getLastLocation('[@displayLabel="random"]'); + self::assertNull($lastLocation); } public function testGetLocationsForSerialDocument() @@ -549,12 +621,19 @@ public function testGetNamesForBookDocument() 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()); + + $firstName = $this->bookReader->getFirstName(); + self::assertEquals($names[0], $firstName); + + $lastName = $this->bookReader->getLastName(); + self::assertEquals($names[1], $lastName); } public function testGetNamesByQueryForBookDocument() @@ -582,6 +661,12 @@ public function testGetNoNamesByQueryForBookDocument() { $names = $this->bookReader->getNames('[@type="corporate"]'); self::assertEmpty($names); + + $firstName = $this->bookReader->getFirstName('[@type="corporate"]'); + self::assertNull($firstName); + + $lastName = $this->bookReader->getLastName('[@type="corporate"]'); + self::assertNull($lastName); } public function testGetNamesForSerialDocument() @@ -621,6 +706,12 @@ public function testGetNotesForBookDocument() self::assertEquals('Eric Alterman.', $notes[0]->getValue()); self::assertNotEmpty($notes[0]->getType()); self::assertEquals('statement of responsibility', $notes[0]->getType()); + + $firstNote = $this->bookReader->getFirstNote(); + self::assertEquals($notes[0], $firstNote); + + $lastNote = $this->bookReader->getLastNote(); + self::assertEquals($notes[1], $lastNote); } public function testGetNotesByQueryForBookDocument() @@ -638,6 +729,12 @@ public function testGetNoNotesByQueryForBookDocument() { $notes = $this->bookReader->getNotes('[@type="xyz"]'); self::assertEmpty($notes); + + $firstNote = $this->bookReader->getFirstNote('[@type="xyz"]'); + self::assertNull($firstNote); + + $lastNote = $this->bookReader->getLastNote('[@type="xyz"]'); + self::assertNull($lastNote); } public function testGetNotesForSerialDocument() @@ -678,6 +775,7 @@ public function testGetOriginInfosForBookDocument() self::assertEquals('publication', $originInfos[0]->getEventType()); self::assertNotEmpty($originInfos[0]->getPlaces()); self::assertEquals(2, count($originInfos[0]->getPlaces())); + $placeTerms = $originInfos[0]->getPlaces()[0]->getPlaceTerms(); self::assertNotEmpty($placeTerms); self::assertEquals('marccountry', $placeTerms[0]->getAuthority()); @@ -689,6 +787,12 @@ public function testGetOriginInfosForBookDocument() self::assertEquals('2000', $originInfos[0]->getIssuedDates()[0]->getValue()); self::assertNotEmpty($originInfos[0]->getIssuances()); self::assertEquals('monographic', $originInfos[0]->getIssuances()[0]->getValue()); + + $firstOriginInfo = $this->bookReader->getFirstOriginInfo(); + self::assertEquals($originInfos[0], $firstOriginInfo); + + $lastOriginInfo = $this->bookReader->getLastOriginInfo(); + self::assertEquals($originInfos[1], $lastOriginInfo); } public function testGetOriginInfosByQueryForBookDocument() @@ -804,6 +908,12 @@ public function testGetPartsForBookDocument() self::assertEquals('1989', $parts[0]->getDates()[0]->getValue()); self::assertNotEmpty($parts[0]->getTexts()); self::assertEquals('Some random text', $parts[0]->getTexts()[0]->getValue()); + + $firstPart = $this->bookReader->getFirstPart(); + self::assertEquals($parts[0], $firstPart); + + $lastPart = $this->bookReader->getLastPart(); + self::assertEquals($parts[1], $lastPart); } public function testGetPartsByQueryForBookDocument()