diff --git a/lib/pkp b/lib/pkp index 1c05e0eb67..0dd0ff4ac2 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit 1c05e0eb67e847a19114b3b0069adb6f83e7cf59 +Subproject commit 0dd0ff4ac20b70359039dddae6f551aae888e6e0 diff --git a/tests/jobs/.gitkeep b/tests/jobs/.gitkeep deleted file mode 100644 index ca99fa2374..0000000000 --- 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/statistics/CompileCounterSubmissionDailyMetricsTest.php b/tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php new file mode 100644 index 0000000000..ad6baec2fb --- /dev/null +++ b/tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php @@ -0,0 +1,87 @@ +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 0000000000..c8ef10c4bb --- /dev/null +++ b/tests/jobs/statistics/CompileCounterSubmissionInstitutionDailyMetricsTest.php @@ -0,0 +1,87 @@ +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/CompileSubmissionGeoDailyMetricsTest.php b/tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php new file mode 100644 index 0000000000..16dc6f7674 --- /dev/null +++ b/tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php @@ -0,0 +1,76 @@ +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 0000000000..a5ee31b90a --- /dev/null +++ b/tests/jobs/statistics/CompileUniqueInvestigationsTest.php @@ -0,0 +1,65 @@ +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 0000000000..c24717ae0f --- /dev/null +++ b/tests/jobs/statistics/CompileUniqueRequestsTest.php @@ -0,0 +1,65 @@ +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 0000000000..90e8201bed --- /dev/null +++ b/tests/jobs/statistics/DeleteUsageStatsTemporaryRecordsTest.php @@ -0,0 +1,95 @@ +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 0000000000..67072daf56 --- /dev/null +++ b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php @@ -0,0 +1,137 @@ +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; + } +}