Skip to content

Commit

Permalink
Implement test for reading language element
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Apr 5, 2024
1 parent 09e7d98 commit d115ff6
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 23 deletions.
99 changes: 77 additions & 22 deletions tests/Mods/ModsReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,28 +379,83 @@ public function testGetNoIdentifiersByQueryForSerialDocument()
self::assertEmpty($identifiers);
}

public function testGetLanguageForBookDocument()
{
$language = $this->bookReader->getLanguage();
self::assertNotNull($language);
// TODO: implement reading of languageTerm and scriptTerm
// self::assertNotEmpty($language->getLanguageTerm());
// self::assertNotEmpty($language->getScriptTerm());

$language = $this->bookReader->getLanguage('[@type="text"]');
self::assertNull($language);
}

public function testGetLanguageForSerialDocument()
{
$language = $this->serialReader->getLanguage();
self::assertNotNull($language);
// TODO: implement reading of languageTerm and scriptTerm
// self::assertNotEmpty($language->getLanguageTerm());
// self::assertNotEmpty($language->getScriptTerm());

$language = $this->serialReader->getLanguage('[@type="text"]');
self::assertNull($language);
public function testGetLanguagesForBookDocument()
{
$languages = $this->bookReader->getLanguages();
self::assertNotEmpty($languages);
self::assertEquals(2, count($languages));
self::assertEmpty($languages[0]->getObjectPart());
self::assertNotEmpty($languages[0]->getValue());
self::assertNotEmpty($languages[0]->getLanguageTerms());
self::assertNotEmpty($languages[0]->getLanguageTerms()[0]->getValue());
self::assertEquals('code', $languages[0]->getLanguageTerms()[0]->getType());
self::assertEquals('iso639-2b', $languages[0]->getLanguageTerms()[0]->getAuthority());
self::assertEquals('eng', $languages[0]->getLanguageTerms()[0]->getValue());
self::assertNotEmpty($languages[0]->getScriptTerms());
self::assertEquals('code', $languages[0]->getScriptTerms()[0]->getType());
self::assertEquals('iso15924', $languages[0]->getScriptTerms()[0]->getAuthority());
self::assertEquals('Latn', $languages[0]->getScriptTerms()[0]->getValue());
}

public function testGetLanguagesByQueryForBookDocument()
{
$languages = $this->bookReader->getLanguages('[@objectPart="summary"]');
self::assertNotEmpty($languages);
self::assertEquals(1, count($languages));
self::assertNotEmpty($languages[0]->getObjectPart());
self::assertEquals('summary', $languages[0]->getObjectPart());
self::assertNotEmpty($languages[0]->getValue());
self::assertNotEmpty($languages[0]->getLanguageTerms());
self::assertNotEmpty($languages[0]->getLanguageTerms()[0]->getValue());
self::assertEquals('code', $languages[0]->getLanguageTerms()[0]->getType());
self::assertEquals('iso639-2b', $languages[0]->getLanguageTerms()[0]->getAuthority());
self::assertEquals('spa', $languages[0]->getLanguageTerms()[0]->getValue());
self::assertNotEmpty($languages[0]->getScriptTerms());
self::assertEquals('code', $languages[0]->getScriptTerms()[0]->getType());
self::assertEquals('iso15924', $languages[0]->getScriptTerms()[0]->getAuthority());
self::assertEquals('Latn', $languages[0]->getScriptTerms()[0]->getValue());
}

public function testGetNoLanguagesByQueryForBookDocument()
{
$languages = $this->bookReader->getLanguages('[@objectPart="abstract"]');
self::assertEmpty($languages);
}

public function testGetLanguagesForSerialDocument()
{
$languages = $this->serialReader->getLanguages();
self::assertNotEmpty($languages);
self::assertEquals(1, count($languages));
self::assertEmpty($languages[0]->getObjectPart());
self::assertNotEmpty($languages[0]->getValue());
self::assertNotEmpty($languages[0]->getLanguageTerms());
self::assertNotEmpty($languages[0]->getLanguageTerms()[0]->getValue());
self::assertEquals('code', $languages[0]->getLanguageTerms()[0]->getType());
self::assertEquals('iso639-2b', $languages[0]->getLanguageTerms()[0]->getAuthority());
self::assertEquals('eng', $languages[0]->getLanguageTerms()[0]->getValue());
self::assertEmpty($languages[0]->getScriptTerms());
}

public function testGetLanguagesByQueryForSerialDocument()
{
$languages = $this->serialReader->getLanguages('[./mods:languageTerm[@type="code"]]');
self::assertNotEmpty($languages);
self::assertEquals(1, count($languages));
self::assertEmpty($languages[0]->getObjectPart());
self::assertNotEmpty($languages[0]->getValue());
self::assertNotEmpty($languages[0]->getLanguageTerms());
self::assertNotEmpty($languages[0]->getLanguageTerms()[0]->getValue());
self::assertEquals('code', $languages[0]->getLanguageTerms()[0]->getType());
self::assertEquals('iso639-2b', $languages[0]->getLanguageTerms()[0]->getAuthority());
self::assertEquals('eng', $languages[0]->getLanguageTerms()[0]->getValue());
self::assertEmpty($languages[0]->getScriptTerms());
}

public function testGetNoLanguagesByQueryForSerialDocument()
{
$languages = $this->serialReader->getLanguages('[@objectPart="summary"]');
self::assertEmpty($languages);
}

public function testGetLocationsForBookDocument()
Expand Down
7 changes: 6 additions & 1 deletion tests/resources/mods_book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@
<dateIssued>c1999</dateIssued>
</originInfo>
<language>
<languageTerm authority="iso639-2b" type="code">eng</languageTerm>
<languageTerm type="code" authority="iso639-2b">eng</languageTerm>
<scriptTerm type="code" authority="iso15924">Latn</scriptTerm>
</language>
<language objectPart="summary">
<languageTerm type="code" authority="iso639-2b">spa</languageTerm>
<scriptTerm type="code" authority="iso15924">Latn</scriptTerm>
</language>
<physicalDescription>
<form authority="marcform">print</form>
Expand Down

0 comments on commit d115ff6

Please sign in to comment.