Skip to content

Commit

Permalink
Add tests for exception
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Apr 16, 2024
1 parent a95a48c commit c75ce69
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
10 changes: 1 addition & 9 deletions src/Mods/Element/Specific/Location/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,10 @@ public function __construct(\SimpleXMLElement $xml)
* @access public
*
* @return string
*
* @throws IncorrectValueInAttributeException
*/
public function getDateLastAccessed(): string
{
$dateLastAccessed = $this->getStringAttribute('dateLastAccessed');

if (empty($dateLastAccessed) || in_array($dateLastAccessed, $this->allowedAccess)) {
return $dateLastAccessed;
}

throw new IncorrectValueInAttributeException('dateLastAccessed', $dateLastAccessed);
return $this->getStringAttribute('dateLastAccessed');
}

/**
Expand Down
22 changes: 17 additions & 5 deletions tests/Mods/ModsReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Slub\Mods;

use PHPUnit\Framework\TestCase;
use Slub\Mods\Exception\IncorrectValueInAttributeException;

class ModsReaderTest extends TestCase
{
Expand Down Expand Up @@ -497,6 +498,9 @@ public function testGetLocationsByQueryForBookDocument()
self::assertEquals('http://www.slub-dresden.de/some-url', $urls[0]->getValue());
self::assertEquals('preview', $urls[1]->getAccess());
self::assertEquals('http://www.slub-dresden.de/some-url/SLO-0000', $urls[1]->getValue());

$this->expectException(IncorrectValueInAttributeException::class);
$urls[3]->getAccess();
}

public function testGetNoLocationsByQueryForBookDocument()
Expand All @@ -512,18 +516,18 @@ public function testGetLocationsForSerialDocument()
self::assertEquals(2, count($locations));
self::assertNotEmpty($locations[0]->getUrls());
self::assertEquals('electronic resource', $locations[0]->getUrls()[0]->getDisplayLabel());
self::assertEquals('primary display', $locations[0]->getUrls()[0]->getUsage());
self::assertEquals('primaryDisplay', $locations[0]->getUrls()[0]->getUsage());
self::assertEquals('http://bibpurl.oclc.org/web/7085', $locations[0]->getUrls()[0]->getValue());
}

public function testGetLocationsByQueryForSerialDocument()
{
$locations = $this->serialReader->getLocations('[./mods:url[@usage="primary display"]]');
$locations = $this->serialReader->getLocations('[./mods:url[@usage="primaryDisplay"]]');
self::assertNotEmpty($locations);
self::assertEquals(1, count($locations));
self::assertNotEmpty($locations[0]->getUrls());
self::assertEquals('electronic resource', $locations[0]->getUrls()[0]->getDisplayLabel());
self::assertEquals('primary display', $locations[0]->getUrls()[0]->getUsage());
self::assertEquals('primaryDisplay', $locations[0]->getUrls()[0]->getUsage());
self::assertEquals('http://bibpurl.oclc.org/web/7085', $locations[0]->getUrls()[0]->getValue());
}

Expand Down Expand Up @@ -968,7 +972,10 @@ public function testGetRecordInfosForSerialDocument()
self::assertEquals('marcorg', $recordInfos[0]->getRecordContentSources()[0]->getAuthority());
self::assertEquals('NLC', $recordInfos[0]->getRecordContentSources()[0]->getValue());
self::assertNotEmpty($recordInfos[0]->getRecordCreationDates());
self::assertEquals('marc', $recordInfos[0]->getRecordCreationDates()[0]->getEncoding());

$this->expectException(IncorrectValueInAttributeException::class);
$recordInfos[0]->getRecordCreationDates()[0]->getEncoding();

self::assertEquals('021127', $recordInfos[0]->getRecordCreationDates()[0]->getValue());
self::assertNotEmpty($recordInfos[0]->getRecordChangeDates());
self::assertEquals('iso8601', $recordInfos[0]->getRecordChangeDates()[0]->getEncoding());
Expand All @@ -979,6 +986,7 @@ public function testGetRecordInfosForSerialDocument()
self::assertNotEmpty($recordInfos[0]->getRecordInfoNotes());
self::assertEquals(2, count($recordInfos[0]->getRecordInfoNotes()));
self::assertEquals('Some info', $recordInfos[0]->getRecordInfoNotes()[1]->getValue());

$languages = $recordInfos[0]->getLanguageOfCatalogings();
self::assertNotEmpty($languages);
self::assertNotNull($languages[0]->getLanguageTerm());
Expand All @@ -1003,7 +1011,10 @@ public function testGetRecordInfosByQueryForSerialDocument()
self::assertEquals('marcorg', $recordInfos[0]->getRecordContentSources()[0]->getAuthority());
self::assertEquals('NLC', $recordInfos[0]->getRecordContentSources()[0]->getValue());
self::assertNotEmpty($recordInfos[0]->getRecordCreationDates());
self::assertEquals('marc', $recordInfos[0]->getRecordCreationDates()[0]->getEncoding());

$this->expectException(IncorrectValueInAttributeException::class);
$recordInfos[0]->getRecordCreationDates()[0]->getEncoding();

self::assertEquals('021127', $recordInfos[0]->getRecordCreationDates()[0]->getValue());
self::assertNotEmpty($recordInfos[0]->getRecordChangeDates());
self::assertEquals('iso8601', $recordInfos[0]->getRecordChangeDates()[0]->getEncoding());
Expand All @@ -1014,6 +1025,7 @@ public function testGetRecordInfosByQueryForSerialDocument()
self::assertNotEmpty($recordInfos[0]->getRecordInfoNotes());
self::assertEquals(2, count($recordInfos[0]->getRecordInfoNotes()));
self::assertEquals('Some info', $recordInfos[0]->getRecordInfoNotes()[1]->getValue());

$languages = $recordInfos[0]->getLanguageOfCatalogings();
self::assertNotEmpty($languages);
self::assertNotNull($languages[0]->getLanguageTerm());
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 @@ -137,7 +137,7 @@
<url dateLastAccessed="2024-01-27">http://www.slub-dresden.de/some-url</url>
<url access="preview">http://www.slub-dresden.de/some-url/SLO-0000</url>
<url access="object in context">http://www.slub-dresden.de/some-url/SLO-0000</url>
<url access="raw object">http://www.slub-dresden.de/some-url/SLO-0000</url>
<url access="raw">http://www.slub-dresden.de/some-url/SLO-0000</url>
</location>
<accessCondition type="use and reproduction">Use of this public-domain resource is unrestricted.</accessCondition>
<part type="poem" order="1">
Expand Down
4 changes: 2 additions & 2 deletions tests/resources/mods_serial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
</subject>
<classification authority="ddc" edition="21">027.7/05</classification>
<location>
<url displayLabel="electronic resource" usage="primary display">http://bibpurl.oclc.org/web/7085</url>
<url displayLabel="electronic resource" usage="primaryDisplay">http://bibpurl.oclc.org/web/7085</url>
</location>
<location>
<url displayLabel="electronic resource">http://collection.nlc-bnc.ca/100/201/300/ejasl/index.html</url>
Expand All @@ -109,7 +109,7 @@
<recordInfo>
<descriptionStandard>aacr</descriptionStandard>
<recordContentSource authority="marcorg">NLC</recordContentSource>
<recordCreationDate encoding="marc">021127</recordCreationDate>
<recordCreationDate encoding="not allowed">021127</recordCreationDate>
<recordChangeDate encoding="iso8601">20080910160139.0</recordChangeDate>
<recordIdentifier>15446420</recordIdentifier>
<recordOrigin>Converted from MARCXML to MODS version 3.8 using MARC21slim2MODS3-8_XSLT1-0.xsl (Revision 1.172 20230208)</recordOrigin>
Expand Down

0 comments on commit c75ce69

Please sign in to comment.