Skip to content

Commit

Permalink
Source elifeAssessmentScietyUri directly from ArticleVoR snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiosironi committed Dec 18, 2024
1 parent cb55f05 commit e184af4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Model/ArticleVoR.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct(
PromiseInterface $authorResponse,
PromiseInterface $elifeAssessmentArticleSection = null,
string $elifeAssessmentTitle = null,
PromiseInterface $elifeAssessmentScietyUri = null,
string $elifeAssessmentScietyUri = null,
PromiseInterface $recommendationsForAuthors = null,
PromiseInterface $recommendationsForAuthorsTitle = null,
Sequence $publicReviews = null,
Expand Down Expand Up @@ -250,7 +250,7 @@ public function getElifeAssessmentTitle()
*/
public function getElifeAssessmentScietyUri()
{
return $this->elifeAssessmentScietyUri->wait();
return $this->elifeAssessmentScietyUri;
}

/**
Expand Down
15 changes: 6 additions & 9 deletions src/Serializer/ArticleVoRNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ protected function denormalizeArticle(

if (empty($data['elifeAssessment'])) {
$elifeAssessmentTitle = null;
$elifeAssessmentScietyUri = null;
} else {
$elifeAssessmentTitle = $data['elifeAssessment']['title'];
$elifeAssessmentScietyUri = $data['elifeAssessment']['scietyUri'] ?? null;
}

if ($article) {
Expand Down Expand Up @@ -172,15 +174,6 @@ protected function denormalizeArticle(
);
});

$elifeAssessmentScietyUri = $data['elifeAssessment']
->then(function (array $elifeAssessment = null) {
if (empty($elifeAssessment)) {
return null;
}

return $elifeAssessment['scietyUri'] ?? null;
});

$elifeAssessmentArticleSection = $data['elifeAssessment']
->then(function (array $elifeAssessment = null) use ($format, $context) {
if (empty($elifeAssessment)) {
Expand Down Expand Up @@ -473,6 +466,10 @@ protected function normalizeArticle(
];
}

if ($article->getElifeAssessmentScietyUri()) {
$data['elifeAssessment']['scietyUri'] = $article->getElifeAssessmentScietyUri();
}

if (empty($context['snippet'])) {
if ($article->getElifeAssessmentArticleSection()) {
$data['elifeAssessment'] = [
Expand Down
4 changes: 2 additions & 2 deletions test/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private function defaultTestData()
'elifeAssessment' => null,
'elifeAssessmentArticleSection' => promise_for(new ArticleSection(new ArraySequence([new Paragraph('eLife Assessment')]))),
'elifeAssessmentTitle' => 'eLife assessment',
'elifeAssessmentScietyUri' => promise_for('https://elife-assessment.com'),
'elifeAssessmentScietyUri' => 'https://elife-assessment.com',
'recommendationsForAuthors' => promise_for(new ArticleSection(new ArraySequence([new Paragraph('Recommendations For Authors')]))),
'recommendationsForAuthorsTitle' => promise_for('Recommendations for authors'),
'publicReviews' => new ArraySequence([new PublicReview('Public review 1', new ArraySequence([new Paragraph('Public review 1 content')]))]),
Expand Down Expand Up @@ -617,7 +617,7 @@ private function sampleRecipes()
->withAuthorResponse(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 author response text')]), '10.7554/eLife.09560authorResponse', 'author-response-id')))
->withElifeAssessmentArticleSection(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 elife assessment text')]), '10.7554/eLife.09560elifeAssessment', 'elife-assessment-id')))
->withElifeAssessmentTitle(null)
->withElifeAssessmentScietyUri(promise_for('https://elife-assessment-09560.com'))
->withElifeAssessmentScietyUri(null)
->withRecommendationsForAuthors(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 recommendations for authors text')]), '10.7554/eLife.09560recommendationsForAuthors', 'recommendations-for-authors-id')))
->withRecommendationsForAuthorsTitle(promise_for('Recommendations for authors'))
->withPublicReviews(new ArraySequence([new PublicReview('Public review 1', new ArraySequence([new Paragraph('Public review 1 content')]))]));
Expand Down
4 changes: 2 additions & 2 deletions test/Model/ArticleVoRTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ public function it_may_have_an_elife_assessment_title()
public function it_may_have_an_elife_assessment_uri()
{
$with = $this->builder
->withPromiseOfElifeAssessmentScietyUri($elifeAssessmentScietyUri = 'https://elife-assessment.com')
->withElifeAssessmentScietyUri($elifeAssessmentScietyUri = 'https://elife-assessment.com')
->__invoke();
$withOut = $this->builder
->withPromiseOfElifeAssessmentScietyUri(null)
->withElifeAssessmentScietyUri(null)
->__invoke();

$this->assertEquals($elifeAssessmentScietyUri, $with->getElifeAssessmentScietyUri());
Expand Down
10 changes: 5 additions & 5 deletions test/Serializer/ArticleVoRNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ function ($test) {
->withPromiseOfAuthorResponse(null)
->withPromiseOfElifeAssessmentArticleSection(null)
->withElifeAssessmentTitle(null)
->withPromiseOfElifeAssessmentScietyUri(null)
->withElifeAssessmentScietyUri(null)
->withPromiseOfRecommendationsForAuthors(null)
->withPromiseOfRecommendationsForAuthorsTitle(null)
->withDoiVersion(null)
Expand Down Expand Up @@ -587,7 +587,7 @@ function ($test) {
// ->withElifeAssessment(new ElifeAssessment(['landmark'], ['solid']))
->withElifeAssessmentArticleSection(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 elife assessment text')]), '10.7554/eLife.09560elifeAssessment', 'elife-assessment-id')))
->withElifeAssessmentTitle('eLife assessment')
->withElifeAssessmentScietyUri(promise_for('https://elife-assessment-09560.com'))
->withElifeAssessmentScietyUri('https://elife-assessment-09560.com')
->withRecommendationsForAuthors(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 recommendations for authors text')]), '10.7554/eLife.09560recommendationsForAuthors', 'recommendations-for-authors-id')))
->withRecommendationsForAuthorsTitle(promise_for('Recommendations for authors'))
->withPublicReviews(new ArraySequence([new PublicReview('Public review 1', new ArraySequence([new Paragraph('Public review 1 content')]))]))
Expand Down Expand Up @@ -656,14 +656,14 @@ function ($test) {
'figuresPdf' => 'http://www.example.com/figures',
'impactStatement' => 'A new hominin species has been unearthed in the Dinaledi Chamber of the Rising Star cave system in the largest assemblage of a single species of hominins yet discovered in Africa.',
'elifeAssessment' => [
'title' => 'eLife assessment',
'title' => 'eLife assessment',
'scietyUri' => 'https://elife-assessment-09560.com',
// 'content' => [
// [
// 'type' => 'paragraph',
// 'text' => 'Article 09560 elife assessment text',
// ],
// ],
// 'scietyUri' => 'https://elife-assessment-09560.com',
// 'doi' => '10.7554/eLife.09560elifeAssessment',
// 'id' => 'elife-assessment-id',
// 'significance' => ['landmark'],
Expand Down Expand Up @@ -708,7 +708,7 @@ function (ApiTestCase $test) {
->withPromiseOfAuthorResponse(null)
->withPromiseOfElifeAssessmentArticleSection(null)
->withElifeAssessmentTitle(null)
->withPromiseOfElifeAssessmentScietyUri(null)
->withElifeAssessmentScietyUri(null)
->withPromiseOfRecommendationsForAuthors(null)
->withPromiseOfRecommendationsForAuthorsTitle(null)
->withDoiVersion(null)
Expand Down

0 comments on commit e184af4

Please sign in to comment.