diff --git a/src/Mods/Element/Common/BaseElement.php b/src/Mods/Element/Common/BaseElement.php index 54e2378..ece9ec7 100644 --- a/src/Mods/Element/Common/BaseElement.php +++ b/src/Mods/Element/Common/BaseElement.php @@ -41,7 +41,7 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the text value of element + * Get the text value of element. * * @access public * @@ -53,7 +53,13 @@ public function getValue(): string } /** - * Get the string value of attribute + * Get the string value of attribute. + * + * @access public + * + * @param string $attribute name + * + * @return string */ protected function getStringAttribute($attribute): string { @@ -66,4 +72,25 @@ protected function getStringAttribute($attribute): string } return ''; } + + /** + * Get the int value of attribute. + * + * @access public + * + * @param string $attribute name + * + * @return int + */ + protected function getIntAttribute($attribute): int + { + if ($this->xml->attributes() != null) { + $value = $this->xml->attributes()->$attribute; + + if (!empty($value)) { + return (int) $value; + } + } + return 0; + } } \ No newline at end of file diff --git a/src/Mods/Element/Part.php b/src/Mods/Element/Part.php index 7cc328c..65d4382 100644 --- a/src/Mods/Element/Part.php +++ b/src/Mods/Element/Part.php @@ -90,12 +90,7 @@ public function getType(): string */ public function getOrder(): int { - $value = $this->xml->attributes()->order; - - if (!empty($value)) { - return (int) $value; - } - return 0; + return $this->getIntAttribute('order'); } /** diff --git a/src/Mods/Element/Specific/Part/Detail.php b/src/Mods/Element/Specific/Part/Detail.php index ed45f99..60dc489 100644 --- a/src/Mods/Element/Specific/Part/Detail.php +++ b/src/Mods/Element/Specific/Part/Detail.php @@ -76,12 +76,7 @@ public function getType(): string */ public function getLevel(): int { - $value = $this->xml->attributes()->level; - - if (!empty($value)) { - return (int) $value; - } - return 0; + return $this->getIntAttribute('level'); } /** diff --git a/src/Mods/Element/Specific/Subject/HierarchicalGeographic.php b/src/Mods/Element/Specific/Subject/HierarchicalGeographic.php index 4ad421e..3e77528 100644 --- a/src/Mods/Element/Specific/Subject/HierarchicalGeographic.php +++ b/src/Mods/Element/Specific/Subject/HierarchicalGeographic.php @@ -14,11 +14,13 @@ use Slub\Mods\Attribute\Common\AuthorityAttribute; use Slub\Mods\Element\Common\BaseElement; -use Slub\Mods\Element\Specific\Subject\HierarchicalGeographic\Element; +use Slub\Mods\Element\Specific\Subject\HierarchicalGeographic\LevelPeriodElement; use Slub\Mods\Element\Specific\Subject\HierarchicalGeographic\TypeElement; +use Slub\Mods\Element\Xml\Element; /** * HierarchicalGeographic MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#hierarchicalgeographic * * @access public */ @@ -26,72 +28,6 @@ class HierarchicalGeographic extends BaseElement { use AuthorityAttribute; - /** - * @access private - * @var Element - */ - private Element $continent; - - /** - * @access private - * @var Element - */ - private Element $country; - - /** - * @access private - * @var TypeElement - */ - private TypeElement $region; - - /** - * @access private - * @var TypeElement - */ - private TypeElement $state; - - /** - * @access private - * @var Element - */ - private Element $territory; - - /** - * @access private - * @var Element - */ - private Element $county; - - /** - * @access private - * @var Element - */ - private Element $city; - - /** - * @access private - * @var TypeElement - */ - private TypeElement $citySection; - - /** - * @access private - * @var Element - */ - private Element $island; - - /** - * @access private - * @var TypeElement - */ - private TypeElement $area; - - /** - * @access private - * @var Element - */ - private Element $extraterrestrialArea; - /** * This extracts the essential MODS metadata from XML * @@ -107,134 +43,255 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the value of continent + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#continent * * @access public * - * @return Element + * @param string $query The XPath query for metadata search + * + * @return LevelPeriodElement[] */ - public function getContinent(): Element + public function getContinents(string $query = ''): array { - return $this->continent; + $continents = []; + $xpath = './mods:continent' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $continents[] = new LevelPeriodElement($value); + } + } + return $continents; } /** - * Get the value of country + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#country * * @access public * - * @return Element + * @param string $query The XPath query for metadata search + * + * @return LevelPeriodElement[] */ - public function getCountry(): Element + public function getCountries(string $query = ''): array { - return $this->country; + $countries = []; + $xpath = './mods:country' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $countries[] = new LevelPeriodElement($value); + } + } + return $countries; } /** - * Get the value of region + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#region * * @access public * - * @return TypeElement + * @param string $query The XPath query for metadata search + * + * @return TypeElement[] */ - public function getRegion(): TypeElement + public function getRegions(string $query = ''): array { - return $this->region; + $regions = []; + $xpath = './mods:region' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $regions[] = new TypeElement($value, 'regionType'); + } + } + return $regions; } /** - * Get the value of state + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#state * * @access public * - * @return TypeElement + * @param string $query The XPath query for metadata search + * + * @return TypeElement[] */ - public function getState(): TypeElement + public function getStates(string $query = ''): array { - return $this->state; + $states = []; + $xpath = './mods:state' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $states[] = new TypeElement($value, 'stateType'); + } + } + return $states; } /** - * Get the value of territory + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#territory * * @access public * - * @return Element + * @param string $query The XPath query for metadata search + * + * @return LevelPeriodElement[] */ - public function getTerritory(): Element + public function getTerritories(string $query = ''): array { - return $this->territory; + $territories = []; + $xpath = './mods:territory' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $territories[] = new LevelPeriodElement($value); + } + } + return $territories; } /** - * Get the value of county + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#county * * @access public * - * @return Element + * @param string $query The XPath query for metadata search + * + * @return LevelPeriodElement[] */ - public function getCounty(): Element + public function getCounties(string $query = ''): array { - return $this->county; + $counties = []; + $xpath = './mods:county' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $counties[] = new LevelPeriodElement($value); + } + } + return $counties; } /** - * Get the value of city + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#city * * @access public * - * @return Element + * @param string $query The XPath query for metadata search + * + * @return LevelPeriodElement[] */ - public function getCity(): Element + public function getCities(string $query = ''): array { - return $this->city; + $cities = []; + $xpath = './mods:city' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $cities[] = new LevelPeriodElement($value); + } + } + return $cities; } /** - * Get the value of citySection + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#citysection * * @access public * - * @return TypeElement + * @param string $query The XPath query for metadata search + * + * @return TypeElement[] */ - public function getCitySection(): TypeElement + public function getCitySections(string $query = ''): array { - return $this->citySection; + $sections = []; + $xpath = './mods:citySection' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $sections[] = new TypeElement($value, 'citySectionType'); + } + } + return $sections; } /** - * Get the value of island + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#island * * @access public * - * @return Element + * @param string $query The XPath query for metadata search + * + * @return LevelPeriodElement[] */ - public function getIsland(): Element + public function getIslands(string $query = ''): array { - return $this->island; + $islands = []; + $xpath = './mods:island' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $islands[] = new LevelPeriodElement($value); + } + } + return $islands; } /** - * Get the value of area + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#area * * @access public * - * @return TypeElement + * @param string $query The XPath query for metadata search + * + * @return TypeElement[] */ - public function getArea(): TypeElement + public function getAreas(string $query = ''): array { - return $this->area; + $areas = []; + $xpath = './mods:area' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $areas[] = new TypeElement($value, 'areaType'); + } + } + return $areas; } /** - * Get the value of extraterrestrialArea + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#extraterrestrialarea * * @access public * - * @return Element + * @param string $query The XPath query for metadata search + * + * @return LevelPeriodElement[] */ - public function getExtraterrestrialArea(): Element + public function getExtraterrestrialAreas(string $query = ''): array { - return $this->extraterrestrialArea; + $extraterrestrialAreas = []; + $xpath = './mods:extraterrestrialArea' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $extraterrestrialAreas[] = new LevelPeriodElement($value); + } + } + return $extraterrestrialAreas; } } diff --git a/src/Mods/Element/Specific/Subject/HierarchicalGeographic/Element.php b/src/Mods/Element/Specific/Subject/HierarchicalGeographic/LevelPeriodElement.php similarity index 76% rename from src/Mods/Element/Specific/Subject/HierarchicalGeographic/Element.php rename to src/Mods/Element/Specific/Subject/HierarchicalGeographic/LevelPeriodElement.php index ace2cda..25fed16 100644 --- a/src/Mods/Element/Specific/Subject/HierarchicalGeographic/Element.php +++ b/src/Mods/Element/Specific/Subject/HierarchicalGeographic/LevelPeriodElement.php @@ -21,7 +21,7 @@ * * @access public */ -class Element extends BaseElement +class LevelPeriodElement extends BaseElement { use AuthorityAttribute, LanguageAttribute; @@ -40,19 +40,21 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the value of level + * Get the value of the 'level' attribute. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#level * * @access public * - * @return string + * @return int */ - public function getLevel(): string + public function getLevel(): int { - return $this->getStringAttribute('level'); + return $this->getIntAttribute('level'); } /** - * Get the value of period + * Get the value of the 'period' attribute. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#period * * @access public * diff --git a/src/Mods/Element/Specific/Subject/HierarchicalGeographic/TypeElement.php b/src/Mods/Element/Specific/Subject/HierarchicalGeographic/TypeElement.php index 89189c5..81cfdb9 100644 --- a/src/Mods/Element/Specific/Subject/HierarchicalGeographic/TypeElement.php +++ b/src/Mods/Element/Specific/Subject/HierarchicalGeographic/TypeElement.php @@ -17,9 +17,15 @@ * * @access public */ -class TypeElement extends Element +class TypeElement extends LevelPeriodElement { + /** + * @access private + * @var string + */ + private string $attribute; + /** * This extracts the essential MODS metadata from XML * @@ -29,13 +35,14 @@ class TypeElement extends Element * * @return void */ - public function __construct(\SimpleXMLElement $xml) + public function __construct(\SimpleXMLElement $xml, string $attribute) { + $this->attribute = $attribute; parent::__construct($xml); } /** - * Get the value of type + * Get the value of the 'xyzType' attribute. * * @access public * @@ -43,6 +50,6 @@ public function __construct(\SimpleXMLElement $xml) */ public function getType(): string { - return $this->getStringAttribute('type'); + return $this->getStringAttribute($this->attribute); } } diff --git a/src/Mods/Element/Subject.php b/src/Mods/Element/Subject.php index 5b79e23..75f1eb1 100644 --- a/src/Mods/Element/Subject.php +++ b/src/Mods/Element/Subject.php @@ -25,9 +25,11 @@ use Slub\Mods\Element\Name; use Slub\Mods\Element\Specific\OriginInfo\Place\Cartographics; use Slub\Mods\Element\Specific\Subject\HierarchicalGeographic; +use Slub\Mods\Element\Xml\Element; /** * Subject MODS metadata element class for the 'php-mods-reader' library. + * @see https://www.loc.gov/standards/mods/userguide/subject.html * * @access public */ @@ -35,66 +37,6 @@ class Subject extends BaseElement { use AuthorityAttribute, LanguageAttribute, IdAttribute, XlinkHrefAttribute, AltRepGroupAttribute, DisplayLabelAttribute, UsageAttribute; - /** - * @access private - * @var AuthorityLanguageElement - */ - private AuthorityLanguageElement $topic; - - /** - * @access private - * @var AuthorityLanguageElement - */ - private AuthorityLanguageElement $geographic; - - /** - * @access private - * @var AuthorityDateLanguageElement - */ - private AuthorityDateLanguageElement $temporal; - - /** - * @access private - * @var TitleInfo - */ - private TitleInfo $titleInfo; - - /** - * @access private - * @var Name - */ - private Name $name; - - /** - * @access private - * @var Genre - */ - private Genre $genre; - - /** - * @access private - * @var HierarchicalGeographic - */ - private HierarchicalGeographic $hierarchicalGeographic; - - /** - * @access private - * @var Cartographics - */ - private Cartographics $cartographics; - - /** - * @access private - * @var AuthorityLanguageElement - */ - private AuthorityLanguageElement $geographicCode; - - /** - * @access private - * @var AuthorityLanguageElement - */ - private AuthorityLanguageElement $occupation; - /** * This extracts the essential MODS metadata from XML * @@ -107,136 +49,235 @@ class Subject extends BaseElement public function __construct(\SimpleXMLElement $xml) { parent::__construct($xml); - - $this->topic = new AuthorityLanguageElement($xml); - $this->geographic = new AuthorityLanguageElement($xml); - $this->temporal = new AuthorityDateLanguageElement($xml); - $this->titleInfo = new TitleInfo($xml); - $this->name = new Name($xml); - $this->genre = new Genre($xml); - $this->hierarchicalGeographic = new HierarchicalGeographic($xml); - $this->cartographics = new Cartographics($xml); - $this->geographicCode = new AuthorityLanguageElement($xml); - $this->occupation = new AuthorityLanguageElement($xml); } /** - * Get the value of topic + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#topic * * @access public * - * @return AuthorityLanguageElement + * @param string $query The XPath query for metadata search + * + * @return AuthorityLanguageElement[] */ - public function getTopic(): AuthorityLanguageElement + public function getTopics(string $query = ''): array { - return $this->topic; + $topics = []; + $xpath = './mods:topic' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $topics[] = new AuthorityLanguageElement($value); + } + } + return $topics; } /** - * Get the value of geographic + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#geographic * * @access public * - * @return AuthorityLanguageElement + * @param string $query The XPath query for metadata search + * + * @return AuthorityLanguageElement[] */ - public function getGeographic(): AuthorityLanguageElement + public function getGeographics(string $query = ''): array { - return $this->geographic; + $geographics = []; + $xpath = './mods:geographic' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $geographics[] = new AuthorityLanguageElement($value); + } + } + return $geographics; } /** - * Get the value of temporal + * Get the value of the element. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#temporal * * @access public * - * @return AuthorityDateLanguageElement + * @param string $query The XPath query for metadata search + * + * @return AuthorityDateLanguageElement[] */ - public function getTemporal(): AuthorityDateLanguageElement + public function getTemporals(string $query = ''): array { - return $this->temporal; + $temporals = []; + $xpath = './mods:temporal' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $temporals[] = new AuthorityLanguageElement($value); + } + } + return $temporals; } /** - * Get the value of titleInfo + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#titleinfo * * @access public * - * @return TitleInfo + * @param string $query The XPath query for metadata search + * + * @return TitleInfo[] */ - public function getTitleInfo(): TitleInfo + public function getTitleInfos(string $query = ''): array { - return $this->titleInfo; + $titleInfos = []; + $xpath = './mods:titleInfo' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $titleInfos[] = new TitleInfo($value); + } + } + return $titleInfos; } /** - * Get the value of name + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#name * * @access public * - * @return Name + * @param string $query The XPath query for metadata search + * + * @return Name[] */ - public function getName(): Name + public function getNames(string $query = ''): array { - return $this->name; + $names = []; + $xpath = './mods:name' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $names[] = new Name($value); + } + } + return $names; } /** - * Get the value of genre + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#genre * * @access public * - * @return Genre + * @param string $query The XPath query for metadata search + * + * @return Genre[] */ - public function getGenre(): Genre + public function getGenres(string $query = ''): array { - return $this->genre; + $genres = []; + $xpath = './mods:genre' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $genres[] = new Genre($value); + } + } + return $genres; } /** - * Get the value of hierarchicalGeographic + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#hierarchicalgeographic * * @access public * - * @return HierarchicalGeographic + * @param string $query The XPath query for metadata search + * + * @return HierarchicalGeographic[] */ - public function getHierarchicalGeographic(): HierarchicalGeographic + public function getHierarchicalGeographics(string $query = ''): array { - return $this->hierarchicalGeographic; + $hierarchicalGeographics = []; + $xpath = './mods:hierarchicalGeographic' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $hierarchicalGeographics[] = new HierarchicalGeographic($value); + } + } + return $hierarchicalGeographics; } /** - * Get the value of cartographics + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#hierarchicalgeographic * * @access public * - * @return Cartographics + * @param string $query The XPath query for metadata search + * + * @return Cartographics[] */ - public function getCartographics(): Cartographics + public function getCartographics(string $query = ''): array { - return $this->cartographics; + $cartographics = []; + $xpath = './mods:cartographics' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $cartographics[] = new Cartographics($value); + } + } + return $cartographics; } /** - * Get the value of geographicCode + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#geographiccode * * @access public * - * @return AuthorityLanguageElement + * @param string $query The XPath query for metadata search + * + * @return AuthorityLanguageElement[] */ - public function getGeographicCode(): AuthorityLanguageElement + public function getGeographicCodes(string $query = ''): array { - return $this->geographicCode; + $geographicCodes = []; + $xpath = './mods:geographicCode' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $geographicCodes[] = new AuthorityLanguageElement($value); + } + } + return $geographicCodes; } /** - * Get the value of occupation + * Get the the array of the elements. + * @see https://www.loc.gov/standards/mods/userguide/subject.html#occupation * * @access public * - * @return AuthorityLanguageElement + * @param string $query The XPath query for metadata search + * + * @return AuthorityLanguageElement[] */ - public function getOccupation(): AuthorityLanguageElement + public function getOccupations(string $query = ''): array { - return $this->occupation; + $occupations = []; + $xpath = './mods:occupation' . $query; + $element = new Element($this->xml, $xpath); + if ($element->exists()) { + foreach ($element->getValues() as $value) { + $occupations[] = new AuthorityLanguageElement($value); + } + } + return $occupations; } } diff --git a/tests/Mods/ModsReaderTest.php b/tests/Mods/ModsReaderTest.php index 346f066..a7ba56c 100644 --- a/tests/Mods/ModsReaderTest.php +++ b/tests/Mods/ModsReaderTest.php @@ -931,12 +931,28 @@ 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() @@ -944,11 +960,15 @@ 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() @@ -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() @@ -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() diff --git a/tests/resources/mods_book.xml b/tests/resources/mods_book.xml index a656b47..c09a09a 100644 --- a/tests/resources/mods_book.xml +++ b/tests/resources/mods_book.xml @@ -78,6 +78,18 @@ Test description for document which contains display label. Eric Alterman. Includes bibliographical references (p. 291-312) and index. + + + United Kingdom + England + North West + Cumbria + Providence + East Side + Blackstone + Lake District + + n-us--- diff --git a/tests/resources/mods_serial.xml b/tests/resources/mods_serial.xml index 60ee312..e608c84 100644 --- a/tests/resources/mods_serial.xml +++ b/tests/resources/mods_serial.xml @@ -51,6 +51,13 @@ Latest issue consulted: V. 9 no. 1 (spring 2008) (viewed Sept. 5, 2008). Mode of access: World Wide Web. Electronic serial in HTML format. + + + E 72°--E 148°/N 13°--N 18° + 1:22,000,000 + Conic proj + + Academic libraries Periodicals