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

pkp/pkp-lib#10306 Queue jobs unit tests #4411

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion classes/decision/types/traits/RequestPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ protected function requestPayment(Submission $submission, User $editor, Context
$authorIds = $this->getAssignedAuthorIds($submission);
foreach ($authorIds as $authorId) {
$notificationMgr->createNotification(
Application::get()->getRequest(),
$authorId,
Notification::NOTIFICATION_TYPE_PAYMENT_REQUIRED,
$context->getId(),
Expand Down
4 changes: 2 additions & 2 deletions jobs/notifications/IssuePublishedNotifyUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use PKP\context\Context;
use PKP\emailTemplate\EmailTemplate;
use PKP\jobs\BaseJob;
use PKP\notification\Notification as PKPNotification;
use PKP\user\User;

class IssuePublishedNotifyUsers extends BaseJob
Expand Down Expand Up @@ -73,7 +74,6 @@ public function handle()

$notificationManager = new NotificationManager();
$notification = $notificationManager->createNotification(
null,
$recipientId,
Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE,
$this->contextId,
Expand All @@ -99,7 +99,7 @@ protected function createMailable(
Issue $issue,
User $recipient,
EmailTemplate $template,
Notification $notification
PKPNotification $notification
): IssuePublishedNotify {
$mailable = new IssuePublishedNotify($context, $issue);
$mailable
Expand Down
1 change: 0 additions & 1 deletion jobs/notifications/OpenAccessMailUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function handle()

$notificationManager = new NotificationManager();
$notification = $notificationManager->createNotification(
null,
$userId,
Notification::NOTIFICATION_TYPE_OPEN_ACCESS,
$this->contextId
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
Submodule pkp updated 50 files
+0 −1 api/v1/submissions/PKPSubmissionController.php
+0 −1 classes/context/SubEditorsDAO.php
+7 −0 classes/core/PKPApplication.php
+30 −9 classes/core/PKPContainer.php
+0 −1 classes/decision/DecisionType.php
+1 −1 classes/mail/mailables/AnnouncementNotify.php
+1 −1 classes/mail/mailables/EditorialReminder.php
+2 −2 classes/notification/NotificationManagerDelegate.php
+2 −2 classes/notification/PKPNotificationOperationManager.php
+0 −1 classes/notification/managerDelegate/AnnouncementNotificationManager.php
+0 −1 classes/notification/managerDelegate/EditorAssignmentNotificationManager.php
+0 −1 classes/notification/managerDelegate/EditorDecisionNotificationManager.php
+0 −1 classes/notification/managerDelegate/EditorialReportNotificationManager.php
+0 −1 classes/notification/managerDelegate/PKPApproveSubmissionNotificationManager.php
+1 −6 classes/notification/managerDelegate/PKPEditingProductionStatusNotificationManager.php
+0 −1 classes/observers/listeners/AssignEditors.php
+0 −1 classes/query/Repository.php
+0 −1 classes/submission/action/EditorAction.php
+0 −1 classes/submission/reviewer/form/PKPReviewerReviewStep3Form.php
+56 −130 composer.lock
+0 −1 controllers/grid/queries/QueriesGridHandler.php
+0 −1 controllers/grid/queries/QueryNotesGridHandler.php
+0 −1 controllers/grid/users/reviewer/form/EditReviewForm.php
+0 −2 controllers/grid/users/stageParticipant/form/PKPStageParticipantNotifyForm.php
+0 −1 jobs/email/EditorialReminder.php
+0 −1 jobs/email/ReviewReminder.php
+0 −1 jobs/invitations/RemoveExpiredInvitationsJob.php
+4 −1 jobs/notifications/NewAnnouncementNotifyUsers.php
+0 −1 jobs/notifications/StatisticsReportMail.php
+67 −8 tests/PKPTestCase.php
+77 −0 tests/jobs/bulk/BulkEmailSenderTest.php
+100 −0 tests/jobs/doi/DepositContextTest.php
+179 −0 tests/jobs/doi/DepositSubmissionTest.php
+215 −0 tests/jobs/email/EditorialReminderTest.php
+55 −0 tests/jobs/invitations/RemoveExpiredInvitationsJobTest.php
+109 −0 tests/jobs/metadata/BatchMetadataChangedJobTest.php
+109 −0 tests/jobs/metadata/MetadataChangedJobTest.php
+162 −0 tests/jobs/notifications/NewAnnouncementNotifyUsersTest.php
+169 −0 tests/jobs/notifications/StatisticsReportMailTest.php
+92 −0 tests/jobs/notifications/StatisticsReportNotifyTest.php
+131 −0 tests/jobs/statistics/ArchiveUsageStatsLogFileTest.php
+66 −0 tests/jobs/statistics/CompileContextMetricsTest.php
+79 −0 tests/jobs/statistics/CompileMonthlyMetricsTest.php
+66 −0 tests/jobs/statistics/CompileSubmissionMetricsTest.php
+66 −0 tests/jobs/statistics/RemoveDoubleClicksTest.php
+67 −0 tests/jobs/submissions/RemoveSubmissionFileFromSearchIndexJobTest.php
+67 −0 tests/jobs/submissions/RemoveSubmissionFromSearchIndexJobTest.php
+ tests/jobs/submissions/UpdateSubmissionSearchJobTest.php
+1 −1 tests/phpunit.xml
+88 −0 tests/support/DoiRegistrationAgency.php
1 change: 0 additions & 1 deletion tests/jobs/.gitkeep

This file was deleted.

117 changes: 117 additions & 0 deletions tests/jobs/doi/DepositIssueTest.php

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions tests/jobs/notifications/IssuePublishedNotifyUsersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

/**
* @file tests/jobs/notifications/IssuePublishedNotifyUsersTest.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @brief Tests for notifying users about issue publish job.
*/

namespace APP\tests\jobs\notifications;

use APP\core\Application;
use APP\jobs\notifications\IssuePublishedNotifyUsers;
use APP\template\TemplateManager;
use Mockery;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use PKP\db\DAORegistry;
use PKP\emailTemplate\Repository as EmailTemplateRepository;
use PKP\tests\DatabaseTestCase;

#[RunTestsInSeparateProcesses]
#[CoversClass(IssuePublishedNotifyUsers::class)]
class IssuePublishedNotifyUsersTest extends DatabaseTestCase
{
/**
* base64_encoded serializion from OJS 3.4.0
*/
protected string $serializedJobData = <<<END
O:48:"APP\\jobs\\notifications\\IssuePublishedNotifyUsers":8:{s:15:"\0*\0recipientIds";O:29:"Illuminate\\Support\\Collection":2:{s:8:"\0*\0items";a:18:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;i:5;i:6;i:6;i:7;i:7;i:8;i:8;i:9;i:9;i:10;i:10;i:11;i:11;i:12;i:12;i:13;i:13;i:14;i:14;i:15;i:15;i:16;i:35;i:37;i:36;i:38;}s:28:"\0*\0escapeWhenCastingToString";b:0;}s:12:"\0*\0contextId";i:1;s:8:"\0*\0issue";O:15:"APP\\issue\\Issue":6:{s:5:"_data";a:21:{s:2:"id";i:2;s:9:"journalId";i:1;s:6:"volume";i:2;s:6:"number";s:1:"1";s:4:"year";i:2015;s:9:"published";i:1;s:13:"datePublished";s:19:"2024-05-23 11:59:46";s:12:"dateNotified";N;s:12:"lastModified";s:19:"2024-05-23 11:59:46";s:12:"accessStatus";i:1;s:14:"openAccessDate";N;s:10:"showVolume";b:1;s:10:"showNumber";b:1;s:8:"showYear";b:1;s:9:"showTitle";b:0;s:13:"styleFileName";N;s:21:"originalStyleFileName";N;s:7:"urlPath";s:0:"";s:5:"doiId";i:5;s:11:"description";a:2:{s:2:"en";s:0:"";s:5:"fr_CA";s:0:"";}s:5:"title";a:2:{s:2:"en";s:0:"";s:5:"fr_CA";s:0:"";}}s:20:"_hasLoadableAdapters";b:0;s:27:"_metadataExtractionAdapters";a:0:{}s:25:"_extractionAdaptersLoaded";b:0;s:26:"_metadataInjectionAdapters";a:0:{}s:24:"_injectionAdaptersLoaded";b:0;}s:9:"\0*\0locale";s:2:"en";s:9:"\0*\0sender";O:13:"PKP\\user\\User":7:{s:5:"_data";a:22:{s:2:"id";i:1;s:8:"userName";s:5:"admin";s:8:"password";s:60:"$2y$10\$uFmYXg8/Ufa0HbskyW57Be22stFGY5qtxJZmTOae3PfDB86V3x7BW";s:5:"email";s:23:"pkpadmin@mailinator.com";s:3:"url";N;s:5:"phone";N;s:14:"mailingAddress";N;s:14:"billingAddress";N;s:7:"country";N;s:7:"locales";a:0:{}s:6:"gossip";N;s:13:"dateLastEmail";N;s:14:"dateRegistered";s:19:"2023-02-28 20:19:07";s:13:"dateValidated";N;s:13:"dateLastLogin";s:19:"2024-05-22 19:05:03";s:18:"mustChangePassword";N;s:7:"authStr";N;s:8:"disabled";b:0;s:14:"disabledReason";N;s:10:"inlineHelp";b:1;s:10:"familyName";a:1:{s:2:"en";s:5:"admin";}s:9:"givenName";a:1:{s:2:"en";s:5:"admin";}}s:20:"_hasLoadableAdapters";b:0;s:27:"_metadataExtractionAdapters";a:0:{}s:25:"_extractionAdaptersLoaded";b:0;s:26:"_metadataInjectionAdapters";a:0:{}s:24:"_injectionAdaptersLoaded";b:0;s:9:"\0*\0_roles";a:0:{}}s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";s:7:"batchId";s:36:"9c1c1368-8bb4-4179-a350-403decb700ba";}
END;

/**
* @see \PKP\tests\DatabaseTestCase@getAffectedTables
*/
protected function getAffectedTables(): array
{
return [
'notifications'
];
}

/**
* Test job is a proper instance
*/
public function testUnserializationGetProperDepositIssueJobInstance(): void
{
$this->assertInstanceOf(
IssuePublishedNotifyUsers::class,
unserialize(($this->serializedJobData))
);
}

/**
* Ensure that a serialized job can be unserialized and executed
*/
public function testRunSerializedJob(): void
{
$this->mockMail();

// need to mock request so that a valid context information is set and can be retrived
$this->mockRequest();

/** @var IssuePublishedNotifyUsers $issuePublishedNotifyUsersJob */
$issuePublishedNotifyUsersJob = unserialize(($this->serializedJobData));

$contextMock = Mockery::mock(get_class(Application::getContextDAO()->newDataObject()))
->makePartial()
->shouldReceive([
'getId' => 1,
'getLocalizedData' => '',
])
->withAnyArgs()
->getMock();

$journalDAOMock = Mockery::mock(\APP\journal\JournalDAO::class)
->makePartial()
->shouldReceive('getById')
->withAnyArgs()
->andReturn($contextMock)
->getMock();

DAORegistry::registerDAO('JournalDAO', $journalDAOMock);

$emailTemplateMock = Mockery::mock(\PKP\emailTemplate\EmailTemplate::class)
->makePartial()
->shouldReceive([
'getLocalizedData' => 'some test string',
])
->withAnyArgs()
->getMock();

$emailTemplateRepoMock = Mockery::mock(app(EmailTemplateRepository::class))
->makePartial()
->shouldReceive([
'getByKey' => $emailTemplateMock,
])
->withAnyArgs()
->getMock();

app()->instance(EmailTemplateRepository::class, $emailTemplateRepoMock);

$notificationSettingsDaoMock = Mockery::mock(\PKP\notification\NotificationSettingsDAO::class)
->makePartial()
->shouldReceive('updateNotificationSetting')
->withAnyArgs()
->andReturn(null)
->getMock();

DAORegistry::registerDAO('NotificationSettingsDAO', $notificationSettingsDaoMock);

TemplateManager::getManager()->assign([
'heading' => null,
'pubIdPlugins' => [],
]);

$issuePublishedNotifyUsersJob->handle();

$this->expectNotToPerformAssertions();
}
}
130 changes: 130 additions & 0 deletions tests/jobs/notifications/OpenAccessMailUsersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

/**
* @file tests/jobs/notifications/OpenAccessMailUsersTest.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @brief Tests for open access mail to users job.
*/

namespace APP\tests\jobs\notifications;

use APP\core\Application;
use APP\issue\Repository as IssueRepository;
use APP\jobs\notifications\OpenAccessMailUsers;
use Mockery;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use PKP\db\DAORegistry;
use PKP\emailTemplate\Repository as EmailTemplateRepository;
use PKP\tests\DatabaseTestCase;

#[RunTestsInSeparateProcesses]
#[CoversClass(OpenAccessMailUsers::class)]
class OpenAccessMailUsersTest extends DatabaseTestCase
{
/**
* base64_encoded serializion from OJS 3.4.0
*/
protected string $serializedJobData = <<<END
O:42:"APP\\jobs\\notifications\\OpenAccessMailUsers":6:{s:10:"\0*\0userIds";O:29:"Illuminate\\Support\\Collection":2:{s:8:"\0*\0items";a:2:{i:0;i:1;i:1;i:2;}s:28:"\0*\0escapeWhenCastingToString";b:0;}s:12:"\0*\0contextId";i:1;s:10:"\0*\0issueId";i:1;s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";s:7:"batchId";s:36:"9c1c4502-5261-4b4a-965c-256cd0eaaaa4";}
END;

/**
* @see \PKP\tests\DatabaseTestCase@getAffectedTables
*/
protected function getAffectedTables(): array
{
return [
'notifications'
];
}

/**
* Test job is a proper instance
*/
public function testUnserializationGetProperDepositIssueJobInstance(): void
{
$this->assertInstanceOf(
OpenAccessMailUsers::class,
unserialize($this->serializedJobData)
);
}

/**
* Ensure that a serialized job can be unserialized and executed
*/
public function testRunSerializedJob(): void
{
$this->mockMail();

// need to mock request so that a valid context information is set and can be retrived
$this->mockRequest();

/** @var OpenAccessMailUsers $openAccessMailUsersJob */
$openAccessMailUsersJob = unserialize($this->serializedJobData);

$contextMock = Mockery::mock(get_class(Application::getContextDAO()->newDataObject()))
->makePartial()
->shouldReceive([
'getId' => 0,
'getLocalizedData' => '',
'getPrimaryLocale' => 'en',
])
->withAnyArgs()
->getMock();

$journalDAOMock = Mockery::mock(\APP\journal\JournalDAO::class)
->makePartial()
->shouldReceive('getById')
->withAnyArgs()
->andReturn($contextMock)
->getMock();

DAORegistry::registerDAO('JournalDAO', $journalDAOMock);

$issueRepoMock = Mockery::mock(app(IssueRepository::class))
->makePartial()
->shouldReceive([
'get' => new \APP\issue\Issue(),
])
->withAnyArgs()
->getMock();

app()->instance(IssueRepository::class, $issueRepoMock);

$emailTemplateMock = Mockery::mock(\PKP\emailTemplate\EmailTemplate::class)
->makePartial()
->shouldReceive([
'getLocalizedData' => 'some test string',
])
->withAnyArgs()
->getMock();

$emailTemplateRepoMock = Mockery::mock(app(EmailTemplateRepository::class))
->makePartial()
->shouldReceive([
'getByKey' => $emailTemplateMock,
])
->withAnyArgs()
->getMock();

app()->instance(EmailTemplateRepository::class, $emailTemplateRepoMock);

$notificationSettingsDaoMock = Mockery::mock(\PKP\notification\NotificationSettingsDAO::class)
->makePartial()
->shouldReceive('updateNotificationSetting')
->withAnyArgs()
->andReturn(null)
->getMock();

DAORegistry::registerDAO('NotificationSettingsDAO', $notificationSettingsDaoMock);

$openAccessMailUsersJob->handle();

$this->expectNotToPerformAssertions();
}
}
88 changes: 88 additions & 0 deletions tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/**
* @file tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @brief Tests for compile counter submission daily metrics job.
*/

namespace APP\tests\jobs\statistics;

use APP\jobs\statistics\CompileCounterSubmissionDailyMetrics;
use Mockery;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use PKP\db\DAORegistry;
use PKP\tests\PKPTestCase;

#[RunTestsInSeparateProcesses]
#[CoversClass(CompileCounterSubmissionDailyMetrics::class)]
class CompileCounterSubmissionDailyMetricsTest extends PKPTestCase
{
/**
* base64_encoded serializion from OJS 3.4.0
*/
protected string $serializedJobData = <<<END
O:56:"APP\\jobs\\statistics\\CompileCounterSubmissionDailyMetrics":3:{s:9:"\0*\0loadId";s:25:"usage_events_20240130.log";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";}
END;

/**
* Test job is a proper instance
*/
public function testUnserializationGetProperDepositIssueJobInstance(): void
{
$this->assertInstanceOf(
CompileCounterSubmissionDailyMetrics::class,
unserialize($this->serializedJobData)
);
}

/**
* Ensure that a serialized job can be unserialized and executed
*/
public function testRunSerializedJob(): void
{
/** @var CompileCounterSubmissionDailyMetrics $compileCounterSubmissionDailyMetricsJob */
$compileCounterSubmissionDailyMetricsJob = unserialize($this->serializedJobData);

$temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class)
->makePartial()
->shouldReceive([
'deleteCounterSubmissionDailyByLoadId' => null,
'compileCounterSubmissionDailyMetrics' => null,
])
->withAnyArgs()
->getMock();

DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock);

$temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class)
->makePartial()
->shouldReceive([
'compileCounterSubmissionDailyMetrics' => null,
])
->withAnyArgs()
->getMock();

DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock);

$temporaryItemRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemRequestsDAO::class)
->makePartial()
->shouldReceive([
'compileCounterSubmissionDailyMetrics' => null,
])
->withAnyArgs()
->getMock();

DAORegistry::registerDAO('TemporaryItemRequestsDAO', $temporaryItemRequestsDAOMock);


$compileCounterSubmissionDailyMetricsJob->handle();

$this->expectNotToPerformAssertions();
}
}
Loading