Skip to content

Commit

Permalink
#9899 added backup/restore for dao and container keys
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Sep 27, 2024
1 parent dbb8b9a commit e708ece
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 15 deletions.
13 changes: 12 additions & 1 deletion tests/PKPTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

use APP\core\Application;
use Illuminate\Support\Facades\Mail;

use APP\core\PageRouter;
use APP\core\Request;
use Mockery;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/classes/filter/FilterDAOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));

Expand Down
12 changes: 12 additions & 0 deletions tests/jobs/bulk/BulkEmailSenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:"<p>Test body</p>";s:12:"\0*\0fromEmail";s:20:"[email protected]";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
*/
Expand Down
22 changes: 22 additions & 0 deletions tests/jobs/doi/DepositContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/jobs/doi/DepositSubmissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
27 changes: 27 additions & 0 deletions tests/jobs/email/EditorialReminderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
27 changes: 24 additions & 3 deletions tests/jobs/metadata/BatchMetadataChangedJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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());
}
Expand Down
27 changes: 24 additions & 3 deletions tests/jobs/metadata/MetadataChangedJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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());
}
Expand Down
26 changes: 26 additions & 0 deletions tests/jobs/notifications/NewAnnouncementNotifyUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:"[email protected]";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
*/
Expand Down
25 changes: 25 additions & 0 deletions tests/jobs/notifications/StatisticsReportMailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
23 changes: 23 additions & 0 deletions tests/jobs/notifications/StatisticsReportNotifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/jobs/statistics/CompileContextMetricsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/jobs/statistics/CompileSubmissionMetricsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/jobs/statistics/RemoveDoubleClicksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading

0 comments on commit e708ece

Please sign in to comment.