diff --git a/jobs/notifications/IssuePublishedNotifyUsers.php b/jobs/notifications/IssuePublishedNotifyUsers.php index 1b80bf76290..5b209d50012 100644 --- a/jobs/notifications/IssuePublishedNotifyUsers.php +++ b/jobs/notifications/IssuePublishedNotifyUsers.php @@ -99,7 +99,7 @@ protected function createMailable( Issue $issue, User $recipient, EmailTemplate $template, - Notification $notification + Notification|\PKP\notification\Notification $notification ): IssuePublishedNotify { $mailable = new IssuePublishedNotify($context, $issue); $mailable diff --git a/tests/jobs/.gitkeep b/tests/jobs/.gitkeep deleted file mode 100644 index ca99fa2374b..00000000000 --- a/tests/jobs/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Placeholder while we have no tests here so git will check out the directory -- keeps phpunit from complaining diff --git a/tests/jobs/doi/DepositIssueTest.php b/tests/jobs/doi/DepositIssueTest.php new file mode 100644 index 00000000000..30badee50cb --- /dev/null +++ b/tests/jobs/doi/DepositIssueTest.php @@ -0,0 +1,105 @@ +

This is an automated message from Journal of Public Knowledge.

";s:19:"enableAnnouncements";b:1;s:15:"enabledDoiTypes";a:2:{i:0;s:11:"publication";i:1;s:5:"issue";}s:10:"enableDois";b:1;s:19:"enableGeoUsageStats";s:8:"disabled";s:27:"enableInstitutionUsageStats";b:0;s:9:"enableOai";b:1;s:16:"isSushiApiPublic";b:1;s:12:"itemsPerPage";i:25;s:8:"keywords";s:7:"request";s:14:"mailingAddress";s:49:"123 456th Street Burnaby, British Columbia Canada";s:13:"membershipFee";d:0;s:16:"notifyAllAuthors";b:1;s:12:"numPageLinks";i:10;s:19:"numWeeksPerResponse";i:4;s:17:"numWeeksPerReview";i:4;s:10:"onlineIssn";s:9:"0378-5955";s:17:"paymentPluginName";s:13:"PaypalPayment";s:15:"paymentsEnabled";b:1;s:9:"printIssn";s:9:"0378-5955";s:14:"publicationFee";d:0;s:20:"publisherInstitution";s:24:"Public Knowledge Project";s:18:"purchaseArticleFee";d:0;s:18:"registrationAgency";s:14:"dataciteplugin";s:25:"submissionAcknowledgement";s:10:"allAuthors";s:20:"submitWithCategories";b:0;s:20:"supportedFormLocales";a:2:{i:0;s:2:"en";i:1;s:5:"fr_CA";}s:16:"supportedLocales";a:2:{i:0;s:2:"en";i:1;s:5:"fr_CA";}s:26:"supportedSubmissionLocales";a:2:{i:0;s:2:"en";i:1;s:5:"fr_CA";}s:12:"supportEmail";s:20:"rvaca@mailinator.com";s:11:"supportName";s:11:"Ramiro Vaca";s:15:"themePluginPath";s:7:"default";s:12:"abbreviation";a:1:{s:2:"en";s:25:"publicknowledgeJ Pub Know";}s:7:"acronym";a:1:{s:2:"en";s:6:"JPKJPK";}s:16:"authorGuidelines";a:2:{s:2:"en";s:1209:"

Authors are invited to make a submission to this journal. All submissions will be assessed by an editor to determine whether they meet the aims and scope of this journal. Those considered to be a good fit will be sent for peer review before determining whether they will be accepted or rejected.

Before making a submission, authors are responsible for obtaining permission to publish any material included with the submission, such as photos, documents and datasets. All authors identified on the submission must consent to be identified as an author. Where appropriate, research should be approved by an appropriate ethics committee in accordance with the legal requirements of the study's country.

An editor may desk reject a submission if it does not meet minimum standards of quality. Before submitting, please ensure that the study design and research argument are structured and articulated properly. The title should be concise and the abstract should be able to stand on its own. This will increase the likelihood of reviewers agreeing to review the paper. When you're satisfied that your submission meets this standard, please follow the checklist below to prepare your submission.

";s:5:"fr_CA";s:44:"##default.contextSettings.authorGuidelines##";}s:17:"authorInformation";a:2:{s:2:"en";s:586:"Interested in submitting to this journal? We recommend that you review the About the Journal page for the journal's section policies, as well as the Author Guidelines. Authors need to register with the journal prior to submitting or, if already registered, can simply log in and begin the five-step process.";s:5:"fr_CA";s:715:"Intéressé-e à soumettre à cette revue ? Nous vous recommandons de consulter les politiques de rubrique de la revue à la page À propos de la revue ainsi que les Directives aux auteurs. Les auteurs-es doivent s'inscrire auprès de la revue avant de présenter une soumission, ou s'ils et elles sont déjà inscrits-es, simplement ouvrir une session et accéder au tableau de bord pour commencer les 5 étapes du processus.";}s:19:"beginSubmissionHelp";a:2:{s:2:"en";s:611:"

Thank you for submitting to the Journal of Public Knowledge. You will be asked to upload files, identify co-authors, and provide information such as the title and abstract.

Please read our Submission Guidelines if you have not done so already. When filling out the forms, provide as many details as possible in order to help our editors evaluate your work.

Once you begin, you can save your submission and come back to it later. You will be able to review and correct any information before you submit.

";s:5:"fr_CA";s:42:"##default.submission.step.beforeYouBegin##";}s:14:"clockssLicense";a:2:{s:2:"en";s:271:"This journal utilizes the CLOCKSS system to create a distributed archiving system among participating libraries and permits those libraries to create permanent archives of the journal for purposes of preservation and restoration. More...";s:5:"fr_CA";s:315:"Cette revue utilise le système CLOCKSS pour créer un système d'archivage distribué parmi les bibliothèques participantes et permet à ces bibliothèques de créer des archives permanentes de la revue à des fins de conservation et de reconstitution. En apprendre davantage... ";}s:16:"contributorsHelp";a:2:{s:2:"en";s:504:"

Add details for all of the contributors to this submission. Contributors added here will be sent an email confirmation of the submission, as well as a copy of all editorial decisions recorded against this submission.

If a contributor can not be contacted by email, because they must remain anonymous or do not have an email account, please do not enter a fake email address. You can add information about this contributor in a message to the editor at a later step in the submission process.

";s:5:"fr_CA";s:40:"##default.submission.step.contributors##";}s:13:"customHeaders";a:1:{s:2:"en";s:41:"";}s:11:"description";a:2:{s:2:"en";s:123:"

The Journal of Public Knowledge is a peer-reviewed quarterly publication on the subject of public access to science.

";s:5:"fr_CA";s:146:"

Le Journal de Public Knowledge est une publication trimestrielle évaluée par les pairs sur le thème de l'accès du public à la science.

";}s:11:"detailsHelp";a:2:{s:2:"en";s:92:"

Please provide the following details to help us manage your submission in our system.

";s:5:"fr_CA";s:35:"##default.submission.step.details##";}s:17:"forTheEditorsHelp";a:2:{s:2:"en";s:278:"

Please provide the following details in order to help our editorial team manage your submission.

When entering metadata, provide entries that you think would be most helpful to the person managing your submission. This information can be changed before publication.

";s:5:"fr_CA";s:41:"##default.submission.step.forTheEditors##";}s:20:"librarianInformation";a:2:{s:2:"en";s:361:"We encourage research librarians to list this journal among their library's electronic journal holdings. As well, it may be worth noting that this journal's open source publishing system is suitable for libraries to host for their faculty members to use with journals they are involved in editing (see Open Journal Systems).";s:5:"fr_CA";s:434:"Nous incitons les bibliothécaires à lister cette revue dans leur fonds de revues numériques. Aussi, il peut être pertinent de mentionner que ce système de publication en libre accès est conçu pour être hébergé par les bibliothèques de recherche pour que les membres de leurs facultés l'utilisent avec les revues dans lesquelles elles ou ils sont impliqués (voir Open Journal Systems).";}s:13:"lockssLicense";a:2:{s:2:"en";s:273:"This journal utilizes the LOCKSS system to create a distributed archiving system among participating libraries and permits those libraries to create permanent archives of the journal for purposes of preservation and restoration. More...";s:5:"fr_CA";s:314:"Cette revue utilise le système LOCKSS pour créer un système de distribution des archives parmi les bibliothèques participantes et afin de permettre à ces bibliothèques de créer des archives permanentes pour fins de préservation et de restauration. En apprendre davantage...";}s:4:"name";a:2:{s:2:"en";s:27:"Journal of Public Knowledge";s:5:"fr_CA";s:36:"Journal de la connaissance du public";}s:16:"openAccessPolicy";a:2:{s:2:"en";s:176:"This journal provides immediate open access to its content on the principle that making research freely available to the public supports a greater global exchange of knowledge.";s:5:"fr_CA";s:217:"Cette revue fournit le libre accès immédiat à son contenu se basant sur le principe que rendre la recherche disponible au public gratuitement facilite un plus grand échange du savoir, à l'échelle de la planète.";}s:16:"privacyStatement";a:2:{s:2:"en";s:206:"

The names and email addresses entered in this journal site will be used exclusively for the stated purposes of this journal and will not be made available for any other purpose or to any other party.

";s:5:"fr_CA";s:193:"

Les noms et courriels saisis dans le site de cette revue seront utilisés exclusivement aux fins indiquées par cette revue et ne serviront à aucune autre fin, ni à toute autre partie.

";}s:17:"readerInformation";a:2:{s:2:"en";s:654:"We encourage readers to sign up for the publishing notification service for this journal. Use the Register link at the top of the home page for the journal. This registration will result in the reader receiving the Table of Contents by email for each new issue of the journal. This list also allows the journal to claim a certain level of support or readership. See the journal's Privacy Statement, which assures readers that their name and email address will not be used for other purposes.";s:5:"fr_CA";s:716:"Nous invitons les lecteurs-trices à s'inscrire pour recevoir les avis de publication de cette revue. Utiliser le lien S'inscrire en haut de la page d'accueil de la revue. Cette inscription permettra au,à la lecteur-trice de recevoir par courriel le sommaire de chaque nouveau numéro de la revue. Cette liste permet aussi à la revue de revendiquer un certain niveau de soutien ou de lectorat. Voir la Déclaration de confidentialité de la revue qui certifie aux lecteurs-trices que leur nom et leur courriel ne seront pas utilisés à d'autres fins.";}s:10:"reviewHelp";a:2:{s:2:"en";s:368:"

Review the information you have entered before you complete your submission. You can change any of the details displayed here by clicking the edit button at the top of each section.

Once you complete your submission, a member of our editorial team will be assigned to review it. Please ensure the details you have entered here are as accurate as possible.

";s:5:"fr_CA";s:34:"##default.submission.step.review##";}s:17:"searchDescription";a:1:{s:2:"en";s:116:"The Journal of Public Knowledge is a peer-reviewed quarterly publication on the subject of public access to science.";}s:19:"submissionChecklist";a:2:{s:2:"en";s:591:"

All submissions must meet the following requirements.

";s:5:"fr_CA";s:37:"##default.contextSettings.checklist##";}s:15:"uploadFilesHelp";a:2:{s:2:"en";s:249:"

Provide any files our editorial team may need to evaluate your submission. In addition to the main work, you may wish to submit data sets, conflict of interest statements, or other supplementary files if these will be helpful for our editors.

";s:5:"fr_CA";s:39:"##default.submission.step.uploadFiles##";}}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*\0agency";O:43:"APP\\plugins\\generic\\datacite\\DatacitePlugin":4:{s:10:"pluginPath";s:24:"plugins/generic/datacite";s:14:"pluginCategory";s:7:"generic";s:7:"request";N;s:58:"\0APP\\plugins\\generic\\datacite\\DatacitePlugin\0_exportPlugin";N;}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( + DepositIssue::class, + unserialize($this->serializedJobData) + ); + } + + /** + * Ensure that a serialized job can be unserialized and executed + */ + public function testRunSerializedJob(): void + { + // need to mock request so that a valid context information is set and can be retrived + $this->mockRequest(); + + $this->mockGuzzleClient(); + + /** @var DepositIssue $depositIssueJob */ + $depositIssueJob = unserialize($this->serializedJobData); + + $issueMock = Mockery::mock(\APP\issue\Issue::class) + ->makePartial() + ->shouldReceive([ + 'getId' => 0, + 'getDatePublished' => \Carbon\Carbon::today() + ->startOfYear() + ->format('Y-m-d H:i:s'), + 'getStoredPubId' => '10.1234/mq45t6723', + ]) + ->shouldReceive('getData') + ->with('doiObject') + ->andReturn(new \PKP\doi\Doi()) + ->getMock(); + + $issueDaoMock = Mockery::mock(\APP\issue\DAO::class, [ + new \PKP\services\PKPSchemaService() + ]) + ->makePartial() + ->shouldReceive([ + 'fromRow' => $issueMock + ]) + ->withAnyArgs() + ->getMock(); + + $issueRepoMock = Mockery::mock(app(IssueRepository::class)) + ->makePartial() + ->shouldReceive([ + 'get' => $issueMock, + ]) + ->withAnyArgs() + ->set('dao', $issueDaoMock) + ->getMock(); + + app()->instance(IssueRepository::class, $issueRepoMock); + + $doiRepoMock = Mockery::mock(app(DoiRepository::class)) + ->makePartial() + ->shouldReceive([ + 'edit' + ]) + ->withAnyArgs() + ->getMock(); + + app()->instance(DoiRepository::class, $doiRepoMock); + + $this->assertNull($depositIssueJob->handle()); + } +} diff --git a/tests/jobs/notifications/IssuePublishedNotifyUsersTest.php b/tests/jobs/notifications/IssuePublishedNotifyUsersTest.php new file mode 100644 index 00000000000..61128fbe6db --- /dev/null +++ b/tests/jobs/notifications/IssuePublishedNotifyUsersTest.php @@ -0,0 +1,87 @@ +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)); + + $journalDAOMock = Mockery::mock(\APP\journal\JournalDAO::class) + ->makePartial() + ->shouldReceive('getId') + ->withAnyArgs() + ->andReturn(new \APP\journal\JournalDAO()) + ->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); + + $this->assertNull($issuePublishedNotifyUsersJob->handle()); + } +} diff --git a/tests/jobs/notifications/OpenAccessMailUsersTest.php b/tests/jobs/notifications/OpenAccessMailUsersTest.php new file mode 100644 index 00000000000..256d6f9c243 --- /dev/null +++ b/tests/jobs/notifications/OpenAccessMailUsersTest.php @@ -0,0 +1,107 @@ +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); + + $journalDAOMock = Mockery::mock(\APP\journal\JournalDAO::class) + ->makePartial() + ->shouldReceive('getId') + ->withAnyArgs() + ->andReturn( + Mockery::mock(\APP\journal\Journal::class) + ->makePartial() + ->shouldReceive([ + 'getData' => '', + 'getPrimaryLocale' => 'en' + ]) + ->withAnyArgs() + ->getMock() + ) + ->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); + + $this->assertNull($openAccessMailUsersJob->handle()); + } +} diff --git a/tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php b/tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php new file mode 100644 index 00000000000..f12409a6821 --- /dev/null +++ b/tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php @@ -0,0 +1,86 @@ +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); + + + $this->assertNull($compileCounterSubmissionDailyMetricsJob->handle()); + } +} diff --git a/tests/jobs/statistics/CompileCounterSubmissionInstitutionDailyMetricsTest.php b/tests/jobs/statistics/CompileCounterSubmissionInstitutionDailyMetricsTest.php new file mode 100644 index 00000000000..fdf2434f5cf --- /dev/null +++ b/tests/jobs/statistics/CompileCounterSubmissionInstitutionDailyMetricsTest.php @@ -0,0 +1,86 @@ +assertInstanceOf( + CompileCounterSubmissionInstitutionDailyMetrics::class, + unserialize($this->serializedJobData) + ); + } + + /** + * Ensure that a serialized job can be unserialized and executed + */ + public function testRunSerializedJob(): void + { + /** @var CompileCounterSubmissionInstitutionDailyMetrics $compileCounterSubmissionInstitutionDailyMetricsJob */ + $compileCounterSubmissionInstitutionDailyMetricsJob = unserialize($this->serializedJobData); + + $temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteCounterSubmissionInstitutionDailyByLoadId' => null, + 'compileCounterSubmissionDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock); + + $temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileCounterSubmissionInstitutionDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); + + $temporaryItemRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemRequestsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileCounterSubmissionInstitutionDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemRequestsDAO', $temporaryItemRequestsDAOMock); + + + $this->assertNull($compileCounterSubmissionInstitutionDailyMetricsJob->handle()); + } +} diff --git a/tests/jobs/statistics/CompileIssueMetricsTest.php b/tests/jobs/statistics/CompileIssueMetricsTest.php new file mode 100644 index 00000000000..43083bee761 --- /dev/null +++ b/tests/jobs/statistics/CompileIssueMetricsTest.php @@ -0,0 +1,64 @@ +assertInstanceOf( + CompileIssueMetrics::class, + unserialize($this->serializedJobData) + ); + } + + /** + * Ensure that a serialized job can be unserialized and executed + */ + public function testRunSerializedJob(): void + { + /** @var CompileIssueMetrics $compileIssueMetricsJob */ + $compileIssueMetricsJob = unserialize($this->serializedJobData); + + $temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileIssueMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock); + + $this->assertNull($compileIssueMetricsJob->handle()); + } +} diff --git a/tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php b/tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php new file mode 100644 index 00000000000..2491e79afbb --- /dev/null +++ b/tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php @@ -0,0 +1,75 @@ +assertInstanceOf( + CompileSubmissionGeoDailyMetrics::class, + unserialize($this->serializedJobData) + ); + } + + /** + * Ensure that a serialized job can be unserialized and executed + */ + public function testRunSerializedJob(): void + { + /** @var CompileSubmissionGeoDailyMetrics $compileSubmissionGeoDailyMetricsJob */ + $compileSubmissionGeoDailyMetricsJob = unserialize($this->serializedJobData); + + $temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteSubmissionGeoDailyByLoadId' => null, + 'compileSubmissionGeoDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock); + + $temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileSubmissionGeoDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); + + $this->assertNull($compileSubmissionGeoDailyMetricsJob->handle()); + } +} diff --git a/tests/jobs/statistics/CompileUniqueInvestigationsTest.php b/tests/jobs/statistics/CompileUniqueInvestigationsTest.php new file mode 100644 index 00000000000..18848851e07 --- /dev/null +++ b/tests/jobs/statistics/CompileUniqueInvestigationsTest.php @@ -0,0 +1,64 @@ +assertInstanceOf( + CompileUniqueInvestigations::class, + unserialize($this->serializedJobData) + ); + } + + /** + * Ensure that a serialized job can be unserialized and executed + */ + public function testRunSerializedJob(): void + { + /** @var CompileUniqueInvestigations $compileUniqueInvestigationsJob */ + $compileUniqueInvestigationsJob = unserialize($this->serializedJobData); + + $temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileUniqueClicks' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); + + $this->assertNull($compileUniqueInvestigationsJob->handle()); + } +} diff --git a/tests/jobs/statistics/CompileUniqueRequestsTest.php b/tests/jobs/statistics/CompileUniqueRequestsTest.php new file mode 100644 index 00000000000..1fd3433e516 --- /dev/null +++ b/tests/jobs/statistics/CompileUniqueRequestsTest.php @@ -0,0 +1,64 @@ +assertInstanceOf( + CompileUniqueRequests::class, + unserialize($this->serializedJobData) + ); + } + + /** + * Ensure that a serialized job can be unserialized and executed + */ + public function testRunSerializedJob(): void + { + /** @var CompileUniqueRequests $compileUniqueRequestsJob */ + $compileUniqueRequestsJob = unserialize($this->serializedJobData); + + $temporaryItemRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemRequestsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileUniqueClicks' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemRequestsDAO', $temporaryItemRequestsDAOMock); + + $this->assertNull($compileUniqueRequestsJob->handle()); + } +} diff --git a/tests/jobs/statistics/DeleteUsageStatsTemporaryRecordsTest.php b/tests/jobs/statistics/DeleteUsageStatsTemporaryRecordsTest.php new file mode 100644 index 00000000000..ba26faaecc1 --- /dev/null +++ b/tests/jobs/statistics/DeleteUsageStatsTemporaryRecordsTest.php @@ -0,0 +1,94 @@ +assertInstanceOf( + DeleteUsageStatsTemporaryRecords::class, + unserialize($this->serializedJobData) + ); + } + + /** + * Ensure that a serialized job can be unserialized and executed + */ + public function testRunSerializedJob(): void + { + /** @var DeleteUsageStatsTemporaryRecords $deleteUsageStatsTemporaryRecordsJob */ + $deleteUsageStatsTemporaryRecordsJob = unserialize($this->serializedJobData); + + $temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock); + + $temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); + + $temporaryItemRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemRequestsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemRequestsDAO', $temporaryItemRequestsDAOMock); + + $temporaryInstitutionsDAOMock = Mockery::mock(\PKP\statistics\TemporaryInstitutionsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryInstitutionsDAO', $temporaryInstitutionsDAOMock); + + $this->assertNull($deleteUsageStatsTemporaryRecordsJob->handle()); + } +} diff --git a/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php new file mode 100644 index 00000000000..ef65b67327e --- /dev/null +++ b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php @@ -0,0 +1,136 @@ +assertInstanceOf( + ProcessUsageStatsLogFile::class, + unserialize($this->serializedJobData) + ); + } + + /** + * Ensure that a serialized job can be unserialized and executed + */ + public function testRunSerializedJob(): void + { + /** @var ProcessUsageStatsLogFile $processUsageStatsLogFileJob */ + $processUsageStatsLogFileJob = unserialize($this->serializedJobData); + + // we need to create a dummy file if not existed as to avoid mocking PHP's built in functions + $dummyFile = $this->createDummyFileIfNeeded($processUsageStatsLogFileJob, 'loadId'); + + $temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + 'insert' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock); + + $temporaryItemInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + 'insert' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); + + $temporaryItemRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryItemRequestsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + 'insert' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemRequestsDAO', $temporaryItemRequestsDAOMock); + + $temporaryInstitutionsDAOMock = Mockery::mock(\PKP\statistics\TemporaryInstitutionsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + 'insert' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryInstitutionsDAO', $temporaryInstitutionsDAOMock); + + $this->assertNull($processUsageStatsLogFileJob->handle()); + + if ($dummyFile) { + unlink($dummyFile); + } + } + + /** + * Create the dummy file with dummy content if required + */ + protected function createDummyFileIfNeeded(ProcessUsageStatsLogFile $job, string $propertyName): ?string + { + $reflection = new ReflectionClass($job); + $property = $reflection->getProperty($propertyName); + $property->setAccessible(true); + $fileName = $property->getValue($job); + + $filePath = StatisticsHelper::getUsageStatsDirPath() + . DIRECTORY_SEPARATOR + . FileLoader::FILE_LOADER_PATH_DISPATCH + . DIRECTORY_SEPARATOR; + + if (!file_exists($filePath . $fileName)) { + file_put_contents($filePath . $fileName, $this->dummyFileContent); + return $filePath . $fileName; + } + + return null; + } +}