From e184af4c0603233a226721c955e22e7e1a48d15c Mon Sep 17 00:00:00 2001 From: Giorgio Sironi Date: Wed, 18 Dec 2024 15:45:15 +0000 Subject: [PATCH] Source elifeAssessmentScietyUri directly from ArticleVoR snippets https://github.com/elifesciences/issues/issues/9034 --- src/Model/ArticleVoR.php | 4 ++-- src/Serializer/ArticleVoRNormalizer.php | 15 ++++++--------- test/Builder.php | 4 ++-- test/Model/ArticleVoRTest.php | 4 ++-- test/Serializer/ArticleVoRNormalizerTest.php | 10 +++++----- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/Model/ArticleVoR.php b/src/Model/ArticleVoR.php index e0d0bfbf..d208088a 100644 --- a/src/Model/ArticleVoR.php +++ b/src/Model/ArticleVoR.php @@ -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, @@ -250,7 +250,7 @@ public function getElifeAssessmentTitle() */ public function getElifeAssessmentScietyUri() { - return $this->elifeAssessmentScietyUri->wait(); + return $this->elifeAssessmentScietyUri; } /** diff --git a/src/Serializer/ArticleVoRNormalizer.php b/src/Serializer/ArticleVoRNormalizer.php index 5d650a7b..98cee78b 100644 --- a/src/Serializer/ArticleVoRNormalizer.php +++ b/src/Serializer/ArticleVoRNormalizer.php @@ -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) { @@ -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)) { @@ -473,6 +466,10 @@ protected function normalizeArticle( ]; } + if ($article->getElifeAssessmentScietyUri()) { + $data['elifeAssessment']['scietyUri'] = $article->getElifeAssessmentScietyUri(); + } + if (empty($context['snippet'])) { if ($article->getElifeAssessmentArticleSection()) { $data['elifeAssessment'] = [ diff --git a/test/Builder.php b/test/Builder.php index 58cba771..dcf63ec8 100644 --- a/test/Builder.php +++ b/test/Builder.php @@ -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')]))]), @@ -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')]))])); diff --git a/test/Model/ArticleVoRTest.php b/test/Model/ArticleVoRTest.php index 78a5a5c1..90b22268 100644 --- a/test/Model/ArticleVoRTest.php +++ b/test/Model/ArticleVoRTest.php @@ -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()); diff --git a/test/Serializer/ArticleVoRNormalizerTest.php b/test/Serializer/ArticleVoRNormalizerTest.php index 04a442d7..cdf74c82 100644 --- a/test/Serializer/ArticleVoRNormalizerTest.php +++ b/test/Serializer/ArticleVoRNormalizerTest.php @@ -527,7 +527,7 @@ function ($test) { ->withPromiseOfAuthorResponse(null) ->withPromiseOfElifeAssessmentArticleSection(null) ->withElifeAssessmentTitle(null) - ->withPromiseOfElifeAssessmentScietyUri(null) + ->withElifeAssessmentScietyUri(null) ->withPromiseOfRecommendationsForAuthors(null) ->withPromiseOfRecommendationsForAuthorsTitle(null) ->withDoiVersion(null) @@ -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')]))])) @@ -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'], @@ -708,7 +708,7 @@ function (ApiTestCase $test) { ->withPromiseOfAuthorResponse(null) ->withPromiseOfElifeAssessmentArticleSection(null) ->withElifeAssessmentTitle(null) - ->withPromiseOfElifeAssessmentScietyUri(null) + ->withElifeAssessmentScietyUri(null) ->withPromiseOfRecommendationsForAuthors(null) ->withPromiseOfRecommendationsForAuthorsTitle(null) ->withDoiVersion(null)