From 16d520ffad3a85ea2fbebda5e94807b4a78e84cd Mon Sep 17 00:00:00 2001 From: Fabian Helfer Date: Wed, 20 Nov 2024 10:03:17 +0100 Subject: [PATCH] Test --- .../tests/ilCertificateCronTest.php | 557 ------------------ 1 file changed, 557 deletions(-) delete mode 100755 components/ILIAS/Certificate/tests/ilCertificateCronTest.php diff --git a/components/ILIAS/Certificate/tests/ilCertificateCronTest.php b/components/ILIAS/Certificate/tests/ilCertificateCronTest.php deleted file mode 100755 index 1d538ee0df50..000000000000 --- a/components/ILIAS/Certificate/tests/ilCertificateCronTest.php +++ /dev/null @@ -1,557 +0,0 @@ - - */ -class ilCertificateCronTest extends ilCertificateBaseTestCase -{ - public function testGetTitle(): void - { - $queueRepository = $this->getMockBuilder(ilCertificateQueueRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock(); - - $userRepository = $this->getMockBuilder(ilUserCertificateRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $valueReplacement = $this->getMockBuilder(ilCertificateValueReplacement::class) - ->disableOriginalConstructor() - ->getMock(); - - $logger = $this->getMockBuilder(ilLogger::class) - ->disableOriginalConstructor() - ->getMock(); - - $languageMock = $this->getMockBuilder(ilLanguage::class) - ->disableOriginalConstructor() - ->getMock(); - - $languageMock - ->expects($this->atLeastOnce()) - ->method('txt') - ->willReturn('SomeTitle'); - - $dic = $this->getMockBuilder(\ILIAS\DI\Container::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic->method('language') - ->willReturn($languageMock); - - $configValues = ['lng']; - - $dic - ->method('offsetGet') - ->willReturnCallback(static function ($key) use ($configValues): string { - return $configValues[$key]; - }); - - $dic['lng'] = $languageMock; - - $cron = new ilCertificateCron( - $queueRepository, - $templateRepository, - $userRepository, - $valueReplacement, - $logger, - $dic, - $languageMock - ); - - $title = $cron->getTitle(); - - $this->assertSame('SomeTitle', $title); - } - - public function testGetDescription(): void - { - $queueRepository = $this->getMockBuilder(ilCertificateQueueRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock(); - - $userRepository = $this->getMockBuilder(ilUserCertificateRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $valueReplacement = $this->getMockBuilder(ilCertificateValueReplacement::class) - ->disableOriginalConstructor() - ->getMock(); - - $logger = $this->getMockBuilder(ilLogger::class) - ->disableOriginalConstructor() - ->getMock(); - - $languageMock = $this->getMockBuilder(ilLanguage::class) - ->disableOriginalConstructor() - ->getMock(); - - $languageMock - ->expects($this->atLeastOnce()) - ->method('txt') - ->willReturn('SomeDescription'); - - $dic = $this->getMockBuilder(\ILIAS\DI\Container::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic->method('language') - ->willReturn($languageMock); - - $configValues = ['lng']; - - $dic - ->method('offsetGet') - ->willReturnCallback(static function ($key) use ($configValues): string { - return $configValues[$key]; - }); - - $dic['lng'] = $languageMock; - - $cron = new ilCertificateCron( - $queueRepository, - $templateRepository, - $userRepository, - $valueReplacement, - $logger, - $dic, - $languageMock - ); - - $title = $cron->getDescription(); - - $this->assertSame('SomeDescription', $title); - } - - public function testGetId(): void - { - $database = $this->createMock(ilDBInterface::class); - - $queueRepository = $this->getMockBuilder(ilCertificateQueueRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock(); - - $userRepository = $this->getMockBuilder(ilUserCertificateRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $valueReplacement = $this->getMockBuilder(ilCertificateValueReplacement::class) - ->disableOriginalConstructor() - ->getMock(); - - $logger = $this->getMockBuilder(ilLogger::class) - ->disableOriginalConstructor() - ->getMock(); - - $languageMock = $this->getMockBuilder(ilLanguage::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic = $this->getMockBuilder(\ILIAS\DI\Container::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic->method('language') - ->willReturn($languageMock); - - $dic->method('database') - ->willReturn($database); - - $configValues = ['lng']; - - $dic - ->method('offsetGet') - ->willReturnCallback(static function ($key) use ($configValues): string { - return $configValues[$key]; - }); - - $dic['lng'] = $languageMock; - - $objectMock = $this->getMockBuilder(ilObject::class) - ->disableOriginalConstructor() - ->getMock(); - - $userMock = $this->getMockBuilder(ilObjUser::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper->method('getInstanceByObjId') - ->willReturnOnConsecutiveCalls( - $objectMock, - $userMock - ); - - $cron = new ilCertificateCron( - $queueRepository, - $templateRepository, - $userRepository, - $valueReplacement, - $logger, - $dic, - $languageMock, - $objectHelper - ); - - $id = $cron->getId(); - - $this->assertSame('certificate', $id); - } - - public function testActivation(): void - { - $database = $this->getMockBuilder(ilDBInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $queueRepository = $this->getMockBuilder(ilCertificateQueueRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock(); - - $userRepository = $this->getMockBuilder(ilUserCertificateRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $valueReplacement = $this->getMockBuilder(ilCertificateValueReplacement::class) - ->disableOriginalConstructor() - ->getMock(); - - $logger = $this->getMockBuilder(ilLogger::class) - ->disableOriginalConstructor() - ->getMock(); - - $languageMock = $this->getMockBuilder(ilLanguage::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic = $this->getMockBuilder(\ILIAS\DI\Container::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic->method('language') - ->willReturn($languageMock); - - $dic->method('database') - ->willReturn($database); - - $configValues = ['lng']; - - $dic - ->method('offsetGet') - ->willReturnCallback(static function ($key) use ($configValues): string { - return $configValues[$key]; - }); - - $dic['lng'] = $languageMock; - - $objectMock = $this->getMockBuilder(ilObject::class) - ->disableOriginalConstructor() - ->getMock(); - - $userMock = $this->getMockBuilder(ilObjUser::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper->method('getInstanceByObjId') - ->willReturnOnConsecutiveCalls( - $objectMock, - $userMock - ); - - $cron = new ilCertificateCron( - $queueRepository, - $templateRepository, - $userRepository, - $valueReplacement, - $logger, - $dic, - $languageMock, - $objectHelper - ); - - $activation = $cron->hasAutoActivation(); - - $this->assertTrue($activation); - } - - public function testFlexibleActivation(): void - { - $database = $this->getMockBuilder(ilDBInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $queueRepository = $this->getMockBuilder(ilCertificateQueueRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock(); - - $userRepository = $this->getMockBuilder(ilUserCertificateRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $valueReplacement = $this->getMockBuilder(ilCertificateValueReplacement::class) - ->disableOriginalConstructor() - ->getMock(); - - $logger = $this->getMockBuilder(ilLogger::class) - ->disableOriginalConstructor() - ->getMock(); - - $languageMock = $this->getMockBuilder(ilLanguage::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic = $this->getMockBuilder(\ILIAS\DI\Container::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic->method('language') - ->willReturn($languageMock); - - $dic->method('database') - ->willReturn($database); - - $configValues = ['lng']; - - $dic - ->method('offsetGet') - ->willReturnCallback(static function ($key) use ($configValues): string { - return $configValues[$key]; - }); - - $dic['lng'] = $languageMock; - - $objectMock = $this->getMockBuilder(ilObject::class) - ->disableOriginalConstructor() - ->getMock(); - - $userMock = $this->getMockBuilder(ilObjUser::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper->method('getInstanceByObjId') - ->willReturnOnConsecutiveCalls( - $objectMock, - $userMock - ); - - $cron = new ilCertificateCron( - $queueRepository, - $templateRepository, - $userRepository, - $valueReplacement, - $logger, - $dic, - $languageMock, - $objectHelper - ); - - $flexibleSchedule = $cron->hasFlexibleSchedule(); - - $this->assertTrue($flexibleSchedule); - } - - public function testGetDefaultScheduleType(): void - { - $database = $this->getMockBuilder(ilDBInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $queueRepository = $this->getMockBuilder(ilCertificateQueueRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock(); - - $userRepository = $this->getMockBuilder(ilUserCertificateRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $valueReplacement = $this->getMockBuilder(ilCertificateValueReplacement::class) - ->disableOriginalConstructor() - ->getMock(); - - $logger = $this->getMockBuilder(ilLogger::class) - ->disableOriginalConstructor() - ->getMock(); - - $languageMock = $this->getMockBuilder(ilLanguage::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic = $this->getMockBuilder(\ILIAS\DI\Container::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic->method('language') - ->willReturn($languageMock); - - $dic->method('database') - ->willReturn($database); - - $configValues = ['lng']; - - $dic - ->method('offsetGet') - ->willReturnCallback(static function ($key) use ($configValues): string { - return $configValues[$key]; - }); - - $dic['lng'] = $languageMock; - - $objectMock = $this->getMockBuilder(ilObject::class) - ->disableOriginalConstructor() - ->getMock(); - - $userMock = $this->getMockBuilder(ilObjUser::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper->method('getInstanceByObjId') - ->willReturnOnConsecutiveCalls( - $objectMock, - $userMock - ); - - $cron = new ilCertificateCron( - $queueRepository, - $templateRepository, - $userRepository, - $valueReplacement, - $logger, - $dic, - $languageMock, - $objectHelper - ); - - $flexibleSchedule = $cron->getDefaultScheduleType(); - - $this->assertSame(CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES, $flexibleSchedule); - } - - public function testGetDefaultScheduleValue(): void - { - $database = $this->getMockBuilder(ilDBInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $queueRepository = $this->getMockBuilder(ilCertificateQueueRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock(); - - $userRepository = $this->getMockBuilder(ilUserCertificateRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $valueReplacement = $this->getMockBuilder(ilCertificateValueReplacement::class) - ->disableOriginalConstructor() - ->getMock(); - - $logger = $this->getMockBuilder(ilLogger::class) - ->disableOriginalConstructor() - ->getMock(); - - $languageMock = $this->getMockBuilder(ilLanguage::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic = $this->getMockBuilder(\ILIAS\DI\Container::class) - ->disableOriginalConstructor() - ->getMock(); - - $dic->method('language') - ->willReturn($languageMock); - - $dic->method('database') - ->willReturn($database); - - $configValues = ['lng']; - - $dic - ->method('offsetGet') - ->willReturnCallback(static function ($key) use ($configValues): string { - return $configValues[$key]; - }); - - $dic['lng'] = $languageMock; - - $objectMock = $this->getMockBuilder(ilObject::class) - ->disableOriginalConstructor() - ->getMock(); - - $userMock = $this->getMockBuilder(ilObjUser::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class) - ->disableOriginalConstructor() - ->getMock(); - - $objectHelper->method('getInstanceByObjId') - ->willReturnOnConsecutiveCalls( - $objectMock, - $userMock - ); - - $cron = new ilCertificateCron( - $queueRepository, - $templateRepository, - $userRepository, - $valueReplacement, - $logger, - $dic, - $languageMock, - $objectHelper - ); - - $scheduleValue = $cron->getDefaultScheduleValue(); - - $this->assertSame(1, $scheduleValue); - } -}