Skip to content

Commit

Permalink
Add tests for getting first and last element
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Jun 17, 2024
1 parent 745033a commit a8af667
Showing 1 changed file with 111 additions and 1 deletion.
112 changes: 111 additions & 1 deletion tests/Mods/ModsReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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="restriction on access"]');
self::assertNull($firstAccessCondition);

$lastAccessCondition = $this->bookReader->getLastAccessCondition('[@type="restriction on access"]');
self::assertNull($lastAccessCondition);
}

public function testGetAccessConditionsForSerialDocument()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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());
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a8af667

Please sign in to comment.