From 93a7d49777f3d0d77e7fdea9f77d6f7e12b674a0 Mon Sep 17 00:00:00 2001 From: Aday Bujeda Date: Thu, 19 Dec 2024 19:23:09 +0000 Subject: [PATCH] Added unit tests for missing reviewer names in emails fix --- .../email/PPRFirstNameEmailServiceTest.php | 24 +++++++++++++++++++ .../PPRFirstNamesManagementServiceTest.php | 18 ++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/pprOjsPlugin/tests/src/services/email/PPRFirstNameEmailServiceTest.php b/pprOjsPlugin/tests/src/services/email/PPRFirstNameEmailServiceTest.php index fa0d49b..5e10725 100644 --- a/pprOjsPlugin/tests/src/services/email/PPRFirstNameEmailServiceTest.php +++ b/pprOjsPlugin/tests/src/services/email/PPRFirstNameEmailServiceTest.php @@ -6,6 +6,7 @@ import('lib.pkp.controllers.grid.users.reviewer.form.ThankReviewerForm'); import('lib.pkp.controllers.grid.users.reviewer.form.ReviewReminderForm'); +import('lib.pkp.controllers.grid.users.reviewer.form.CreateReviewerForm'); class PPRFirstNameEmailServiceTest extends PPRTestCase { @@ -148,6 +149,29 @@ public function test_addFirstNameLabelsToAdvancedSearchReviewerForm_should_deleg $this->assertEquals(false, $result); } + public function test_addFirstNameLabelsToCreateReviewerForm_should_delegate_to_pprFirstNamesManagementService() { + $objectFactory = $this->getTestUtil()->createObjectFactory(); + + $objectFactory->expects($this->atLeastOnce())->method('firstNamesManagementService'); + $objectFactory->firstNamesManagementService()->expects($this->once())->method('addFirstNameLabelsToTemplate'); + + $target = new PPRFirstNameEmailService($this->defaultPPRPlugin, $objectFactory); + $result = $target->addFirstNameLabelsToCreateReviewerForm('createreviewerform::display', [null]); + $this->assertEquals(false, $result); + } + + public function test_addCreatedReviewerId_should_update_template_manager_with_reviewerId() { + $objectFactory = $this->getTestUtil()->createObjectFactory(); + $form = $this->createMock(CreateReviewerForm::class); + $reviewerId = $this->getRandomId(); + $form->method('getData')->with('reviewerId')->willReturn($reviewerId); + + $target = new PPRFirstNameEmailService($this->defaultPPRPlugin, $objectFactory); + $target->addCreatedReviewerId('createreviewerform::execute', [$form]); + $templateManager = TemplateManager::getManager(); + $this->assertEquals($reviewerId, $templateManager->getTemplateVars('reviewerId')); + } + public function test_addFirstNamesToThankReviewerForm_should_update_form_message_variable_with_firstNamesManagementService_result() { $objectFactory = $this->getTestUtil()->createObjectFactory(); $form = $this->createMock(ThankReviewerForm::class); diff --git a/pprOjsPlugin/tests/src/util/PPRFirstNamesManagementServiceTest.php b/pprOjsPlugin/tests/src/util/PPRFirstNamesManagementServiceTest.php index 87db134..4d49c4e 100644 --- a/pprOjsPlugin/tests/src/util/PPRFirstNamesManagementServiceTest.php +++ b/pprOjsPlugin/tests/src/util/PPRFirstNamesManagementServiceTest.php @@ -5,6 +5,12 @@ class PPRFirstNamesManagementServiceTest extends PPRTestCase { + public function setUp(): void { + parent::setUp(); + # RESET TEMPLATE MANAGER DATA + TemplateManager::getManager()->setData([]); + } + public function test_getReviewer_should_use_reviewerId_if_provided() { $submissionUtil = $this->createMock(PPRSubmissionUtil::class); $reviewerId = $this->getRandomId(); @@ -26,6 +32,18 @@ public function test_getReviewer_should_use_request_reviewerId_reviewerId_is_not $this->assertEquals($reviewer, $result); } + public function test_getReviewer_should_use_template_manager_reviewerId_when_parameter_and_request_reviewerId_not_set() { + $submissionUtil = $this->createMock(PPRSubmissionUtil::class); + $reviewerId = $this->getRandomId(); + $reviewer = $this->addReviewer($submissionUtil, $reviewerId); + $this->getRequestMock()->method('getUserVar')->with('reviewerId')->willReturn(null); + TemplateManager::getManager()->assign('reviewerId', $reviewerId); + + $target = new PPRFirstNamesManagementService($submissionUtil); + $result = $target->getReviewer(null); + $this->assertEquals($reviewer, $result); + } + public function test_getReviewer_should_use_request_reviewAssignmentId_when_parameter_and_request_reviewerId_not_set() { $submissionUtil = $this->createMock(PPRSubmissionUtil::class); $reviewAssignmentId = $this->getRandomId();