From 00bd4b591e4bdbea25a251a63702e4edcc66775b Mon Sep 17 00:00:00 2001 From: Fabian Helfer Date: Wed, 20 Nov 2024 10:28:15 +0100 Subject: [PATCH 1/3] Test --- components/ILIAS/Certificate/PRIVACY.md | 79 --- components/ILIAS/Certificate/README.md | 489 --------------- .../class.ilUserCertificateApiGUI.php | 98 --- .../API/Repository/UserDataRepository.php | 3 - .../class.ilObjCertificateSettingsGUI.php | 0 .../{ => Provider}/class.ilCertificateGUI.php | 0 .../ilApiUserCertificateRepositoryTest.php | 2 +- .../tests/ilCertificateCronTest.php | 557 ------------------ .../tests/ilUserCertificateApiGUITest.php | 4 +- 9 files changed, 2 insertions(+), 1230 deletions(-) delete mode 100755 components/ILIAS/Certificate/PRIVACY.md delete mode 100755 components/ILIAS/Certificate/README.md delete mode 100755 components/ILIAS/Certificate/classes/API/Download/class.ilUserCertificateApiGUI.php rename components/ILIAS/Certificate/classes/{ => Form}/class.ilObjCertificateSettingsGUI.php (100%) mode change 100755 => 100644 rename components/ILIAS/Certificate/classes/{ => Provider}/class.ilCertificateGUI.php (100%) mode change 100755 => 100644 delete mode 100755 components/ILIAS/Certificate/tests/ilCertificateCronTest.php diff --git a/components/ILIAS/Certificate/PRIVACY.md b/components/ILIAS/Certificate/PRIVACY.md deleted file mode 100755 index 8954b0773a6a..000000000000 --- a/components/ILIAS/Certificate/PRIVACY.md +++ /dev/null @@ -1,79 +0,0 @@ -# Certificate Service Privacy - -This documentation does not warrant completeness or correctness. Please report any -missing or wrong information using the [ILIAS issue tracker](https://mantis.ilias.de) -or contribute a fix via [Pull Request](docs/development/contributing.md#pull-request-to-the-repositories). - -## General Information - -- An account with "Edit Settings" permissions for "Administration > Achievements > Certificates > Settings" - can enable the "Certificate Service" globally. -- If the "Certificate Service" is globally activated then the object types - - - ILIAS/Course - - ILIAS/StudyProgramme - - ILIAS/Exercise - - ILIAS/Test - - ILIAS/ScormAicc - - ILIAS/CmiXapi - - ILIAS/LTIConsumer - - feature an additional sub-tab "Certificate" in the "Settings" tab. -- Accounts with the permission "Edit Settings" for these particular objects can configure and activate certificates. - -## Data being stored - -For each issued persisting user certificate, the ID of the user account is stored. The purpose of this ID being stored - is the identification of the certificate being presented to or exported by the respective owner of certificate. -- In addition, certificate templates may contain placeholders. -- All placeholders defined in a certificate template will be replaced by the corresponding user data and contextual - data i.e., course title or issuing date. -- The issuing of certificate and thus replacing placeholders with user data is triggered by the user who - completes an object. -- The actual replacing of placeholders is done by processing a queue. The queue holds the user ID along with the object - related data and a datetime information. Once a queue item has been processed, the record will be deleted. -- The issued certificates are immutable: They contain the user data that replaced the placeholders at the - moment of issuing. It will not change with time. - - Stored Data (if used as a placeholder in a certificate template): - - - Certificate ID (globally unique id) - - Username - - Fullname Presentation - - Firstname - - Lastname - - Title - - Salutation - - Birthday - - Institution - - Department - - Street - - City - - ZIP - - Country - - Matriculation - - User Defined Fields (if avaiable and enabled for "Certificate" in field definition) - -## Data being presented - -- The "Certificate Service" presents the certificate and the respective personal data only to the owner of the - issued certificates at "Achievements > Certificates". Owners can download a PDF document of their certificate. -- Certificates are also presented to their owner in "Achievements > Learning History", if activated. -- Certificates may be presented to other accounts in the object types listed above. Please refer to the respective - "PRIVACY.md" of those object types to see presentation of certificate data in that very object type. - For example the course object presents certificate download links in the "Member" tab to user accounts with - "Manage Member" permission. -- Furthermore, certificates are presented to users in "Administration > Achievements > Certificates" in the **Certificates** tab - if the user has **read** permission on the certificate settings. - -## Data being deleted - -- If a user account is deleted, all it's certificates will be completely deleted from the database. - There is no trash for users. - -## Data being exported - -- Certificate owners can export PDF documents of their certificates at "Achievements > Certificates". - No other exports of user related data is provided by the "Certificate Service" itself. Exports may be possible - in the object types listed above. Please refer to the respective "PRIVACY.md" files. -- Users with **read** permission on the certificate settings can export PDF documents of certificates at "Administration > Achievements > Certificates" in the **Certificates** tab. \ No newline at end of file diff --git a/components/ILIAS/Certificate/README.md b/components/ILIAS/Certificate/README.md deleted file mode 100755 index 9a77b845dc63..000000000000 --- a/components/ILIAS/Certificate/README.md +++ /dev/null @@ -1,489 +0,0 @@ -# Certificates - -Certificates are used to display the users progress of learning -in a special way. -When this feature is activated the user will be able to download -a PDF file that will prove the successful attendance to a given -Module or Service. - -This documentation can be used for developers to add the feature -for 'Certificates' to their component. - -**Table Of Contents** -* [General](#general) -* [Settings](#settings) - * [Java Server](#java-server) - * [Certificate Settings](#certificate-settings) -* [GUI](#gui) -* [Implementation for new components](#implementation-for-new-components) - * [Placeholder Description](#placeholder-description) - * [Methods](#methods) - * [Placeholder Values](#placeholder-values) - * [Methods](#methods-1) -* [Cron Job](#cron-job) - * [GUI](#gui-1) - * [Custom Certificate Settings GUI](#custom-certificate-settings-gui) - * [User Certificates Classes](#user-certificates-classes) - * [Template Certificate Classes](#template-certificate-classes) - * [Cron Queue Classes](#cron-queue-classes) - * [Actions](#actions) - * [Copy](#copy) - * [Delete](#delete) - * [Preview](#preview) - * [Events](#events) - * [updateStatus](#updatestatus) -* [API](#api) - * [UserCertificateAPI](#usercertificateapi) - * [UserDataFilter](#userdatafilter) -* [Migration](#migration) - * [Certificate Templates](#certificate-templates) - * [User Certificates](#user-certificates) - - -## General - -The certificates and the templates for the certificates will be stored -in the database. - -The content of each certificate or template will be stored in the -format: -[XSL-FO](https://en.wikipedia.org/wiki/XSL_Formatting_Objects). - -The data that is stored in the database is a projection of the current -status, which means that it MUST not be altered afterwards. -E.g. the name change of a user after achieving the certificate will **not** -automatically be **updated**. - -If the ILIAS system will be upgraded from a ILIAS version <=5.3.0 -a migration MUST be executed. -See the [migration](#migration) chapter for more information. - -Currently only the newest version of a user certificate will -be shown in the GUI. -Previous certificate are also stored in the database, -but are not displayed in the GUI. - -The user certificates can be created directly or via a cron job -with a delay. - -* Creating user certificates instantly after resolving the learning progress - of a user is only recommended for systems with low up to mediocre user workload. - Due to the fact that learning progress events can be raised for different users - and different context objects in a very short amount of time - this can lead to response delays in the GUI. -* Creating user certificates via the cron job is recommended for systems - with a high user workload. - This approach stores a reminder of the learning progress event into a - queue. - The cron job will process the queue on execution. - To avoid high latencies we recommend to execute the cron job in a - few minute schedule. - -## Settings - -The feature to create certificate templates and therefore creating -certificates MUST be activated via `Administration -> Certificates` -and the [Java Server](#java-server) must be configured. - -A default background image can be added that will be used as default -image for every certificate authority. - -Additionally, the `Learning Progress` MUST be activated for the Module/Service -to create new user certificates. - -### Java Server - -To create PDF files from the stored XSL-FO data from the database -a Java server is required to create these PDF files. - -A configuration file must be created in the menu -`Administration -> General Settings -> Server(Tab) -> Java-Server(Subtab)`. -Start the server with the configuration file and enter -the required values into the form. - -After being started the server is ready to be used -to create PDF files. - -### Certificate Settings - -The location of the settings to create the certificate template -depends on the implementing Service/Module. - -It is recommended to add the certificate settings view for the -current template under the current object in the menu `Settings` -as a sub-tab `Certificate`. - -The certificate settings for each component are very similar but -can be modified by the component itself to add new actions or fields. - -The biggest differences between all components are the placeholders -that can be used for the component certificate. -How to add these components will be described in the following chapters. - -A save of the template will be versioned in the database. -The newest version of the template that was recently saved -and has been set to `Active` -will be used to create the user certificate. - -A change to a previous version is currently not supported. - -## GUI - -The table with persisted user certificates will be displayed -in a separated tab in `Learning History`. - -The subtab `Certificate` is only visible when certificates -are activates via the [certificate settings](#certificate-settings). - -## Implementation for new components - -A new/separate case MUST be added in the following classes: -* [`ilCertificateGUIFactory::create`](classes/Gui/class.ilCertificateGUIFactory.php) -* [`ilCertificatePathFactory::create`](classes/File/Template/Path/class.ilCertificatePathFactory.php) - -A new/separate case MAY be added in the following classes: -* [`ilCertificatePdfFileNameFactory::fetchCertificateGenerator`](classes/File/Certificate/Filename/class.ilCertificatePdfFileNameFactory.php) - -Beside integrating the settings into the [GUI](#gui-1) there are two classes that -also MUST be created for the purpose of providing/resolving placeholders. - -The first class that MUST be added is a `Placeholder Description` class -which contain all the placeholders with the given descriptions. -This class is used in the settings GUI. - -The second class that MUST be implemented is a `Placeholder Values` class -which will calculate based on the user and given component the values that -should be replaced for the placeholders. - -**Important**: This class has to be appended to the map -defined in [`ilCertificateTypeClassMap`](classes/Cron/class.ilCertificateTypeClassMap.php). - -### Placeholder Description - -A `Placeholder Description` class is an implementation of -[`ilCertificatePlaceholderDescription`](classes/Placeholder/Description/interface.ilCertificatePlaceholderDescription.php). - -This class defines the description for the placeholders and -will create a HTML-View of these parameters that will be displayed in -certificate settings GUI. - -#### Methods - -This chapter will describe the default methods that MUST be defined -by a new implementation. - -```php -ilCertificatePlaceholderDescription::getPlaceholderDescriptions() -``` - -Will return a associative array with the placeholder as key and -the description as value. - -```php -ilCertificatePlaceholderDescription::createPlaceholderHtmlDescription() -``` - -The method MUST create a HTML string that can be displayed in the settings -GUI. -Templates SHOULD be used to create the HTML string. -A default template can be used which is located in -`./components/ILIAS/Certificates/default/tpl.default_description.html` - -### Placeholder Values - -A `Placeholder Values` class is an implementation of -[`ilCertificatePlaceholderValues`](classes/Placeholder/Values/interface.ilCertificatePlaceholderValues.php). - -This class is used to calculate the values for the placeholders -based on the user data and object data. - -#### Methods - -```php -ilCertificatePlaceholderValues::getPlaceholderValues($userId: integer, $objId: integer) -``` - -This method will return an associative array with the placeholder as key and the actual -data as value. -The value data will be calculated on the method call. -If the values can't be calculated or the user is not permitted to have certificate, -please throw an `ilInvalidCertificateException`. -The [cron job](#cron-job) won't create a user certificate if -this exception is thrown. - -```php -ilCertificatePlaceholderValues::getPlaceholderValuesForPreview() -``` - -This method will return example data that will be used for a preview -PDF version of the certificate. - -## Cron Job - -A component that has a successful Learning Progress status will be -added to a queue that will be processed on each execution of the -cron job. - -The cron job will create an implementation of the `Placeholder Value` class -that is provided in the queue entry to receive the values for the placeholders -and replace them in the XLS-FO content of the template. -The certificate will be stored in the database and will be listed as obtained certificate -in the [GUI](#gui). - -### GUI - -To implement a certificate settings in a GUI -an instance of `ilCertifcateGUI` MUST be used. -As seen in the constructor of this class, an instance -of `ilCertificateFormRepository` is needed. -The `ilCertificateSettingsFormRepository` can be used -for a default certificate settings interface. - -#### Custom Certificate Settings GUI - -If a custom certificate settings GUI is needed, a new Repository -class can be created. -This class MUST implement the interface `ilCertificateFormRepository` - -### User Certificates Classes - -User certificates should be stored in the data container object `ilUserCertificate`. -This container can be given the `ilUserCertificateRepository::save()` method that will -store the certificate in the defined database. - -User certificate entries will mainly be created during the cron job based -on the [certificate queue entries](#cron-queue-classes). -Each entry displays an achievement of a certificate. - -Example: - -```php -// Refers to already used certificate template -use ILIAS\Certificate\ValueObject\CertificateId;$patternCertificateId = 10; - -// Object ID of the Module/Service (e.g. Course, Test) -$objId = 200; - -// Type of the current object -$objType = 'crs'; - -// User who achieved the certificate -$userId = 3000; - -// Current name of the User -$userName = 'Ilyas Homer'; - -// Timstamp of achievement, if the time is not availble use current timstamp -$acquiredTimestamp = 1532347101; - -// The XLS-FO content, in older version this was the content of the file -$certificateContent = ' ... '; - -// Template values that have been replaced with actual user data -$templateValues = '{"USER_LOGIN": "ilyas"}'; - -// Validation date/time. For future purposes(Currently not implemented) -$validUntil = null; - -// Numeric iterative version value of the current certifcate. -$version = 1; - -// ILIAS version at the time of achievement -$iliasVersion = 'v5.4.0'; - -// Determines if the current certifcate is the newest and visible certificate -$currentlyActive = true; - -// Unique UUID for the certificate -$cert_id = new CertificateId('unique-uuid'); - -$certificate = new ilUserCertificate( - $patternCertificateId, - $objId, - $objType, - $userId, - $userName, - $acquiredTimestamp, - $certificateContent, - $templateValues, - $validUntil, - $version, - $iliasVersion, - $currentlyActive, - $cert_id -); - -$repository = new ilUserCertificateRepository($database, $logger); -$repository->save($certifcate); -``` - -### Template Certificate Classes - -Certificate templates should be stored in the data container object `ilCertificateTemplate`. -This container can be given the `ilCertificateTemplateRepository::save()` method that will -store the template in the defined database. - -These classes are used in the certificate settings GUI during creating the certificate -template. - -Example: - -```php - -$objId = 200; -$obj_type = 'crs'; -$certificateContent = '...' -$certificateHash = md5($certificateHash); -$templateValues = json_encode(array('ID' => 'DESCRIPTION')); -$version = 2; -$iliasVerion = 'v5.4.0'; -$createdTimestamp = time(); -$currentlyActive = true; -$backgroundImageIdentification = 'a_id' - -$template = new ilCertificateTemplate( - $obj_id, - $obj_type, - $certificateContent, - $certificateHash, - $templateValues, - $version, - $iliasVersion, - $createdTimestamp, - $currentlyActive, - $backgroundImageIdentification -); - -$repository = new ilCertificateTemplateDatabaseRepository($database); -$repository->save($template); -``` - -### Cron Queue Classes - -Queue entry data should be stored in the data container object `ilCertificateQueueEntry`. -This container can be given the `ilCertificateQueueRepository::save()` method that will -store the template in the defined database. - -An entry will be created on an successful LP status change. -Queue entries will later be processed by a cron job to create [user certificate](#user-certificates-classes). - -Example: - -```php - -$objId = 200; -$userId = 5000; -$adapterClass = 'CoursePlaceholderValues' -$state = ilCronConstants::IN_PROGRESS; - -$template = new ilCertificateQueueEntry( - $objId, - $userId, - $adapterClass, - $state -); - -$repository = new ilCertificateQueueRepository($database); -$repository->save($template); -``` - -### Actions - -The actions will be shown on the GUI as buttons. -Developers MAY create an specified action for -their Service/Module. - -#### Copy - -The copy action SHOULD be executed during the -copy process of an Service/Module. - -#### Delete - -The delete action will be activated via a button -in the template form. - -Custom delete action can be created by implementing -the Interface `ilCertificateDeleteAction`, -but every template form SHOULD use at least -an Implementation of `ilCertificateTemplateDeleteAction`. - -The actions will be added via `ilCertificateGUIFactory` - -#### Preview - -The preview action will create a PDF with default -values. -This default values of this action are defined in the -implementations of the -[Placeholder Values Classes](#placeholder-values). - -### Events - -The certificates using the ILIAS Event System to add new -certificates to the cron job queue. -There are a few possible events the certificate service is -listening to: - -| Event | Component | Explanation | -|------------------|--------------------|-------------------------------------------------------| -| updateStatus | ILIAS/Tracking | This event will be thrown by the Learning Progress | - -#### updateStatus - -On an update status event (performed by the Learning Progress) -a possible new user certificate will be added directly to the queue. - -If the Learning Progress is globally deactivated, the administrator -can enter particular components for Learning Progress. -The course is NOT supported for this behaviour, but components -can be added via the certificates template settings UI. -Completing all of the selected events will add the user -into the [queue](#cron-queue-classes). - -## API - -This service also provides an API to fetch data related to the certificates. -Currently, an endpoint is provided to fetch user certificate related data. - -Public API classes: -* `Certificate\API\UserCertificateAPI` - -### UserCertificateAPI - -`UserCertificateAPI::getUserCertificateData` will return an `array` of `UserCertificateDto`. - `UserCertificateDto` contains specific information of users who achieved a certificate. - The method will need an `UserDataFilter` object and an array of - `ilCtrl-enabled GUI class` names that will be used to create a link to download the certificate. - -_Attention: This API will not check if a user has access to the certificate link. -Please make sure the user using this API has every privilege to download the certificates. -This is valid for the querying purpose as well as for the certificate delivery purpose._ - -### UserDataFilter - -The `UserDataFilter` contains the elements to limit the final result set. -The first parameter MUST be an `array` of `usr_id`. - - -## Migration - -The migration was a feature in the previous ILIAS version 5.4.x, and is no -longer supported. -If the migration step is needed for your system, please install a 5.4.x version -first and let the users migrate their user certificates. - -### Certificate Templates - -Certificate templates will be imported to the database -during an database update step. - -This step **MUST** be executed before a user migrates -the achieved certificates. - -### User Certificates - -User certificates will be imported per user via a background -task. -This background task, will be executed by the user via the -[GUI](#gui). diff --git a/components/ILIAS/Certificate/classes/API/Download/class.ilUserCertificateApiGUI.php b/components/ILIAS/Certificate/classes/API/Download/class.ilUserCertificateApiGUI.php deleted file mode 100755 index d612928afb15..000000000000 --- a/components/ILIAS/Certificate/classes/API/Download/class.ilUserCertificateApiGUI.php +++ /dev/null @@ -1,98 +0,0 @@ - - */ -class ilUserCertificateApiGUI -{ - final public const CMD_DOWNLOAD = 'download'; - - private readonly ilLogger $certificateLogger; - private readonly ServerRequestInterface $request; - private readonly ilLanguage $language; - private readonly ilCtrlInterface $ctrl; - - public function __construct( - ?ilLanguage $language = null, - ?ServerRequestInterface $request = null, - ?ilLogger $certificateLogger = null, - ?ilCtrlInterface $ctrl = null - ) { - global $DIC; - - if ($language === null) { - $language = $DIC->language(); - } - $this->language = $language; - - if ($request === null) { - $request = $DIC->http()->request(); - } - $this->request = $request; - - if ($certificateLogger === null) { - $certificateLogger = $DIC->logger()->cert(); - } - $this->certificateLogger = $certificateLogger; - - if ($ctrl === null) { - $ctrl = $DIC->ctrl(); - } - $this->ctrl = $ctrl; - - $this->language->loadLanguageModule('cert'); - } - - public function executeCommand(): void - { - $cmd = $this->ctrl->getCmd(); - - switch ($cmd) { - case self::CMD_DOWNLOAD: - $this->{$cmd}(); - break; - - default: - break; - } - } - - public function download(): void - { - $userCertificateRepository = new ilUserCertificateRepository(null, $this->certificateLogger); - $pdfGenerator = new ilPdfGenerator($userCertificateRepository); - - $userCertificateId = (int) $this->request->getQueryParams()['certificate_id']; - - $userCertificate = $userCertificateRepository->fetchCertificate($userCertificateId); - - $pdfAction = new ilCertificatePdfAction( - $pdfGenerator, - new ilCertificateUtilHelper(), - $this->language->txt('error_creating_certificate_pdf') - ); - - $pdfAction->downloadPdf($userCertificate->getUserId(), $userCertificate->getObjId()); - } -} diff --git a/components/ILIAS/Certificate/classes/API/Repository/UserDataRepository.php b/components/ILIAS/Certificate/classes/API/Repository/UserDataRepository.php index f4194f2e991a..a310d657d6b5 100755 --- a/components/ILIAS/Certificate/classes/API/Repository/UserDataRepository.php +++ b/components/ILIAS/Certificate/classes/API/Repository/UserDataRepository.php @@ -92,9 +92,6 @@ public function getUserData(UserDataFilter $filter, array $ilCtrlStack): array $link = ''; if ([] !== $ilCtrlStack) { - $this->ctrl->setParameterByClass(ilUserCertificateApiGUI::class, 'certificate_id', $id); - $link = $this->ctrl->getLinkTargetByClass($ilCtrlStack, ilUserCertificateApiGUI::CMD_DOWNLOAD); - $this->ctrl->clearParametersByClass(ilUserCertificateApiGUI::class); } $dataObject = new UserCertificateDto( diff --git a/components/ILIAS/Certificate/classes/class.ilObjCertificateSettingsGUI.php b/components/ILIAS/Certificate/classes/Form/class.ilObjCertificateSettingsGUI.php old mode 100755 new mode 100644 similarity index 100% rename from components/ILIAS/Certificate/classes/class.ilObjCertificateSettingsGUI.php rename to components/ILIAS/Certificate/classes/Form/class.ilObjCertificateSettingsGUI.php diff --git a/components/ILIAS/Certificate/classes/class.ilCertificateGUI.php b/components/ILIAS/Certificate/classes/Provider/class.ilCertificateGUI.php old mode 100755 new mode 100644 similarity index 100% rename from components/ILIAS/Certificate/classes/class.ilCertificateGUI.php rename to components/ILIAS/Certificate/classes/Provider/class.ilCertificateGUI.php diff --git a/components/ILIAS/Certificate/tests/ilApiUserCertificateRepositoryTest.php b/components/ILIAS/Certificate/tests/ilApiUserCertificateRepositoryTest.php index 52e455c81b67..40d0b0d83239 100755 --- a/components/ILIAS/Certificate/tests/ilApiUserCertificateRepositoryTest.php +++ b/components/ILIAS/Certificate/tests/ilApiUserCertificateRepositoryTest.php @@ -92,6 +92,6 @@ public function testGetUserData(): void $this->assertSame('breakdanceMcFunkyPants', $object->getUserLogin()); $this->assertSame('ilyas@ilias.de', $object->getUserEmail()); $this->assertSame('breakdance@funky.de', $object->getUserSecondEmail()); - $this->assertSame('somewhere.php?goto=4', $object->getDownloadLink()); + $this->assertSame('', $object->getDownloadLink()); } } 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); - } -} diff --git a/components/ILIAS/Certificate/tests/ilUserCertificateApiGUITest.php b/components/ILIAS/Certificate/tests/ilUserCertificateApiGUITest.php index 94cea0f4636f..39c1489f563d 100755 --- a/components/ILIAS/Certificate/tests/ilUserCertificateApiGUITest.php +++ b/components/ILIAS/Certificate/tests/ilUserCertificateApiGUITest.php @@ -40,8 +40,6 @@ public function testCreationOfGuiClass(): void $controller = $this->getMockBuilder(ilCtrlInterface::class) ->disableOriginalConstructor() ->getMock(); - - $gui = new ilUserCertificateApiGUI($language, $request, $logger, $controller); - $this->assertInstanceOf(ilUserCertificateApiGUI::class, $gui); + $this->assertSame('', ''); } } From 91e221bcfc4ac8a9058f89076abc51d28892efb3 Mon Sep 17 00:00:00 2001 From: Fabian Helfer Date: Wed, 20 Nov 2024 10:40:09 +0100 Subject: [PATCH 2/3] Test --- scripts/PHP-CS-Fixer/run_check.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/PHP-CS-Fixer/run_check.sh b/scripts/PHP-CS-Fixer/run_check.sh index 1d48c01f6225..52f425cf65e7 100755 --- a/scripts/PHP-CS-Fixer/run_check.sh +++ b/scripts/PHP-CS-Fixer/run_check.sh @@ -1,4 +1,5 @@ #!/bin/bash +echo "Run PHP-CS-Fixer in refactor/" if [[ -z "${GHRUN}" ]]; then RUNCSFIXER=$(vendor/composer/vendor/bin/php-cs-fixer fix --using-cache=no --dry-run -vvv --config=./scripts/PHP-CS-Fixer/code-format.php_cs $@) From af8dcb74065373f0c02f2d6dc0991c29811db27a Mon Sep 17 00:00:00 2001 From: Fabian Helfer Date: Wed, 20 Nov 2024 10:43:25 +0100 Subject: [PATCH 3/3] Test --- scripts/Import/Functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Import/Functions.sh b/scripts/Import/Functions.sh index 9dc518f3ede3..0cae07557539 100755 --- a/scripts/Import/Functions.sh +++ b/scripts/Import/Functions.sh @@ -11,7 +11,7 @@ function get_changed_files() { CHANGED_FILES=$(git diff-tree --name-only --diff-filter=ACMRT --no-commit-id -r ${GH_SHA} | grep -e '.php$' -e '.js$') else URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files" - CHANGED_FILES=$(curl -s -X GET -G $URL | jq -r '.[] | .filename' | grep -e '\.php$' -e '\.js$') + CHANGED_FILES=$(curl -s -X GET -G $URL | jq -r '.[] | select(.status != "removed") | .filename' | grep -e '\.php$' -e '\.js$') fi printf "${CHANGED_FILES[*]}" }