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/statistics/CompileCounterSubmissionDailyMetricsTest.php b/tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php new file mode 100644 index 00000000000..ae780eefbe2 --- /dev/null +++ b/tests/jobs/statistics/CompileCounterSubmissionDailyMetricsTest.php @@ -0,0 +1,107 @@ +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); + + $temporaryTitleInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryTitleInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileCounterSubmissionDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleInvestigationsDAO', $temporaryTitleInvestigationsDAOMock); + + $temporaryTitleRequestsDAO = Mockery::mock(\APP\statistics\TemporaryTitleRequestsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileCounterSubmissionDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleRequestsDAO', $temporaryTitleRequestsDAO); + + $compileCounterSubmissionDailyMetricsJob->handle(); + + $this->expectNotToPerformAssertions(); + } +} diff --git a/tests/jobs/statistics/CompileCounterSubmissionInstitutionDailyMetricsTest.php b/tests/jobs/statistics/CompileCounterSubmissionInstitutionDailyMetricsTest.php new file mode 100644 index 00000000000..3b49eba0bb0 --- /dev/null +++ b/tests/jobs/statistics/CompileCounterSubmissionInstitutionDailyMetricsTest.php @@ -0,0 +1,107 @@ +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, + 'compileCounterSubmissionInstitutionDailyMetrics' => 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); + + $temporaryTitleInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryTitleInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileCounterSubmissionInstitutionDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleInvestigationsDAO', $temporaryTitleInvestigationsDAOMock); + + $temporaryTitleRequestsDAO = Mockery::mock(\APP\statistics\TemporaryTitleRequestsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileCounterSubmissionInstitutionDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleRequestsDAO', $temporaryTitleRequestsDAO); + + $compileCounterSubmissionInstitutionDailyMetricsJob->handle(); + + $this->expectNotToPerformAssertions(); + } +} diff --git a/tests/jobs/statistics/CompileSeriesMetricsTest.php b/tests/jobs/statistics/CompileSeriesMetricsTest.php new file mode 100644 index 00000000000..06291c3f553 --- /dev/null +++ b/tests/jobs/statistics/CompileSeriesMetricsTest.php @@ -0,0 +1,67 @@ +assertInstanceOf( + CompileSeriesMetrics::class, + unserialize($this->serializedJobData) + ); + } + + /** + * Ensure that a serialized job can be unserialized and executed + */ + public function testRunSerializedJob(): void + { + /** @var CompileSeriesMetrics $compileSeriesMetricsJob */ + $compileSeriesMetricsJob = unserialize($this->serializedJobData); + + $temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileSeriesMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTotalsDAO', $temporaryTotalsDAOMock); + + + $compileSeriesMetricsJob->handle(); + + $this->expectNotToPerformAssertions(); + } +} diff --git a/tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php b/tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php new file mode 100644 index 00000000000..fc2b7f9b4c6 --- /dev/null +++ b/tests/jobs/statistics/CompileSubmissionGeoDailyMetricsTest.php @@ -0,0 +1,77 @@ +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); + + $temporaryTitleInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryTitleInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileSubmissionGeoDailyMetrics' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleInvestigationsDAO', $temporaryTitleInvestigationsDAOMock); + + $compileSubmissionGeoDailyMetricsJob->handle(); + + $this->expectNotToPerformAssertions(); + } +} diff --git a/tests/jobs/statistics/CompileUniqueInvestigationsTest.php b/tests/jobs/statistics/CompileUniqueInvestigationsTest.php new file mode 100644 index 00000000000..a3579125205 --- /dev/null +++ b/tests/jobs/statistics/CompileUniqueInvestigationsTest.php @@ -0,0 +1,77 @@ +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([ + 'compileBookItemUniqueClicks' => null, + 'compileChapterItemUniqueClicks' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemInvestigationsDAO', $temporaryItemInvestigationsDAOMock); + + $temporaryTitleInvestigationsDAOock = Mockery::mock(\APP\statistics\TemporaryTitleInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileTitleUniqueClicks' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleInvestigationsDAO', $temporaryTitleInvestigationsDAOock); + + $compileUniqueInvestigationsJob->handle(); + + $this->expectNotToPerformAssertions(); + } +} diff --git a/tests/jobs/statistics/CompileUniqueRequestsTest.php b/tests/jobs/statistics/CompileUniqueRequestsTest.php new file mode 100644 index 00000000000..c9a11140c49 --- /dev/null +++ b/tests/jobs/statistics/CompileUniqueRequestsTest.php @@ -0,0 +1,77 @@ +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([ + 'compileBookItemUniqueClicks' => null, + 'compileChapterItemUniqueClicks' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryItemRequestsDAO', $temporaryItemRequestsDAOMock); + + $temporaryTitleRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryTitleRequestsDAO::class) + ->makePartial() + ->shouldReceive([ + 'compileTitleUniqueClicks' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleRequestsDAO', $temporaryTitleRequestsDAOMock); + + $compileUniqueRequestsJob->handle(); + + $this->expectNotToPerformAssertions(); + } +} diff --git a/tests/jobs/statistics/DeleteUsageStatsTemporaryRecordsTest.php b/tests/jobs/statistics/DeleteUsageStatsTemporaryRecordsTest.php new file mode 100644 index 00000000000..6948e6fc249 --- /dev/null +++ b/tests/jobs/statistics/DeleteUsageStatsTemporaryRecordsTest.php @@ -0,0 +1,116 @@ +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); + + $temporaryTitleInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryTitleInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleInvestigationsDAO', $temporaryTitleInvestigationsDAOMock); + + $temporaryTitleRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryTitleRequestsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleRequestsDAO', $temporaryTitleRequestsDAOMock); + + $temporaryInstitutionsDAOMock = Mockery::mock(\PKP\statistics\TemporaryInstitutionsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryInstitutionsDAO', $temporaryInstitutionsDAOMock); + + $deleteUsageStatsTemporaryRecordsJob->handle(); + + $this->expectNotToPerformAssertions(); + } +} diff --git a/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php new file mode 100644 index 00000000000..7f7d24fd8c2 --- /dev/null +++ b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php @@ -0,0 +1,160 @@ +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'); + + $temporaryInstitutionsDAOMock = Mockery::mock(\PKP\statistics\TemporaryInstitutionsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + 'insert' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryInstitutionsDAO', $temporaryInstitutionsDAOMock); + + $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); + + $temporaryTitleInvestigationsDAOMock = Mockery::mock(\APP\statistics\TemporaryTitleInvestigationsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + 'insert' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleInvestigationsDAO', $temporaryTitleInvestigationsDAOMock); + + $temporaryTitleRequestsDAOMock = Mockery::mock(\APP\statistics\TemporaryTitleRequestsDAO::class) + ->makePartial() + ->shouldReceive([ + 'deleteByLoadId' => null, + 'insert' => null, + ]) + ->withAnyArgs() + ->getMock(); + + DAORegistry::registerDAO('TemporaryTitleRequestsDAO', $temporaryTitleRequestsDAOMock); + + $processUsageStatsLogFileJob->handle(); + + if ($dummyFile) { + unlink($dummyFile); + } + + $this->expectNotToPerformAssertions(); + } + + /** + * 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; + } +}