Skip to content

Commit

Permalink
Added unit tests for missing reviewer names in emails fix
Browse files Browse the repository at this point in the history
  • Loading branch information
abujeda committed Dec 19, 2024
1 parent a13baf5 commit 93a7d49
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions pprOjsPlugin/tests/src/util/PPRFirstNamesManagementServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 93a7d49

Please sign in to comment.