Skip to content

Commit d39a6da

Browse files
touhidurabirGaziYucel
authored andcommitted
#10306 unit tests for queue jobs (#10340)
* #10306 unit tests for queue jobs * #10306 added unit test for job RemoveExpiredInvitationsJob * #10306 added not to perform assertion on void return type method * #10306 fixed test class namespace * #10306 updated user repository class import path * #10306 added mock support * #10306 removed direct mocking of job class * #10306 fixed jobs data for OMP * #10306 updated job data for OPS * #10306 updated job data for OJS * #10306 update context dao determining based on application name * #10306 removed unnecessary request param from createNotification method * #10306 addressed warnings and notification table backup/restore * #10306 fixed id issue for NewAnnouncementNotifyUsers job * #10306 added skip for ReviewReminder job test for OPS * #10306 fixed query repository notification create issue with request param * #10306 fixed issue with dummy file and added router name on request mock * #10306 updated announcement notify test to consider eloquent storage
1 parent 9c2b529 commit d39a6da

File tree

49 files changed

+2013
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2013
-52
lines changed

api/v1/submissions/PKPSubmissionController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,6 @@ public function versionPublication(Request $illuminateRequest): JsonResponse
11661166
$notificationSubscriptionSettingsDao = DAORegistry::getDAO('NotificationSubscriptionSettingsDAO');
11671167
foreach ($usersIterator as $user) {
11681168
$notification = $notificationManager->createNotification(
1169-
$request,
11701169
$user->getId(),
11711170
Notification::NOTIFICATION_TYPE_SUBMISSION_NEW_VERSION,
11721171
$submission->getData('contextId'),

classes/context/SubEditorsDAO.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ public function assignEditors(Submission $submission, Context $context): Collect
233233
// Send a notification to assigned users
234234
foreach ($assignments as $assignment) {
235235
$notificationManager->createNotification(
236-
Application::get()->getRequest(),
237236
$assignment->userId,
238237
Notification::NOTIFICATION_TYPE_SUBMISSION_SUBMITTED,
239238
$submission->getData('contextId'),

classes/core/PKPApplication.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@ public function getUUID(): string
317317
*/
318318
public function getHttpClient(): Client
319319
{
320+
if (PKPContainer::getInstance()->runningUnitTests()) {
321+
$client = Registry::get(\PKP\tests\PKPTestCase::MOCKED_GUZZLE_CLIENT_NAME);
322+
if ($client) {
323+
return $client;
324+
}
325+
}
326+
320327
$application = Application::get();
321328
$userAgent = $application->getName() . '/';
322329
if (static::isInstalled() && !static::isUpgrading()) {

classes/core/PKPContainer.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040

4141
class PKPContainer extends Container
4242
{
43+
/**
44+
* Define if the app currently runing the unit test
45+
*/
46+
private bool $isRunningUnitTest = false;
47+
4348
/**
4449
* The base path of the application, needed for base_path helper
4550
*/
@@ -538,15 +543,6 @@ protected function settingProxyForStreamContext(): void
538543
libxml_set_streams_context($context);
539544
}
540545

541-
/**
542-
* Override Laravel method; always false.
543-
* Prevents the undefined method error when the Log Manager tries to determine the driver
544-
*/
545-
public function runningUnitTests(): bool
546-
{
547-
return false;
548-
}
549-
550546
/**
551547
* Determine if the application is currently down for maintenance.
552548
*/
@@ -590,6 +586,31 @@ public function environment(string ...$environments): string|bool
590586

591587
return $this->get('config')['app']['env'];
592588
}
589+
590+
/**
591+
* Override Laravel method; always false.
592+
* Prevents the undefined method error when the Log Manager tries to determine the driver
593+
*/
594+
public function runningUnitTests(): bool
595+
{
596+
return $this->isRunningUnitTest;
597+
}
598+
599+
/**
600+
* Set the app running unit test
601+
*/
602+
public function setRunningUnitTests(): void
603+
{
604+
$this->isRunningUnitTest = true;
605+
}
606+
607+
/**
608+
* Unset the app running unit test
609+
*/
610+
public function unsetRunningUnitTests(): void
611+
{
612+
$this->isRunningUnitTest = false;
613+
}
593614
}
594615

595616
if (!PKP_STRICT_MODE) {

classes/decision/DecisionType.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ protected function createReviewRound(Submission $submission, int $stageId, ?int
523523
if ($count == 0) {
524524
$notificationMgr = new NotificationManager();
525525
$notificationMgr->createNotification(
526-
Application::get()->getRequest(),
527526
null,
528527
Notification::NOTIFICATION_TYPE_REVIEW_ROUND_STATUS,
529528
$submission->getData('contextId'),

classes/mail/mailables/AnnouncementNotify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function setData(?string $locale = null): void
8989
$this->context->getData('urlPath'),
9090
'announcement',
9191
'view',
92-
$this->announcement->getAttribute('announcementId')
92+
[$this->announcement->getAttribute('announcementId')]
9393
),
9494
]
9595
);

classes/mail/mailables/EditorialReminder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function setOutstandingTasks(array $outstanding, array $submissions, int
7474
$this->context->getPath(),
7575
'workflow',
7676
'access',
77-
$submission->getId()
77+
[$submission->getId()]
7878
);
7979

8080
$outstandingTasks[] = '

classes/notification/NotificationManagerDelegate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
5656
*
5757
* @copydoc PKPNotificationOperationManager::createNotification()
5858
*/
59-
public function createNotification(PKPRequest $request, ?int $userId = null, ?int $notificationType = null, ?int $contextId = Application::SITE_CONTEXT_ID, ?int $assocType = null, ?int $assocId = null, int $level = Notification::NOTIFICATION_LEVEL_NORMAL, ?array $params = null): ?Notification
59+
public function createNotification(?int $userId = null, ?int $notificationType = null, ?int $contextId = Application::SITE_CONTEXT_ID, ?int $assocType = null, ?int $assocId = null, int $level = Notification::NOTIFICATION_LEVEL_NORMAL, ?array $params = null): ?Notification
6060
{
6161
assert($notificationType == $this->getNotificationType() || $this->multipleTypesUpdate());
62-
return parent::createNotification($request, $userId, $notificationType, $contextId, $assocType, $assocId, $level, $params);
62+
return parent::createNotification($userId, $notificationType, $contextId, $assocType, $assocId, $level, $params);
6363
}
6464

6565
/**

classes/notification/PKPNotificationOperationManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getParamsForCurrentLocale(array $params): array
140140
/**
141141
* Create a new notification with the specified arguments and insert into DB
142142
*/
143-
public function createNotification(PKPRequest $request, ?int $userId = null, ?int $notificationType = null, ?int $contextId = Application::SITE_CONTEXT_ID, ?int $assocType = null, ?int $assocId = null, int $level = Notification::NOTIFICATION_LEVEL_NORMAL, ?array $params = null): ?Notification
143+
public function createNotification(?int $userId = null, ?int $notificationType = null, ?int $contextId = Application::SITE_CONTEXT_ID, ?int $assocType = null, ?int $assocId = null, int $level = Notification::NOTIFICATION_LEVEL_NORMAL, ?array $params = null): ?Notification
144144
{
145145
if ($userId && in_array($notificationType, $this->getUserBlockedNotifications($userId, $contextId))) {
146146
return null;
@@ -228,7 +228,7 @@ public function formatToGeneralNotification(PKPRequest $request, array $notifica
228228
*/
229229
public function formatToInPlaceNotification(PKPRequest $request, array $notifications): array
230230
{
231-
$formattedNotificationsData = null;
231+
$formattedNotificationsData = [];
232232

233233
$templateMgr = TemplateManager::getManager($request);
234234
foreach ($notifications as $notification) {

classes/notification/managerDelegate/AnnouncementNotificationManager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public function getStyleClass($notification): string
9696
public function notify(User $user): ?Notification
9797
{
9898
return parent::createNotification(
99-
Application::get()->getRequest(),
10099
$user->getId(),
101100
Notification::NOTIFICATION_TYPE_NEW_ANNOUNCEMENT,
102101
$this->_announcement->getAttribute('assocId'),

0 commit comments

Comments
 (0)