Skip to content

Commit

Permalink
Test one part authors
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Richter committed Nov 27, 2024
1 parent f1e7bc5 commit 9eed946
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Classes/Processing/BibEntryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
use Illuminate\Support\Stringable;
use Illuminate\Support\Str;
use Slub\LisztCommon\Common\Collection;
use Slub\LisztCommon\Processing\IndexProcessor;

class BibEntryProcessor
class BibEntryProcessor extends IndexProcessor
{

public static function process(
Expand All @@ -32,28 +33,28 @@ public static function process(
$bibliographyItem['localizedCitations'][$locale] = $localizedCitation->get($key)['citation'];
}
$bibliographyItem['tei'] = $teiDataSets->get($key);
$bibliographyItem['tx_lisztcommon_header'] = self::buildListingField($bibliographyItem, BibEntryConfig::getAuthorHeader());
if ($bibliographyItem['tx_lisztcommon_header'] == '') {
$bibliographyItem['tx_lisztcommon_header'] = self::buildListingField($bibliographyItem, BibEntryConfig::getEditorHeader());
$bibliographyItem[self::HEADER_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::getAuthorHeader());
if ($bibliographyItem[self::HEADER_FIELD] == '') {
$bibliographyItem[self::HEADER_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::getEditorHeader());
}
$bibliographyItem['tx_lisztcommon_body'] = self::buildListingField($bibliographyItem, BibEntryConfig::getBody());
switch($bibliographyItem['itemType']) {
$bibliographyItem[self::BODY_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::getBody());
switch($bibliographyItem[self::TYPE_FIELD]) {
case 'book':
$bibliographyItem['tx_lisztcommon_footer'] = self::buildListingField($bibliographyItem, BibEntryConfig::getBookFooter());
$bibliographyItem[self::FOOTER_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::getBookFooter());
break;
case 'bookSection':
$bibliographyItem['tx_lisztcommon_footer'] = self::buildListingField($bibliographyItem, BibEntryConfig::getBookSectionFooter());
$bibliographyItem[self::FOOTER_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::getBookSectionFooter());
break;
case 'journalArticle':
$bibliographyItem['tx_lisztcommon_footer'] = self::buildListingField($bibliographyItem, BibEntryConfig::getArticleFooter());
$bibliographyItem[self::FOOTER_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::getArticleFooter());
break;
case 'thesis':
$bibliographyItem['tx_lisztcommon_footer'] = self::buildListingField($bibliographyItem, BibEntryConfig::getThesisFooter());
$bibliographyItem[self::FOOTER_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::getThesisFooter());
break;
}

$bibliographyItem['tx_lisztcommon_searchable'] = self::buildListingField($bibliographyItem, BibEntryConfig::SEARCHABLE_FIELDS);
$bibliographyItem['tx_lisztcommon_boosted'] = self::buildListingField($bibliographyItem, BibEntryConfig::BOOSTED_FIELDS);
$bibliographyItem[self::SEARCHABLE_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::SEARCHABLE_FIELDS);
$bibliographyItem[self::BOOSTED_FIELD] = self::buildListingField($bibliographyItem, BibEntryConfig::BOOSTED_FIELDS);

return $bibliographyItem;
}
Expand Down
21 changes: 21 additions & 0 deletions Tests/Unit/Processing/BibEntryProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ protected function setUp(): void
}
JSON;

$this->exampleBookWithAnonymousAuthor =
<<<JSON
{
"key": "key",
"itemType": "book",
"title": "$this->title",
"creators": [
{
"creatorType": "editor",
"firstName": "",
"lastName": "$this->editorLastName"
}
],
"place": "$this->place",
"date": "$this->date"
}
JSON;

$this->exampleArticle =
<<<JSON
{
Expand Down Expand Up @@ -147,14 +165,17 @@ public function headerIsProcessedCorrectly(): void
$bookSection = $this->subject->process($this->exampleBookSectionArray, new Collection(), new Collection());
$article = $this->subject->process($this->exampleArticleArray, new Collection(), new Collection());
$bookWithoutAuthor = $this->subject->process($this->exampleBookWithoutAuthorArray, new Collection(), new Collection());
$bookWithAnonymousAuthor = $this->subject->process($this->exampleBookWithoutAuthorArray, new Collection(), new Collection());

$expected = Str::of($this->authorFirstName . ' ' . $this->authorLastName);
$expectedWithoutAuthor = Str::of($this->editorFirstName . ' ' . $this->editorLastName . ' (Hg.)');
$expectedWithAnonymousAuthor = Str::of($this->authorLastName . ' (Hg.)');

self::assertEquals($book['tx_lisztcommon_header'], $expected);
self::assertEquals($bookSection['tx_lisztcommon_header'], $expected);
self::assertEquals($article['tx_lisztcommon_header'], $expected);
self::assertEquals($bookWithoutAuthor['tx_lisztcommon_header'], $expectedWithoutAuthor);
self::assertEquals($bookWithAnonymousAuthor['tx_lisztcommon_header'], $expectedWithAnonymousAuthor);
}

/**
Expand Down

0 comments on commit 9eed946

Please sign in to comment.