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 unit tests for queue jobs #10340

Open
wants to merge 12 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
1 change: 0 additions & 1 deletion api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ public function versionPublication(Request $illuminateRequest): JsonResponse
$notificationSubscriptionSettingsDao = DAORegistry::getDAO('NotificationSubscriptionSettingsDAO');
foreach ($usersIterator as $user) {
$notification = $notificationManager->createNotification(
$request,
$user->getId(),
Notification::NOTIFICATION_TYPE_SUBMISSION_NEW_VERSION,
$submission->getData('contextId'),
Expand Down
1 change: 0 additions & 1 deletion classes/context/SubEditorsDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ public function assignEditors(Submission $submission, Context $context): Collect
// Send a notification to assigned users
foreach ($assignments as $assignment) {
$notificationManager->createNotification(
Application::get()->getRequest(),
$assignment->userId,
Notification::NOTIFICATION_TYPE_SUBMISSION_SUBMITTED,
$submission->getData('contextId'),
Expand Down
7 changes: 7 additions & 0 deletions classes/core/PKPApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ public function getUUID(): string
*/
public function getHttpClient(): Client
{
if (PKPContainer::getInstance()->runningUnitTests()) {
$client = Registry::get(\PKP\tests\PKPTestCase::MOCKED_GUZZLE_CLIENT_NAME);
if ($client) {
return $client;
}
}

Comment on lines +319 to +325
Copy link
Member Author

@touhidurabir touhidurabir Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part of functionality to mocking ability for guzzel request .

$application = Application::get();
$userAgent = $application->getName() . '/';
if (static::isInstalled() && !static::isUpgrading()) {
Expand Down
39 changes: 30 additions & 9 deletions classes/core/PKPContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@

class PKPContainer extends Container
{
/**
* Define if the app currently runing the unit test
*/
private bool $isRunningUnitTest = false;

/**
* The base path of the application, needed for base_path helper
*/
Expand Down Expand Up @@ -538,15 +543,6 @@ protected function settingProxyForStreamContext(): void
libxml_set_streams_context($context);
}

/**
* Override Laravel method; always false.
* Prevents the undefined method error when the Log Manager tries to determine the driver
*/
public function runningUnitTests(): bool
{
return false;
}

/**
* Determine if the application is currently down for maintenance.
*/
Expand Down Expand Up @@ -590,6 +586,31 @@ public function environment(string ...$environments): string|bool

return $this->get('config')['app']['env'];
}

/**
* Override Laravel method; always false.
* Prevents the undefined method error when the Log Manager tries to determine the driver
*/
public function runningUnitTests(): bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be removed once we add and configure the Laravel logging service provider, correct? I think this is related to what you're talking about with Erik. It might be worth filing in Github, noting this function in the issue, and adding a FIXME here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly , this has there before this PR and probably will stay . Our Container class extends the laravel core container but We have our very own Application class . Once we able to handle the bootstrapping process to Laravel's foundation Application, we can remove this (as it's reside there) . As few core class required this information, so we have copied it from Laravel's foundation application class to our PKPContainer just to facilitate the dependency.

{
return $this->isRunningUnitTest;
}

/**
* Set the app running unit test
*/
public function setRunningUnitTests(): void
{
$this->isRunningUnitTest = true;
}

/**
* Unset the app running unit test
*/
public function unsetRunningUnitTests(): void
{
$this->isRunningUnitTest = false;
}
}

if (!PKP_STRICT_MODE) {
Expand Down
1 change: 0 additions & 1 deletion classes/decision/DecisionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ protected function createReviewRound(Submission $submission, int $stageId, ?int
if ($count == 0) {
$notificationMgr = new NotificationManager();
$notificationMgr->createNotification(
Application::get()->getRequest(),
null,
Notification::NOTIFICATION_TYPE_REVIEW_ROUND_STATUS,
$submission->getData('contextId'),
Expand Down
2 changes: 1 addition & 1 deletion classes/mail/mailables/EditorialReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function setOutstandingTasks(array $outstanding, array $submissions, int
$this->context->getPath(),
'workflow',
'access',
$submission->getId()
[$submission->getId()]
);

$outstandingTasks[] = '
Expand Down
4 changes: 2 additions & 2 deletions classes/notification/NotificationManagerDelegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
*
* @copydoc PKPNotificationOperationManager::createNotification()
*/
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
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
{
assert($notificationType == $this->getNotificationType() || $this->multipleTypesUpdate());
return parent::createNotification($request, $userId, $notificationType, $contextId, $assocType, $assocId, $level, $params);
return parent::createNotification($userId, $notificationType, $contextId, $assocType, $assocId, $level, $params);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/notification/PKPNotificationOperationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function getParamsForCurrentLocale(array $params): array
/**
* Create a new notification with the specified arguments and insert into DB
*/
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
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
{
if ($userId && in_array($notificationType, $this->getUserBlockedNotifications($userId, $contextId))) {
return null;
Expand Down Expand Up @@ -228,7 +228,7 @@ public function formatToGeneralNotification(PKPRequest $request, array $notifica
*/
public function formatToInPlaceNotification(PKPRequest $request, array $notifications): array
{
$formattedNotificationsData = null;
$formattedNotificationsData = [];

$templateMgr = TemplateManager::getManager($request);
foreach ($notifications as $notification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function getStyleClass($notification): string
public function notify(User $user): ?Notification
{
return parent::createNotification(
Application::get()->getRequest(),
$user->getId(),
Notification::NOTIFICATION_TYPE_NEW_ANNOUNCEMENT,
$this->_announcement->getAssocId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
} elseif (!$editorAssigned && !$notification) {
// Create a notification.
$this->createNotification(
$request,
null,
$this->getNotificationType(),
$context->getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
// got here from the editor decision which sends its own email.
foreach ((array) $userIds as $userId) {
$this->createNotification(
$request,
$userId,
$this->getNotificationType(),
$request->getContext()->getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public function getStyleClass(Notification $notification): string
public function notify(User $user): ?Notification
{
return parent::createNotification(
$this->_request,
$user->getId(),
Notification::NOTIFICATION_TYPE_EDITORIAL_REPORT,
$this->_context->getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
if (!$notification && $isPublished == $forPublicationState) {
// Create notification.
$this->createNotification(
$request,
null,
$type,
$submission->getData('contextId'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
if ($notificationType == Notification::NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS) {
// Add 'awaiting representations' notification
$this->_createNotification(
$request,
$submissionId,
$editorStageAssignment->userId,
$notificationType,
Expand All @@ -145,7 +144,6 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
if ($notificationType == Notification::NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER) {
// Add 'assign a user' notification
$this->_createNotification(
$request,
$submissionId,
$editorStageAssignment->userId,
$notificationType,
Expand All @@ -170,7 +168,6 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
if ($notificationType == Notification::NOTIFICATION_TYPE_AWAITING_COPYEDITS) {
// Add 'awaiting copyedits' notification
$this->_createNotification(
$request,
$submissionId,
$editorStageAssignment->userId,
$notificationType,
Expand All @@ -184,7 +181,6 @@ public function updateNotification(PKPRequest $request, ?array $userIds, int $as
if ($notificationType == Notification::NOTIFICATION_TYPE_ASSIGN_COPYEDITOR) {
// Add 'assign a copyeditor' notification
$this->_createNotification(
$request,
$submissionId,
$editorStageAssignment->userId,
$notificationType,
Expand Down Expand Up @@ -219,7 +215,7 @@ public function _removeNotification(int $submissionId, int $userId, int $notific
/**
* Create a notification if none exists.
*/
public function _createNotification(PKPRequest $request, int $submissionId, int $userId, int $notificationType, ?int $contextId): void
public function _createNotification(int $submissionId, int $userId, int $notificationType, ?int $contextId): void
{
$notification = Notification::withAssoc(Application::ASSOC_TYPE_SUBMISSION, $submissionId)
->withUserId($userId)
Expand All @@ -229,7 +225,6 @@ public function _createNotification(PKPRequest $request, int $submissionId, int
if (!$notification) {
$notificationMgr = new NotificationManager();
$notificationMgr->createNotification(
$request,
$userId,
$notificationType,
$contextId,
Expand Down
1 change: 0 additions & 1 deletion classes/observers/listeners/AssignEditors.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function handle(SubmissionSubmitted $event)

// Send notification
$notification = $notificationManager->createNotification(
Application::get()->getRequest(),
$manager->getId(),
Notification::NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_REQUIRED,
$event->context->getId(),
Expand Down
1 change: 0 additions & 1 deletion classes/query/QueryDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ public function addQuery(int $submissionId, int $stageId, string $title, string

foreach ($participantUserIds as $participantUserId) {
$notificationMgr->createNotification(
Application::get()->getRequest(),
$participantUserId,
Notification::NOTIFICATION_TYPE_NEW_QUERY,
$contextId,
Expand Down
1 change: 0 additions & 1 deletion classes/submission/action/EditorAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public function addReviewer($request, $submission, $reviewerId, &$reviewRound, $
// Add notification
$notificationMgr = new NotificationManager();
$notificationMgr->createNotification(
$request,
$reviewerId,
Notification::NOTIFICATION_TYPE_REVIEW_ASSIGNMENT,
$submission->getData('contextId'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public function execute(...$functionParams)

// Notify editors
$notification = $notificationMgr->createNotification(
Application::get()->getRequest(),
$userId,
Notification::NOTIFICATION_TYPE_REVIEWER_COMMENT,
$submission->getData('contextId'),
Expand Down
1 change: 0 additions & 1 deletion controllers/grid/queries/QueriesGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ public function updateQuery($args, $request)
$user = Repo::user()->get((int) $userId);

$notification = $notificationMgr->createNotification(
$request,
$userId,
Notification::NOTIFICATION_TYPE_NEW_QUERY,
$request->getContext()->getId(),
Expand Down
1 change: 0 additions & 1 deletion controllers/grid/queries/QueryNotesGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ protected function insertedNoteNotify(Note $note): void

// Notify the user of a new query.
$notification = $notificationManager->createNotification(
$request,
$userId,
Notification::NOTIFICATION_TYPE_QUERY_ACTIVITY,
$request->getContext()->getId(),
Expand Down
1 change: 0 additions & 1 deletion controllers/grid/users/reviewer/form/EditReviewForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ public function execute(...$functionArgs)
$context = $request->getContext();

$notification = $notificationManager->createNotification(
$request,
$reviewAssignment->getReviewerId(),
Notification::NOTIFICATION_TYPE_REVIEW_ASSIGNMENT_UPDATED,
$context->getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public function sendMessage(int $userId, Submission $submission, Request $reques
// Send the email
$notificationMgr = new NotificationManager();
$notification = $notificationMgr->createNotification(
$request,
$userId,
Notification::NOTIFICATION_TYPE_NEW_QUERY,
$request->getContext()->getId(),
Expand Down Expand Up @@ -349,7 +348,6 @@ private function _addAssignmentTaskNotification($request, $type, $userId, $submi
$context = $request->getContext();
$notificationMgr = new NotificationManager();
$notificationMgr->createNotification(
$request,
$userId,
$type,
$context->getId(),
Expand Down
1 change: 0 additions & 1 deletion jobs/email/EditorialReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public function handle(): void

$notificationManager = new NotificationManager();
$notification = $notificationManager->createNotification(
Application::get()->getRequest(),
$this->editorId,
Notification::NOTIFICATION_TYPE_EDITORIAL_REMINDER,
$this->contextId
Expand Down
1 change: 0 additions & 1 deletion jobs/invitations/RemoveExpiredInvitationsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace PKP\jobs\invitations;

use APP\facades\Repo;
use PKP\invitation\models\InvitationModel;
use PKP\jobs\BaseJob;

Expand Down
1 change: 0 additions & 1 deletion jobs/notifications/StatisticsReportMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function handle()

$notificationManager = new NotificationManager();
$notification = $notificationManager->createNotification(
Application::get()->getRequest(),
$user->getId(),
Notification::NOTIFICATION_TYPE_EDITORIAL_REPORT,
$this->contextId
Expand Down
Loading