Skip to content

Commit

Permalink
Merge pull request #38 from slub/33-one-part-names
Browse files Browse the repository at this point in the history
Test one part authors
  • Loading branch information
dikastes authored Nov 28, 2024
2 parents 2558121 + 16242a8 commit cd8f048
Show file tree
Hide file tree
Showing 2 changed files with 37 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
24 changes: 24 additions & 0 deletions Tests/Unit/Processing/BibEntryProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class BibEntryProcessorTest extends UnitTestCase
private ?BibEntryProcessor $subject = null;
private array $exampleBookArray = [];
private array $exampleBookWithoutAuthorArray = [];
private array $exampleBookWithAnonymousAuthorArray = [];
private array $exampleBookSectionArray = [];
private array $exampleArticleArray = [];

Expand All @@ -37,6 +38,7 @@ final class BibEntryProcessorTest extends UnitTestCase

private string $exampleBook = '';
private string $exampleBookWithoutAuthor = '';
private string $exampleBookWithAnonymousAuthor = '';
private string $exampleArticle = '';
private string $exampleBookSection = '';

Expand Down Expand Up @@ -80,6 +82,24 @@ protected function setUp(): void
}
JSON;

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

$this->exampleArticle =
<<<JSON
{
Expand Down Expand Up @@ -129,6 +149,7 @@ protected function setUp(): void
$this->subject = GeneralUtility::makeInstance(BibEntryProcessor::class);
$this->exampleBookArray = json_decode($this->exampleBook, true);
$this->exampleBookWithoutAuthorArray = json_decode($this->exampleBookWithoutAuthor, true);
$this->exampleBookWithAnonymousAuthorArray = json_decode($this->exampleBookWithAnonymousAuthor, true);
$this->exampleArticleArray = json_decode($this->exampleArticle, true);
$this->exampleBookSectionArray = json_decode($this->exampleBookSection, true);
}
Expand All @@ -147,14 +168,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->exampleBookWithAnonymousAuthorArray, new Collection(), new Collection());

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

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 cd8f048

Please sign in to comment.