diff --git a/tests/PKPTestCase.php b/tests/PKPTestCase.php index 1dc5318b045..8c069cceb47 100644 --- a/tests/PKPTestCase.php +++ b/tests/PKPTestCase.php @@ -22,7 +22,6 @@ use APP\core\Application; use Illuminate\Support\Facades\Mail; - use APP\core\PageRouter; use APP\core\Request; use Mockery; @@ -257,6 +256,18 @@ protected function localeToRegExp(string $translation): string return '/^' . implode('.*?', $escapedPieces) . '$/u'; } + /** + * Get the app specific search dao based on application name + */ + protected function getAppSearchDaoKey(): string + { + return match(Application::get()->getName()) { + 'ojs2' => 'ArticleSearchDAO', + 'omp' => 'MonographSearchDAO', + 'ops' => 'PreprintSearchDAO', + }; + } + /** * Mock the mail facade * @see https://laravel.com/docs/10.x/mocking diff --git a/tests/classes/filter/FilterDAOTest.php b/tests/classes/filter/FilterDAOTest.php index d1a7c1c3fd5..da0f8b7970b 100644 --- a/tests/classes/filter/FilterDAOTest.php +++ b/tests/classes/filter/FilterDAOTest.php @@ -19,6 +19,7 @@ namespace PKP\tests\classes\filter; use PKP\db\DAORegistry; +use PKP\filter\PersistableFilter; use PKP\filter\FilterDAO; use PKP\filter\FilterGroup; use PKP\filter\FilterGroupDAO; @@ -48,7 +49,8 @@ protected function setUp(): void $someGroup->setInputType('primitive::string'); $someGroup->setOutputType('primitive::string'); $filterGroupDao = DAORegistry::getDAO('FilterGroupDAO'); /** @var FilterGroupDAO $filterGroupDao */ - self::assertTrue(is_integer($filterGroupId = $filterGroupDao->insertObject($someGroup))); + $filterGroupId = $filterGroupDao->insertObject($someGroup); + self::assertTrue(is_integer($filterGroupId)); } /** @@ -61,7 +63,7 @@ public function testFilterCrud() // Install a test filter object. $settings = ['seq' => '1', 'some-key' => 'some-value']; $testFilter = $filterDao->configureObject(PersistableTestFilter::class, 'test-filter-group', $settings, false, 1); - self::assertInstanceOf('PersistableFilter', $testFilter); + self::assertInstanceOf(PersistableFilter::class, $testFilter); $filterId = $testFilter->getId(); self::assertTrue(is_integer($filterId)); diff --git a/tests/jobs/bulk/BulkEmailSenderTest.php b/tests/jobs/bulk/BulkEmailSenderTest.php index fa8232688d9..0aa81e12c40 100644 --- a/tests/jobs/bulk/BulkEmailSenderTest.php +++ b/tests/jobs/bulk/BulkEmailSenderTest.php @@ -32,6 +32,18 @@ class BulkEmailSenderTest extends PKPTestCase O:29:"PKP\\jobs\\bulk\BulkEmailSender":9:{s:10:"\0*\0userIds";a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}s:12:"\0*\0contextId";i:1;s:10:"\0*\0subject";s:12:"Test subject";s:7:"\0*\0body";s:16:"

Test body

";s:12:"\0*\0fromEmail";s:20:"rvaca@mailinator.com";s:11:"\0*\0fromName";s:11:"Ramiro Vaca";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";s:7:"batchId";s:36:"9c1cbc05-017b-4a02-bd5a-b113c92a7735";} END; + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + UserCollector::class, + UserRepository::class, + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/doi/DepositContextTest.php b/tests/jobs/doi/DepositContextTest.php index 1a2823ad096..13d51f14fa1 100644 --- a/tests/jobs/doi/DepositContextTest.php +++ b/tests/jobs/doi/DepositContextTest.php @@ -34,6 +34,28 @@ class DepositContextTest extends PKPTestCase O:27:"PKP\\jobs\\doi\\DepositContext":3:{s:12:"\0*\0contextId";i:1;s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return array_filter([ + ...parent::getMockedDAOs(), + substr(strrchr(get_class(Application::getContextDAO()), '\\'), 1), + ]); + } + + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + DoiRepository::class, + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/doi/DepositSubmissionTest.php b/tests/jobs/doi/DepositSubmissionTest.php index 3987168d3cf..02668c1f9e5 100644 --- a/tests/jobs/doi/DepositSubmissionTest.php +++ b/tests/jobs/doi/DepositSubmissionTest.php @@ -56,6 +56,18 @@ protected function setUp(): void } } + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + SubmissionRepository::class, + DoiRepository::class, + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/email/EditorialReminderTest.php b/tests/jobs/email/EditorialReminderTest.php index e7940afd748..db93c376425 100644 --- a/tests/jobs/email/EditorialReminderTest.php +++ b/tests/jobs/email/EditorialReminderTest.php @@ -37,6 +37,33 @@ class EditorialReminderTest extends PKPTestCase O:32:"PKP\\jobs\\email\\EditorialReminder":4:{s:11:"\0*\0editorId";i:2;s:12:"\0*\0contextId";i:1;s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return [ + ...parent::getMockedDAOs(), + 'NotificationSubscriptionSettingsDAO', + 'ReviewRoundDAO', + 'NotificationDAO', + 'NotificationSettingsDAO', + ]; + } + + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + UserRepository::class, + SubmissionCollector::class, + SubmissionRepository::class, + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/metadata/BatchMetadataChangedJobTest.php b/tests/jobs/metadata/BatchMetadataChangedJobTest.php index 472037fd4da..59ab4e80f15 100644 --- a/tests/jobs/metadata/BatchMetadataChangedJobTest.php +++ b/tests/jobs/metadata/BatchMetadataChangedJobTest.php @@ -14,6 +14,7 @@ use Mockery; use PKP\db\DAORegistry; +use APP\core\Application; use PKP\tests\PKPTestCase; use PKP\jobs\metadata\BatchMetadataChangedJob; use APP\submission\Repository as SubmissionRepository; @@ -32,6 +33,28 @@ class BatchMetadataChangedJobTest extends PKPTestCase O:41:"PKP\\jobs\\metadata\\BatchMetadataChangedJob":3:{s:13:"submissionIds";a:2:{i:0;i:1;i:1;i:2;}s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return [ + ...parent::getMockedDAOs(), + $this->getAppSearchDaoKey(), + ]; + } + + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + SubmissionRepository::class, + ]; + } + /** * Test job is a proper instance */ @@ -99,9 +122,7 @@ public function testRunSerializedJob(): void ->withAnyArgs() ->getMock(); - DAORegistry::registerDAO('ArticleSearchDAO', $submissionSearchDAOMock); // for OJS - DAORegistry::registerDAO('MonographSearchDAO', $submissionSearchDAOMock); // for OMP - DAORegistry::registerDAO('PreprintSearchDAO', $submissionSearchDAOMock); // for OPS + DAORegistry::registerDAO($this->getAppSearchDaoKey(), $submissionSearchDAOMock); $this->assertNull($batchMetadataChangedJob->handle()); } diff --git a/tests/jobs/metadata/MetadataChangedJobTest.php b/tests/jobs/metadata/MetadataChangedJobTest.php index 8112b08e92e..ec8cfca067f 100644 --- a/tests/jobs/metadata/MetadataChangedJobTest.php +++ b/tests/jobs/metadata/MetadataChangedJobTest.php @@ -14,6 +14,7 @@ use Mockery; use PKP\db\DAORegistry; +use APP\core\Application; use PKP\tests\PKPTestCase; use PKP\jobs\metadata\MetadataChangedJob; use APP\submission\Repository as SubmissionRepository; @@ -32,6 +33,28 @@ class MetadataChangedJobTest extends PKPTestCase O:36:"PKP\\jobs\\metadata\\MetadataChangedJob":3:{s:15:"\0*\0submissionId";i:24;s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return [ + ...parent::getMockedDAOs(), + $this->getAppSearchDaoKey(), + ]; + } + + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + SubmissionRepository::class, + ]; + } + /** * Test job is a proper instance */ @@ -99,9 +122,7 @@ public function testRunSerializedJob(): void ->withAnyArgs() ->getMock(); - DAORegistry::registerDAO('ArticleSearchDAO', $submissionSearchDAOMock); // for OJS - DAORegistry::registerDAO('MonographSearchDAO', $submissionSearchDAOMock); // for OMP - DAORegistry::registerDAO('PreprintSearchDAO', $submissionSearchDAOMock); // for OPS + DAORegistry::registerDAO($this->getAppSearchDaoKey(), $submissionSearchDAOMock); $this->assertNull($metadataChangedJob->handle()); } diff --git a/tests/jobs/notifications/NewAnnouncementNotifyUsersTest.php b/tests/jobs/notifications/NewAnnouncementNotifyUsersTest.php index f68a1b7a5c9..0d6dd424bdd 100644 --- a/tests/jobs/notifications/NewAnnouncementNotifyUsersTest.php +++ b/tests/jobs/notifications/NewAnnouncementNotifyUsersTest.php @@ -35,6 +35,32 @@ class NewAnnouncementNotifyUsersTest extends PKPTestCase O:49:"PKP\\jobs\\notifications\\NewAnnouncementNotifyUsers":7:{s:15:"\0*\0recipientIds";O:29:"Illuminate\Support\Collection":2:{s:8:"\0*\0items";a:3:{i:0;i:2;i:1;i:3;i:2;i:4;}s:28:"\0*\0escapeWhenCastingToString";b:0;}s:12:"\0*\0contextId";i:1;s:17:"\0*\0announcementId";i:1;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";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return array_filter([ + ...parent::getMockedDAOs(), + substr(strrchr(get_class(Application::getContextDAO()), '\\'), 1), + 'NotificationDAO', + 'NotificationSettingsDAO', + ]); + } + + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + AnnouncementRepository::class, + EmailTemplateRepository::class, + UserRepository::class, + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/notifications/StatisticsReportMailTest.php b/tests/jobs/notifications/StatisticsReportMailTest.php index 5d9790bc8af..173c6918b02 100644 --- a/tests/jobs/notifications/StatisticsReportMailTest.php +++ b/tests/jobs/notifications/StatisticsReportMailTest.php @@ -34,6 +34,31 @@ class StatisticsReportMailTest extends PKPTestCase O:43:"PKP\\jobs\\notifications\\StatisticsReportMail":6:{s:10:"\0*\0userIds";O:29:"Illuminate\Support\Collection":2:{s:8:"\0*\0items";a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:6;}s:28:"\0*\0escapeWhenCastingToString";b:0;}s:12:"\0*\0contextId";i:1;s:12:"\0*\0dateStart";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2024-05-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:10:"Asia/Dhaka";}s:10:"\0*\0dateEnd";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2024-06-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:10:"Asia/Dhaka";}s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return array_filter([ + ...parent::getMockedDAOs(), + substr(strrchr(get_class(Application::getContextDAO()), '\\'), 1), + 'NotificationDAO', + 'NotificationSettingsDAO', + ]); + } + + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + EmailTemplateRepository::class, + UserRepository::class, + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/notifications/StatisticsReportNotifyTest.php b/tests/jobs/notifications/StatisticsReportNotifyTest.php index dea72c0c112..60843414bfe 100644 --- a/tests/jobs/notifications/StatisticsReportNotifyTest.php +++ b/tests/jobs/notifications/StatisticsReportNotifyTest.php @@ -49,6 +49,29 @@ protected function getSerializedJobData(): string }; } + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return [ + ...parent::getMockedDAOs(), + 'NotificationDAO', + 'NotificationSettingsDAO', + ]; + } + + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + UserRepository::class, + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/statistics/CompileContextMetricsTest.php b/tests/jobs/statistics/CompileContextMetricsTest.php index 32fa89dde1c..7b774e8c094 100644 --- a/tests/jobs/statistics/CompileContextMetricsTest.php +++ b/tests/jobs/statistics/CompileContextMetricsTest.php @@ -31,6 +31,17 @@ class CompileContextMetricsTest extends PKPTestCase O:41:"PKP\\jobs\\statistics\\CompileContextMetrics":3:{s:9:"\0*\0loadId";s:25:"usage_events_20240130.log";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return [ + ...parent::getMockedDAOs(), + 'TemporaryTotalsDAO', + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/statistics/CompileSubmissionMetricsTest.php b/tests/jobs/statistics/CompileSubmissionMetricsTest.php index 6691ff84d6b..6046f9fd282 100644 --- a/tests/jobs/statistics/CompileSubmissionMetricsTest.php +++ b/tests/jobs/statistics/CompileSubmissionMetricsTest.php @@ -31,6 +31,17 @@ class CompileSubmissionMetricsTest extends PKPTestCase O:44:"PKP\\jobs\\statistics\\CompileSubmissionMetrics":3:{s:9:"\0*\0loadId";s:25:"usage_events_20240130.log";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return [ + ...parent::getMockedDAOs(), + 'TemporaryTotalsDAO', + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/statistics/RemoveDoubleClicksTest.php b/tests/jobs/statistics/RemoveDoubleClicksTest.php index 944d9ecee40..5b71d8cb0d8 100644 --- a/tests/jobs/statistics/RemoveDoubleClicksTest.php +++ b/tests/jobs/statistics/RemoveDoubleClicksTest.php @@ -31,6 +31,17 @@ class RemoveDoubleClicksTest extends PKPTestCase O:38:"PKP\\jobs\\statistics\\RemoveDoubleClicks":3:{s:9:"\0*\0loadId";s:25:"usage_events_20240130.log";s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return [ + ...parent::getMockedDAOs(), + 'TemporaryTotalsDAO', + ]; + } + /** * Test job is a proper instance */ diff --git a/tests/jobs/submissions/RemoveSubmissionFileFromSearchIndexJobTest.php b/tests/jobs/submissions/RemoveSubmissionFileFromSearchIndexJobTest.php index 8c523ca6027..b03d2c5610d 100644 --- a/tests/jobs/submissions/RemoveSubmissionFileFromSearchIndexJobTest.php +++ b/tests/jobs/submissions/RemoveSubmissionFileFromSearchIndexJobTest.php @@ -14,6 +14,7 @@ use Mockery; use PKP\db\DAORegistry; +use APP\core\Application; use PKP\tests\PKPTestCase; use PKP\jobs\submissions\RemoveSubmissionFileFromSearchIndexJob; @@ -31,6 +32,17 @@ class RemoveSubmissionFileFromSearchIndexJobTest extends PKPTestCase O:59:"PKP\\jobs\\submissions\\RemoveSubmissionFileFromSearchIndexJob":4:{s:15:"\0*\0submissionId";i:25;s:19:"\0*\0submissionFileId";i:55;s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return [ + ...parent::getMockedDAOs(), + $this->getAppSearchDaoKey(), + ]; + } + /** * Test job is a proper instance */ @@ -56,9 +68,7 @@ public function testRunSerializedJob(): void ->withAnyArgs() ->getMock(); - DAORegistry::registerDAO('ArticleSearchDAO', $submissionSearchDAOMock); // for OJS - DAORegistry::registerDAO('MonographSearchDAO', $submissionSearchDAOMock); // for OMP - DAORegistry::registerDAO('PreprintSearchDAO', $submissionSearchDAOMock); // for OPS + DAORegistry::registerDAO($this->getAppSearchDaoKey(), $submissionSearchDAOMock); // Test that the job can be handled without causing an exception. $this->assertNull($removeSubmissionFileFromSearchIndexJob->handle()); diff --git a/tests/jobs/submissions/RemoveSubmissionFromSearchIndexJobTest.php b/tests/jobs/submissions/RemoveSubmissionFromSearchIndexJobTest.php index 7f236ebae29..4a7925594c9 100644 --- a/tests/jobs/submissions/RemoveSubmissionFromSearchIndexJobTest.php +++ b/tests/jobs/submissions/RemoveSubmissionFromSearchIndexJobTest.php @@ -14,6 +14,7 @@ use Mockery; use PKP\db\DAORegistry; +use APP\core\Application; use PKP\tests\PKPTestCase; use PKP\jobs\submissions\RemoveSubmissionFromSearchIndexJob; @@ -31,6 +32,17 @@ class RemoveSubmissionFromSearchIndexJobTest extends PKPTestCase O:55:"PKP\\jobs\\submissions\\RemoveSubmissionFromSearchIndexJob":3:{s:15:"\0*\0submissionId";i:26;s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedDAOs() + */ + protected function getMockedDAOs(): array + { + return [ + ...parent::getMockedDAOs(), + $this->getAppSearchDaoKey(), + ]; + } + /** * Test job is a proper instance */ @@ -56,9 +68,7 @@ public function testRunSerializedJob(): void ->withAnyArgs() ->getMock(); - DAORegistry::registerDAO('ArticleSearchDAO', $submissionSearchDAOMock); // for OJS - DAORegistry::registerDAO('MonographSearchDAO', $submissionSearchDAOMock); // for OMP - DAORegistry::registerDAO('PreprintSearchDAO', $submissionSearchDAOMock); // for OPS + DAORegistry::registerDAO($this->getAppSearchDaoKey(), $submissionSearchDAOMock); // Test that the job can be handled without causing an exception. $this->assertNull($removeSubmissionFromSearchIndexJob->handle()); diff --git a/tests/jobs/submissions/UpdateSubmissionSearchJobTest.php b/tests/jobs/submissions/UpdateSubmissionSearchJobTest.php index 11915bd032b..ad627aaee2b 100644 --- a/tests/jobs/submissions/UpdateSubmissionSearchJobTest.php +++ b/tests/jobs/submissions/UpdateSubmissionSearchJobTest.php @@ -30,6 +30,17 @@ class UpdateSubmissionSearchJobTest extends PKPTestCase O:46:"PKP\jobs\submissions\UpdateSubmissionSearchJob":3:{s:15:"\0*\0submissionId";i:1;s:10:"connection";s:8:"database";s:5:"queue";s:5:"queue";} END; + /** + * @see PKPTestCase::getMockedContainerKeys() + */ + protected function getMockedContainerKeys(): array + { + return [ + ...parent::getMockedContainerKeys(), + \APP\submission\Repository::class, + ]; + } + /** * Test job is a proper instance */