Skip to content

Commit

Permalink
Implement tests for subject element
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Apr 11, 2024
1 parent 765f9c8 commit e9a5fcc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/Mods/Element/Specific/Subject/HierarchicalGeographic.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function getTerritories(string $query = ''): array
public function getCounties(string $query = ''): array
{
$counties = [];
$xpath = './mods:territory' . $query;
$xpath = './mods:county' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
Expand All @@ -193,7 +193,7 @@ public function getCounties(string $query = ''): array
public function getCities(string $query = ''): array
{
$cities = [];
$xpath = './mods:territory' . $query;
$xpath = './mods:city' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
Expand All @@ -216,7 +216,7 @@ public function getCities(string $query = ''): array
public function getCitySections(string $query = ''): array
{
$sections = [];
$xpath = './mods:section' . $query;
$xpath = './mods:citySection' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
Expand All @@ -239,7 +239,7 @@ public function getCitySections(string $query = ''): array
public function getIslands(string $query = ''): array
{
$islands = [];
$xpath = './mods:territory' . $query;
$xpath = './mods:island' . $query;
$element = new Element($this->xml, $xpath);
if ($element->exists()) {
foreach ($element->getValues() as $value) {
Expand Down
57 changes: 40 additions & 17 deletions tests/Mods/ModsReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,24 +931,44 @@ public function testGetSubjectsForBookDocument()
{
$subjects = $this->bookReader->getSubjects();
self::assertNotEmpty($subjects);
self::assertEquals(7, count($subjects));
self::assertEquals(8, count($subjects));
self::assertNotEmpty($subjects[0]->getValue());
//self::assertNotEmpty($subjects[0]->getTopic());
//self::assertNotEmpty($subjects[0]->getGeographic());

// TODO: implement reading of elements
$hierarchicalGeographics = $subjects[0]->getHierarchicalGeographics();
self::assertNotEmpty($hierarchicalGeographics);
self::assertNotEmpty($hierarchicalGeographics[0]->getCountries());
self::assertEquals(2, count($hierarchicalGeographics[0]->getCountries()));
self::assertEquals(1, $hierarchicalGeographics[0]->getCountries()[0]->getLevel());
self::assertEquals('United Kingdom', $hierarchicalGeographics[0]->getCountries()[0]->getValue());
self::assertNotEmpty($hierarchicalGeographics[0]->getRegions());
self::assertEquals('North West', $hierarchicalGeographics[0]->getRegions()[0]->getValue());
self::assertNotEmpty($hierarchicalGeographics[0]->getCounties());
self::assertEquals('Cumbria', $hierarchicalGeographics[0]->getCounties()[0]->getValue());
self::assertNotEmpty($hierarchicalGeographics[0]->getCities());
self::assertEquals('Providence', $hierarchicalGeographics[0]->getCities()[0]->getValue());
self::assertNotEmpty($hierarchicalGeographics[0]->getCitySections());
self::assertEquals(2, count($hierarchicalGeographics[0]->getCitySections()));
self::assertEquals('neighborhood', $hierarchicalGeographics[0]->getCitySections()[0]->getType());
self::assertEquals(1, $hierarchicalGeographics[0]->getCitySections()[0]->getLevel());
self::assertEquals('East Side', $hierarchicalGeographics[0]->getCitySections()[0]->getValue());
self::assertNotEmpty($hierarchicalGeographics[0]->getAreas());
self::assertEquals('national park', $hierarchicalGeographics[0]->getAreas()[0]->getType());
self::assertEquals('Lake District', $hierarchicalGeographics[0]->getAreas()[0]->getValue());
}

public function testGetSubjectsByQueryForBookDocument()
{
$subjects = $this->bookReader->getSubjects('[./mods:topic="Mass media"]');
self::assertNotEmpty($subjects);
self::assertEquals(1, count($subjects));
self::assertNotEmpty($subjects[0]->getAuthority());
self::assertEquals('lcsh', $subjects[0]->getAuthority());
self::assertNotEmpty($subjects[0]->getValue());
//self::assertNotEmpty($subjects[0]->getTopic());
//self::assertNotEmpty($subjects[0]->getGeographic());

// TODO: implement reading of elements
self::assertNotEmpty($subjects[0]->getTopics());
self::assertEquals(2, count($subjects[0]->getTopics()));
self::assertEquals('Political aspects', $subjects[0]->getTopics()[1]->getValue());
self::assertNotEmpty($subjects[0]->getGeographics());
self::assertEquals(1, count($subjects[0]->getGeographics()));
self::assertEquals('United States', $subjects[0]->getGeographics()[0]->getValue());
}

public function testGetNoSubjectsByQueryForBookDocument()
Expand All @@ -961,12 +981,15 @@ public function testGetSubjectsForSerialDocument()
{
$subjects = $this->serialReader->getSubjects();
self::assertNotEmpty($subjects);
self::assertEquals(6, count($subjects));
self::assertEquals(7, count($subjects));
self::assertNotEmpty($subjects[0]->getValue());
//self::assertNotEmpty($subjects[0]->getTopic());
//self::assertNotEmpty($subjects[0]->getGenre());
self::assertNotEmpty($subjects[0]->getCartographics());

// TODO: implement reading of elements
// TODO: implement reading of cartographics
/*self::assertNotEmpty($subjects[0]->getCartographics()[0]->getCoordinates());
self::assertEquals('', $subjects[0]->getCartographics()[0]->getCoordinates()[0]->getValue());
self::assertNotEmpty($subjects[0]->getCartographics()[0]->getScale());
self::assertNotEmpty($subjects[0]->getCartographics()[0]->getProjection());*/
}

public function testGetSubjectsByQueryForSerialDocument()
Expand All @@ -975,10 +998,10 @@ public function testGetSubjectsByQueryForSerialDocument()
self::assertNotEmpty($subjects);
self::assertEquals(1, count($subjects));
self::assertNotEmpty($subjects[0]->getValue());
//self::assertNotEmpty($subjects[0]->getForm());
//self::assertNotEmpty($subjects[0]->getGenre());

// TODO: implement reading of elements
self::assertNotEmpty($subjects[0]->getTopics());
self::assertEquals('Web sites', $subjects[0]->getTopics()[0]->getValue());
self::assertNotEmpty($subjects[0]->getGenres());
self::assertEquals('Directories', $subjects[0]->getGenres()[0]->getValue());
}

public function testGetNoSubjectsByQueryForSerialDocument()
Expand Down
12 changes: 12 additions & 0 deletions tests/resources/mods_book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
<abstract displayLabel="Content description">Test description for document which contains display label.</abstract>
<note type="statement of responsibility">Eric Alterman.</note>
<note type="bibliography">Includes bibliographical references (p. 291-312) and index.</note>
<subject>
<hierarchicalGeographic>
<country level="1">United Kingdom</country>
<country level="2">England</country>
<region>North West</region>
<county>Cumbria</county>
<city>Providence</city>
<citySection citySectionType="neighborhood" level="1">East Side</citySection>
<citySection citySectionType="neighborhood" level="2">Blackstone</citySection>
<area areaType="national park">Lake District</area>
</hierarchicalGeographic>
</subject>
<subject>
<geographicCode authority="marcgac">n-us---</geographicCode>
</subject>
Expand Down
7 changes: 7 additions & 0 deletions tests/resources/mods_serial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
<note>Latest issue consulted: V. 9 no. 1 (spring 2008) (viewed Sept. 5, 2008).</note>
<note type="system details">Mode of access: World Wide Web.</note>
<note>Electronic serial in HTML format.</note>
<subject>
<cartographics>
<coordinates>E 72°--E 148°/N 13°--N 18°</coordinates>
<scale>1:22,000,000</scale>
<projection>Conic proj</projection>
</cartographics>
</subject>
<subject authority="lcsh">
<topic>Academic libraries</topic>
<genre>Periodicals</genre>
Expand Down

0 comments on commit e9a5fcc

Please sign in to comment.