Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed missing reviewer names in emails #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pprOjsPlugin/services/email/PPRFirstNameEmailService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function register() {
HookRegistry::register('TemplateManager::fetch', array($this, 'replaceFirstNameInTemplateText'));

HookRegistry::register('advancedsearchreviewerform::display', array($this, 'addFirstNameLabelsToAdvancedSearchReviewerForm'));
HookRegistry::register('createreviewerform::display', array($this, 'addFirstNameLabelsToCreateReviewerForm'));
HookRegistry::register('createreviewerform::execute', array($this, 'addCreatedReviewerId'));

HookRegistry::register('LoadComponentHandler', array($this, 'addPPRStageParticipantGridHandler'));
}
Expand Down Expand Up @@ -109,6 +111,19 @@ function addFirstNameLabelsToAdvancedSearchReviewerForm($hookName, $arguments) {
return false;
}

function addFirstNameLabelsToCreateReviewerForm($hookName, $arguments) {
$this->pprObjectFactory->firstNamesManagementService()->addFirstNameLabelsToTemplate('emailVariables');

return false;
}

function addCreatedReviewerId($hookName, $arguments) {
$form = $arguments[0];
$reviewerId = $form->getData('reviewerId');
$templateMgr = TemplateManager::getManager(Application::get()->getRequest());
$templateMgr->assign(['reviewerId' => $reviewerId]);
}

function addFirstNamesToThankReviewerForm($hookName, $arguments) {
$thankReviewerForm = $arguments[0];
$review = $thankReviewerForm->getReviewAssignment();
Expand Down
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 @@ -36,13 +37,15 @@ public function test_register_should_register_service_hooks_when_firstNameEmailE
$target = new PPRFirstNameEmailService($pprPluginMock);
$target->register();

$this->assertEquals(7, $this->countHooks());
$this->assertEquals(9, $this->countHooks());
$this->assertEquals(1, count($this->getHooks('Mail::send')));
$this->assertEquals(1, count($this->getHooks('reviewreminderform::display')));
$this->assertEquals(1, count($this->getHooks('thankreviewerform::display')));
$this->assertEquals(1, count($this->getHooks('sendreviewsform::display')));
$this->assertEquals(1, count($this->getHooks('TemplateManager::fetch')));
$this->assertEquals(1, count($this->getHooks('advancedsearchreviewerform::display')));
$this->assertEquals(1, count($this->getHooks('createreviewerform::display')));
$this->assertEquals(1, count($this->getHooks('createreviewerform::execute')));
$this->assertEquals(1, count($this->getHooks('LoadComponentHandler')));
}

Expand Down Expand Up @@ -146,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
4 changes: 4 additions & 0 deletions pprOjsPlugin/util/PPRFirstNamesManagementService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ public function replaceFirstNames($originalText, $submission, $reviewerId = null

public function getReviewer($reviewerId) {
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$reviewer = null;
if ($reviewerId) {
$reviewer = $this->pprSubmissionUtil->getUser($reviewerId);
} elseif ($reviewerId = $request->getUserVar('reviewerId')) {
// TRY reviewerId REQUEST PARAMETER
$reviewer = $this->pprSubmissionUtil->getUser($reviewerId);
} elseif ($reviewerId = $templateMgr->getTemplateVars('reviewerId')) {
// TRY reviewerId IN TEMPLATE MANAGER
$reviewer = $this->pprSubmissionUtil->getUser($reviewerId);
} elseif ($reviewId = $request->getUserVar('reviewAssignmentId')) {
// TRY reviewAssignment REQUEST PARAMETER
$reviewer = $this->pprSubmissionUtil->getReviewer($reviewId);
Expand Down
Loading