From a63aa66bf2e05449d08d832143d495fd70ef7d27 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Thu, 6 Jun 2024 11:50:10 +0200 Subject: [PATCH] Keep only one directory for tests (#17257) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Keep only one directory for tests * Fix namespaces * Make the CronTask::testCronTemp() test more resilient * Remove remaining usages of the tests/unit dir * Remove unit from coverage, add codecov token --------- Co-authored-by: Cédric Anne --- .github/actions/test_tests-cache.sh | 11 - .github/actions/test_tests-units.sh | 42 -- .github/workflows/ci.yml | 4 - .github/workflows/coverage.yml | 7 +- composer.json | 1 - tests/README.md | 9 +- tests/bootstrap.php | 2 +- .../AbstractRightsDropdown.php | 0 tests/{units => functional}/Autoload.php | 0 tests/functional/CronTask.php | 52 ++ tests/{units => functional}/DB.php | 0 tests/{units => functional}/DBConnection.php | 0 .../{units => functional}/DBmysqlIterator.php | 0 tests/{units => functional}/GLPI.php | 0 tests/{units => functional}/GLPIMailer.php | 0 .../Glpi/Application/ErrorHandler.php | 0 .../Extension/FrontEndAssetsExtension.php | 0 .../Glpi/Cache/CacheManager.php | 0 .../Glpi/Cache/SimpleCache.php | 0 .../Glpi/Console/CommandLoader.php | 0 .../Glpi/ContentTemplates/TemplateManager.php | 125 ++++ .../Glpi/Csv/LogCsvExport.php | 0 tests/functional/Glpi/Dashboard/Provider.php | 555 ++++++++++++++++ .../Glpi/Dashboard/Widget.php | 0 .../Glpi/Features/Clonable.php | 0 .../Glpi/Features/Dcbreadcrumb.php | 0 .../Glpi/Http/Firewall.php | 0 .../Glpi/Http/ProxyRouter.php | 0 .../Glpi/Inventory/Conf.php | 0 .../Glpi/Inventory/Request.php | 0 .../Glpi/RichText/RichText.php | 0 .../System/Diagnostic/DatabaseKeysChecker.php | 0 .../DatabaseSchemaConsistencyChecker.php | 0 .../DatabaseSchemaIntegrityChecker.php | 0 .../DataDirectoriesProtectedPath.php | 0 .../System/Requirement/DbConfiguration.php | 0 .../Glpi/System/Requirement/DbEngine.php | 0 .../Glpi/System/Requirement/DbTimezones.php | 0 .../Requirement/DirectoriesWriteAccess.php | 0 .../Requirement/DirectoryWriteAccess.php | 0 .../Glpi/System/Requirement/Extension.php | 0 .../System/Requirement/ExtensionClass.php | 0 .../System/Requirement/ExtensionConstant.php | 0 .../System/Requirement/ExtensionFunction.php | 0 .../System/Requirement/ExtensionGroup.php | 0 .../Requirement/InstallationNotOverriden.php | 0 .../System/Requirement/LogsWriteAccess.php | 0 .../Glpi/System/Requirement/MemoryLimit.php | 0 .../Glpi/System/Requirement/MysqliMysqlnd.php | 0 .../Requirement/PhpSupportedVersion.php | 0 .../Glpi/System/Requirement/PhpVersion.php | 0 .../System/Requirement/ProtectedWebAccess.php | 0 .../Glpi/System/Requirement/SeLinux.php | 0 .../Requirement/SessionsConfiguration.php | 0 .../SessionsSecurityConfiguration.php | 0 .../Glpi/Toolbox/DataExport.php | 0 .../Glpi/Toolbox/DatabaseSchema.php | 0 .../Glpi/Toolbox/Filesystem.php | 0 .../Glpi/Toolbox/FrontEnd.php | 0 .../Glpi/Toolbox/Sanitizer.php | 0 .../Glpi/Toolbox/URL.php | 0 .../Glpi/Toolbox/VersionParser.php | 0 tests/{units => functional}/Html.php | 0 tests/{units => functional}/Migration.php | 0 tests/{units => functional}/QueryParam.php | 0 tests/{units => functional}/RuleAsset.php | 0 tests/{units => functional}/RuleRight.php | 0 tests/functional/Session.php | 35 + .../ShareDashboardDropdown.php | 0 tests/run_tests.sh | 6 - tests/units/CronTask.php | 107 ---- .../Glpi/ContentTemplates/TemplateManager.php | 168 ----- tests/units/Glpi/Dashboard/Provider.php | 603 ------------------ tests/units/Session.php | 77 --- tools/dup_tests.sh | 47 -- tools/genphpcov.sh | 55 -- 76 files changed, 775 insertions(+), 1131 deletions(-) delete mode 100755 .github/actions/test_tests-units.sh rename tests/{units => functional}/AbstractRightsDropdown.php (100%) rename tests/{units => functional}/Autoload.php (100%) rename tests/{units => functional}/DB.php (100%) rename tests/{units => functional}/DBConnection.php (100%) rename tests/{units => functional}/DBmysqlIterator.php (100%) rename tests/{units => functional}/GLPI.php (100%) rename tests/{units => functional}/GLPIMailer.php (100%) rename tests/{units => functional}/Glpi/Application/ErrorHandler.php (100%) rename tests/{units => functional}/Glpi/Application/View/Extension/FrontEndAssetsExtension.php (100%) rename tests/{units => functional}/Glpi/Cache/CacheManager.php (100%) rename tests/{units => functional}/Glpi/Cache/SimpleCache.php (100%) rename tests/{units => functional}/Glpi/Console/CommandLoader.php (100%) rename tests/{units => functional}/Glpi/Csv/LogCsvExport.php (100%) rename tests/{units => functional}/Glpi/Dashboard/Widget.php (100%) rename tests/{units => functional}/Glpi/Features/Clonable.php (100%) rename tests/{units => functional}/Glpi/Features/Dcbreadcrumb.php (100%) rename tests/{units => functional}/Glpi/Http/Firewall.php (100%) rename tests/{units => functional}/Glpi/Http/ProxyRouter.php (100%) rename tests/{units => functional}/Glpi/Inventory/Conf.php (100%) rename tests/{units => functional}/Glpi/Inventory/Request.php (100%) rename tests/{units => functional}/Glpi/RichText/RichText.php (100%) rename tests/{units => functional}/Glpi/System/Diagnostic/DatabaseKeysChecker.php (100%) rename tests/{units => functional}/Glpi/System/Diagnostic/DatabaseSchemaConsistencyChecker.php (100%) rename tests/{units => functional}/Glpi/System/Diagnostic/DatabaseSchemaIntegrityChecker.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/DataDirectoriesProtectedPath.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/DbConfiguration.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/DbEngine.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/DbTimezones.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/DirectoriesWriteAccess.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/DirectoryWriteAccess.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/Extension.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/ExtensionClass.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/ExtensionConstant.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/ExtensionFunction.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/ExtensionGroup.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/InstallationNotOverriden.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/LogsWriteAccess.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/MemoryLimit.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/MysqliMysqlnd.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/PhpSupportedVersion.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/PhpVersion.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/ProtectedWebAccess.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/SeLinux.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/SessionsConfiguration.php (100%) rename tests/{units => functional}/Glpi/System/Requirement/SessionsSecurityConfiguration.php (100%) rename tests/{units => functional}/Glpi/Toolbox/DataExport.php (100%) rename tests/{units => functional}/Glpi/Toolbox/DatabaseSchema.php (100%) rename tests/{units => functional}/Glpi/Toolbox/Filesystem.php (100%) rename tests/{units => functional}/Glpi/Toolbox/FrontEnd.php (100%) rename tests/{units => functional}/Glpi/Toolbox/Sanitizer.php (100%) rename tests/{units => functional}/Glpi/Toolbox/URL.php (100%) rename tests/{units => functional}/Glpi/Toolbox/VersionParser.php (100%) rename tests/{units => functional}/Html.php (100%) rename tests/{units => functional}/Migration.php (100%) rename tests/{units => functional}/QueryParam.php (100%) rename tests/{units => functional}/RuleAsset.php (100%) rename tests/{units => functional}/RuleRight.php (100%) rename tests/{units => functional}/ShareDashboardDropdown.php (100%) delete mode 100644 tests/units/CronTask.php delete mode 100644 tests/units/Glpi/ContentTemplates/TemplateManager.php delete mode 100644 tests/units/Glpi/Dashboard/Provider.php delete mode 100644 tests/units/Session.php delete mode 100755 tools/dup_tests.sh delete mode 100755 tools/genphpcov.sh diff --git a/.github/actions/test_tests-cache.sh b/.github/actions/test_tests-cache.sh index 3427b64e79f..239f977c195 100755 --- a/.github/actions/test_tests-cache.sh +++ b/.github/actions/test_tests-cache.sh @@ -7,17 +7,6 @@ for CONFIG in {"--use-default","--dsn=memcached://memcached","--dsn=redis://redi php bin/console cache:configure \ --config-dir=./tests/config --ansi --no-interaction \ $CONFIG - vendor/bin/atoum \ - -p 'php -d memory_limit=512M' \ - --debug \ - --force-terminal \ - --use-dot-report \ - --bootstrap-file tests/bootstrap.php \ - --fail-if-void-methods \ - --fail-if-skipped-methods \ - --no-code-coverage \ - -d tests/units \ - -t cache vendor/bin/atoum \ -p 'php -d memory_limit=512M' \ --debug \ diff --git a/.github/actions/test_tests-units.sh b/.github/actions/test_tests-units.sh deleted file mode 100755 index e6a70e53ee1..00000000000 --- a/.github/actions/test_tests-units.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -set -e -u -x -o pipefail - -ATOUM_ADDITIONNAL_OPTIONS="" -if [[ "$CODE_COVERAGE" = true ]]; then - export COVERAGE_DIR="coverage-unit" -else - ATOUM_ADDITIONNAL_OPTIONS="--no-code-coverage"; -fi - -# Get additional test arguments from -f, -d and -m options. -SCOPE="-d tests/units" -METHODS="" -while getopts ":d:f:m:" OPTNAME; do - case $OPTNAME in - d|f) - SCOPE="-${OPTNAME} ${OPTARG}" - ;; - m) - METHODS="-m ${OPTARG}" - ;; - \?) - echo "Invalid option: -$OPTARG" >&2 - exit 1 - ;; - esac -done - -vendor/bin/atoum \ - -p 'php -d memory_limit=512M' \ - --debug \ - --force-terminal \ - --use-dot-report \ - --bootstrap-file tests/bootstrap.php \ - --fail-if-void-methods \ - --fail-if-skipped-methods \ - $ATOUM_ADDITIONNAL_OPTIONS \ - --max-children-number 10 \ - $SCOPE \ - $METHODS - -unset COVERAGE_DIR diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e753ebef1fb..6a1d2113bc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,10 +170,6 @@ jobs: run: | .github/actions/init_initialize-9.5-db.sh docker compose exec -T app .github/actions/test_update-from-9.5.sh - - name: "Unit tests" - if: env.skip != 'true' - run: | - docker compose exec -T app .github/actions/test_tests-units.sh - name: "Functional tests" if: env.skip != 'true' run: | diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index eb19e2168fc..3a5aa4dc935 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -59,9 +59,6 @@ jobs: - name: "Install database" run: | docker compose exec -T app .github/actions/test_install.sh - - name: "Unit tests" - run: | - docker compose exec -T app .github/actions/test_tests-units.sh - name: "Functional tests" run: | docker compose exec -T app .github/actions/test_tests-functional.sh @@ -75,6 +72,8 @@ jobs: docker compose exec -T app .github/actions/test_tests-imap.sh - name: "Codecov" uses: "codecov/codecov-action@v4" + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - files: ./tests/coverage-unit/clover.xml,./tests/coverage-functional/clover.xml,./tests/coverage-ldap/clover.xml,./tests/coverage-imap/clover.xml + files: ./tests/coverage-functional/clover.xml,./tests/coverage-ldap/clover.xml,./tests/coverage-imap/clover.xml override_branch: ${{ matrix.branch }} diff --git a/composer.json b/composer.json index 5d73efe9540..ccec36f441b 100644 --- a/composer.json +++ b/composer.json @@ -132,7 +132,6 @@ "scripts": { "testdb": "atoum -p 'php -d memory_limit=512M' --debug --force-terminal --use-dot-report --bootstrap-file tests/bootstrap.php --no-code-coverage --max-children-number 1 -d tests/database", "testfunc": "atoum -p 'php -d memory_limit=512M' --debug --force-terminal --use-dot-report --bootstrap-file tests/bootstrap.php --no-code-coverage --max-children-number 1 -d tests/functional/", - "testunits": "atoum -p 'php -d memory_limit=512M' --debug --force-terminal --use-dot-report --bootstrap-file tests/bootstrap.php --no-code-coverage -d tests/units", "testweb": "atoum -p 'php -d memory_limit=512M' --debug --force-terminal --use-dot-report --bootstrap-file tests/bootstrap.php --no-code-coverage --max-children-number 1 -d tests/web", "testldap": "atoum -p 'php -d memory_limit=512M' --debug --force-terminal --use-dot-report --bootstrap-file tests/bootstrap.php --no-code-coverage --max-children-number 1 -d tests/LDAP", "testimap": "atoum -p 'php -d memory_limit=512M' --debug --force-terminal --use-dot-report --bootstrap-file tests/bootstrap.php --no-code-coverage --max-children-number 1 -d tests/imap", diff --git a/tests/README.md b/tests/README.md index aba9207f1ac..b9b57511e7e 100644 --- a/tests/README.md +++ b/tests/README.md @@ -49,8 +49,7 @@ Running the test suite on developpement env ------------------------------------------- There are multiple directories for tests: -- `tests/units` for unit tests; -- `tests/functional` for functional tests; +- `tests/functional` for unit and functional tests; - `tests/imap` for Mail collector tests; - `tests/LDAP` for LDAP connection tests; - `tests/web` for API tests. @@ -58,11 +57,11 @@ There are multiple directories for tests: You can choose to run tests on a whole directory, on any file, or on any \. You have to specify a bootstrap file each time: ```bash -$ atoum -bf tests/bootstrap.php -mcn 1 -d tests/units/ +$ atoum -bf tests/bootstrap.php -mcn 1 -d tests/functional/ [...] -$ atoum -bf tests/bootstrap.php -f tests/units/Html.php +$ atoum -bf tests/bootstrap.php -f tests/functional/Html.php [...] -$ atoum -bf tests/bootstrap.php -f tests/units/Html.php -m tests\units\Html::testConvDateTime +$ atoum -bf tests/bootstrap.php -f tests/functional/Html.php -m tests\units\Html::testConvDateTime ``` In `tests\units\Html::testConvDateTime`, you may need to double the backslashes (depending on the shell you use); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a6e12a7b8d4..1ba0e436b71 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -108,7 +108,7 @@ include_once __DIR__ . '/InventoryTestCase.php'; include_once __DIR__ . '/functional/CommonITILRecurrent.php'; include_once __DIR__ . '/functional/Glpi/ContentTemplates/Parameters/AbstractParameters.php'; -include_once __DIR__ . '/units/AbstractRightsDropdown.php'; +include_once __DIR__ . '/functional/AbstractRightsDropdown.php'; // check folder exists instead of class_exists('\GuzzleHttp\Client'), to prevent global includes if (file_exists(__DIR__ . '/../vendor/autoload.php') && !file_exists(__DIR__ . '/../vendor/guzzlehttp/guzzle')) { diff --git a/tests/units/AbstractRightsDropdown.php b/tests/functional/AbstractRightsDropdown.php similarity index 100% rename from tests/units/AbstractRightsDropdown.php rename to tests/functional/AbstractRightsDropdown.php diff --git a/tests/units/Autoload.php b/tests/functional/Autoload.php similarity index 100% rename from tests/units/Autoload.php rename to tests/functional/Autoload.php diff --git a/tests/functional/CronTask.php b/tests/functional/CronTask.php index aca5d113b24..995db7a1812 100644 --- a/tests/functional/CronTask.php +++ b/tests/functional/CronTask.php @@ -36,11 +36,63 @@ namespace tests\units; use DbTestCase; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; /* Test for inc/crontask.class.php */ class CronTask extends DbTestCase { + public function testCronTemp() + { + //create some files + $filenames = [ + 'recent_file.txt', + 'file1.txt', + 'file2.txt', + 'file3.txt', + 'file4.txt', + ]; + foreach ($filenames as $filename) { + $this->variable(file_put_contents(GLPI_TMP_DIR . '/' . $filename, bin2hex(random_bytes(20))))->isNotFalse(); + } + + //create auto_orient directory + if (!file_exists(GLPI_TMP_DIR . '/auto_orient/')) { + $this->boolean(mkdir(GLPI_TMP_DIR . '/auto_orient/', 0755, true))->isTrue(); + } + + $tmp_dir_iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator(GLPI_TMP_DIR, RecursiveDirectoryIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($tmp_dir_iterator as $path) { + if (basename($path) !== 'recent_file.txt') { + // change the modification date of the file to make it considered as "not recent" + $this->boolean(touch($path, time() - (HOUR_TIMESTAMP * 2)))->isTrue(); + } + } + + // launch Cron for cleaning _tmp directory + $mode = - \CronTask::MODE_EXTERNAL; // force + \CronTask::launch($mode, 5, 'temp'); + + $nb_file = $this->getFileCountRecursively(GLPI_TMP_DIR); + $this->variable($nb_file)->isEqualTo(1); // only recent_file.txt should be preserved + } + + + public function getFileCountRecursively($path) + { + + $dir = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS); + $files = new \RecursiveIteratorIterator( + $dir, + \RecursiveIteratorIterator::CHILD_FIRST + ); + return iterator_count($files); + } + protected function registerProvider() { return [ diff --git a/tests/units/DB.php b/tests/functional/DB.php similarity index 100% rename from tests/units/DB.php rename to tests/functional/DB.php diff --git a/tests/units/DBConnection.php b/tests/functional/DBConnection.php similarity index 100% rename from tests/units/DBConnection.php rename to tests/functional/DBConnection.php diff --git a/tests/units/DBmysqlIterator.php b/tests/functional/DBmysqlIterator.php similarity index 100% rename from tests/units/DBmysqlIterator.php rename to tests/functional/DBmysqlIterator.php diff --git a/tests/units/GLPI.php b/tests/functional/GLPI.php similarity index 100% rename from tests/units/GLPI.php rename to tests/functional/GLPI.php diff --git a/tests/units/GLPIMailer.php b/tests/functional/GLPIMailer.php similarity index 100% rename from tests/units/GLPIMailer.php rename to tests/functional/GLPIMailer.php diff --git a/tests/units/Glpi/Application/ErrorHandler.php b/tests/functional/Glpi/Application/ErrorHandler.php similarity index 100% rename from tests/units/Glpi/Application/ErrorHandler.php rename to tests/functional/Glpi/Application/ErrorHandler.php diff --git a/tests/units/Glpi/Application/View/Extension/FrontEndAssetsExtension.php b/tests/functional/Glpi/Application/View/Extension/FrontEndAssetsExtension.php similarity index 100% rename from tests/units/Glpi/Application/View/Extension/FrontEndAssetsExtension.php rename to tests/functional/Glpi/Application/View/Extension/FrontEndAssetsExtension.php diff --git a/tests/units/Glpi/Cache/CacheManager.php b/tests/functional/Glpi/Cache/CacheManager.php similarity index 100% rename from tests/units/Glpi/Cache/CacheManager.php rename to tests/functional/Glpi/Cache/CacheManager.php diff --git a/tests/units/Glpi/Cache/SimpleCache.php b/tests/functional/Glpi/Cache/SimpleCache.php similarity index 100% rename from tests/units/Glpi/Cache/SimpleCache.php rename to tests/functional/Glpi/Cache/SimpleCache.php diff --git a/tests/units/Glpi/Console/CommandLoader.php b/tests/functional/Glpi/Console/CommandLoader.php similarity index 100% rename from tests/units/Glpi/Console/CommandLoader.php rename to tests/functional/Glpi/Console/CommandLoader.php diff --git a/tests/functional/Glpi/ContentTemplates/TemplateManager.php b/tests/functional/Glpi/ContentTemplates/TemplateManager.php index 4a1ad75eea5..4df07985b27 100644 --- a/tests/functional/Glpi/ContentTemplates/TemplateManager.php +++ b/tests/functional/Glpi/ContentTemplates/TemplateManager.php @@ -47,6 +47,131 @@ */ class TemplateManager extends DbTestCase { + protected function testTemplatesProvider(): array + { + return [ + [ + 'content' => "{{ test_var }}", + 'params' => ['test_var' => 'test_value'], + 'expected' => "

test_value

", + ], + [ + 'content' => "Test var: {{ test_var }}", + 'params' => ['test_var' => 'test_value'], + 'expected' => "

Test var: test_value

", + ], + [ + 'content' => "Test condition: {% if test_condition == true %}TRUE{% else %}FALSE{% endif %}", + 'params' => ['test_condition' => 'true'], + 'expected' => "

Test condition: TRUE

", + ], + [ + 'content' => "Test condition: {% if test_condition == true %}TRUE{% else %}FALSE{% endif %}", + 'params' => ['test_condition' => 'false'], + 'expected' => "

Test condition: TRUE

", + ], + [ + 'content' => "Test for: {% for item in items %}{{ item }} {% else %}no items{% endfor %}", + 'params' => ['items' => ['a', 'b', 'c', 'd', 'e']], + 'expected' => "

Test for: a b c d e

", + ], + [ + 'content' => "Test for: {% for item in items %}{{ item }} {% else %}no items{% endfor %}", + 'params' => ['items' => []], + 'expected' => "

Test for: no items

", + ], + [ + 'content' => "Test forbidden tag: {% set var = 'value' %}", + 'params' => [], + 'expected' => "", + 'error' => 'Invalid twig template (Tag "set" is not allowed in "template" at line 1.)', + ], + [ + 'content' => "Test syntax error {{", + 'params' => [], + 'expected' => "", + 'error' => 'Invalid twig template syntax', + ], + [ + 'content' => '<h1>Test sanitized template</h1><hr />{{content|raw}}', + 'params' => ['content' => '

Item content

'], + 'expected' => '

Test sanitized template


Item content

', + 'error' => null, + ], + [ + 'content' => '<h1>Test sanitized template 2</h1><hr />{{content|raw}}', + 'params' => ['content' => 'Item content should not be unsanitized: <--'], + 'expected' => '

Test sanitized template 2


Item content should not be unsanitized: <--', + 'error' => null, + ], + [ + 'content' => "<p>Test sanitized template {% if count > 5 %}<b>++</b>{% endif %}</p>", + 'params' => ['count' => 25], + 'expected' => "

Test sanitized template ++

", + 'error' => null, + ], + [ + 'content' => '<h1 onclick="alert(1);">Test safe HTML2</h1><hr />{{content|raw}}', + 'params' => ['content' => 'Fill this form:'], + 'expected' => '

Test safe HTML2


Fill this form:', + 'error' => null, + ], + ]; + } + + /** + * @dataProvider testTemplatesProvider + */ + public function testRender( + string $content, + array $params, + string $expected, + ?string $error = null + ): void { + $manager = $this->newTestedInstance(); + + $html = null; + + if ($error !== null) { + $this->exception( + function () use ($manager, $content, $params, &$html) { + $html = $manager->render($content, $params); + } + ); + return; + } else { + $html = $manager->render($content, $params); + } + + $this->string($html)->isEqualTo($expected); + } + + /** + * @dataProvider testTemplatesProvider + */ + public function testValidate( + string $content, + array $params, + string $expected, + ?string $error = null + ): void { + $manager = $this->newTestedInstance(); + $err_msg = null; + $is_valid = $manager->validate($content, $err_msg); + $this->boolean($is_valid)->isEqualTo(empty($error)); + + // Handle error if neeced + if ($error !== null) { + $this->string($err_msg)->contains($error); + } + } + + public function testGetSecurityPolicy(): void + { + // Not much to test here, maybe keepk this for code coverage ? + $manager = $this->newTestedInstance(); + $this->object($manager->getSecurityPolicy())->isInstanceOf(\Twig\Sandbox\SecurityPolicy::class); + } /** * Get all possible CommonITILObject classes. * diff --git a/tests/units/Glpi/Csv/LogCsvExport.php b/tests/functional/Glpi/Csv/LogCsvExport.php similarity index 100% rename from tests/units/Glpi/Csv/LogCsvExport.php rename to tests/functional/Glpi/Csv/LogCsvExport.php diff --git a/tests/functional/Glpi/Dashboard/Provider.php b/tests/functional/Glpi/Dashboard/Provider.php index 7bcb244a6ee..d52ce224b6c 100644 --- a/tests/functional/Glpi/Dashboard/Provider.php +++ b/tests/functional/Glpi/Dashboard/Provider.php @@ -44,6 +44,561 @@ class Provider extends DbTestCase { + public function testNbTicketsByAgreementStatusAndTechnician() + { + global $DB; + + // Prepare context + $slm = new \Slm(); + $slm->add([ + 'name' => 'SLM', + ]); + + $slaTto = new \SLA(); + $slaTto->add([ + 'name' => 'sla tto', + 'type' => '1', // TTO + 'number_time' => 4, + 'definition_time' => 'hour', + 'slms_id' => $slm->getID(), + ]); + + $slaTtr = new \SLA(); + $slaTtr->add([ + 'name' => 'sla ttr', + 'type' => '0', // TTR + 'number_time' => 4, + 'definition_time' => 'hour', + 'slms_id' => $slm->getID(), + ]); + + $ticket = new \Ticket(); + $ticket->add([ + 'name' => "test dashboard card SLA / tech", + 'content' => 'foo', + '_users_id_assign' => 2, // glpi + 'sla_id_tto' => $slaTto->getID(), + 'sla_id_ttr' => $slaTtr->getID(), + 'status' => \Ticket::ASSIGNED, + ]); + $this->boolean($ticket->isNewItem())->isFalse(); + + $ticket2 = new \Ticket(); + $ticket2->add([ + 'name' => "test dashboard card SLA / tech", + 'content' => 'foo', + '_users_id_assign' => 4, // tech + 'sla_id_tto' => $slaTto->getID(), + 'sla_id_ttr' => $slaTtr->getID(), + 'status' => \Ticket::ASSIGNED, + ]); + $this->boolean($ticket2->isNewItem())->isFalse(); + + $ticket3 = new \Ticket(); + $ticket3->add([ + 'name' => "test dashboard card SLA / tech", + 'content' => 'foo', + '_users_id_assign' => 4, // tech + 'sla_id_tto' => $slaTto->getID(), + 'sla_id_ttr' => $slaTtr->getID(), + 'status' => \Ticket::ASSIGNED, + ]); + $this->boolean($ticket3->isNewItem())->isFalse(); + + $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnician(); + $expected = [ + 'label' => "Tickets by SLA status and by technician", + 'data' => [ + 'labels' => ['tech', 'glpi'], + 'series' => [ + [ + 'name' => 'Late own and resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late own', + 'data' => [0, 0] + ], + [ + 'name' => 'On time', + 'data' => [2, 1] + ] + ] + ], + 'icon' => 'fas fa-stopwatch' + ]; + $this->array($output)->isEqualTo($expected); + + $DB->update( + $ticket::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + ], + [ + 'id' => $ticket->getID() + ] + ); + $DB->update( + $ticket2::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + ], + [ + 'id' => $ticket2->getID() + ] + ); + $ticket->getFromDB($ticket->getID()); + $ticket2->getFromDB($ticket2->getID()); + + $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnician(); + $expected = [ + 'label' => "Tickets by SLA status and by technician", + 'data' => [ + 'labels' => ['glpi', 'tech'], + 'series' => [ + [ + 'name' => 'Late own and resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late own', + 'data' => [1, 1] + ], + [ + 'name' => 'On time', + 'data' => [0, 1] + ] + ] + ], + 'icon' => 'fas fa-stopwatch' + ]; + $this->array($output)->isEqualTo($expected); + + $DB->update( + $ticket::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 60, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket->getID() + ] + ); + $DB->update( + $ticket2::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 60, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket2->getID() + ] + ); + $ticket->getFromDB($ticket->getID()); + $ticket2->getFromDB($ticket2->getID()); + $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnician(); + $expected = [ + 'label' => "Tickets by SLA status and by technician", + 'data' => [ + 'labels' => ['glpi', 'tech'], + 'series' => [ + [ + 'name' => 'Late own and resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late resolve', + 'data' => [1, 1] + ], + [ + 'name' => 'Late own', + 'data' => [0, 0] + ], + [ + 'name' => 'On time', + 'data' => [0, 1] + ] + ] + ], + 'icon' => 'fas fa-stopwatch' + ]; + $this->array($output)->isEqualTo($expected); + + $DB->update( + $ticket::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket->getID() + ] + ); + $DB->update( + $ticket2::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket2->getID() + ] + ); + $DB->update( + $ticket3::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket3->getID() + ] + ); + $ticket->getFromDB($ticket->getID()); + $ticket2->getFromDB($ticket2->getID()); + $ticket3->getFromDB($ticket3->getID()); + $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnician(); + $expected = [ + 'label' => "Tickets by SLA status and by technician", + 'data' => [ + 'labels' => ['tech', 'glpi'], + 'series' => [ + [ + 'name' => 'Late own and resolve', + 'data' => [2, 1] + ], + [ + 'name' => 'Late resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late own', + 'data' => [0, 0] + ], + [ + 'name' => 'On time', + 'data' => [0, 0] + ] + ] + ], + 'icon' => 'fas fa-stopwatch' + ]; + $this->array($output)->isEqualTo($expected); + } + + + public function testNbTicketsByAgreementStatusAndTechnicianGroup() + { + global $DB; + + // Prepare context + $slm = new \Slm(); + $slm->add([ + 'name' => 'SLM', + ]); + + $slaTto = new \SLA(); + $slaTto->add([ + 'name' => 'sla tto', + 'type' => '1', // TTO + 'number_time' => 4, + 'definition_time' => 'hour', + 'slms_id' => $slm->getID(), + ]); + + $slaTtr = new \SLA(); + $slaTtr->add([ + 'name' => 'sla ttr', + 'type' => '0', // TTR + 'number_time' => 4, + 'definition_time' => 'hour', + 'slms_id' => $slm->getID(), + ]); + + $group = new \Group(); + $group->add([ + 'entities_id' => 0, + 'name' => 'group sla test', + 'level' => 1, + 'groups_id' => 0, + ]); + $this->boolean($group->isNewItem())->isFalse(); + + $group2 = new \Group(); + $group2->add([ + 'entities_id' => 0, + 'name' => 'second group sla test', + 'level' => 1, + 'groups_id' => 0, + ]); + $this->boolean($group2->isNewItem())->isFalse(); + + $ticket = new \Ticket(); + $ticket->add([ + 'name' => "test dashboard card SLA / tech", + 'content' => 'foo', + '_groups_id_assign' => $group->getID(), + 'sla_id_tto' => $slaTto->getID(), + 'sla_id_ttr' => $slaTtr->getID(), + 'status' => \Ticket::ASSIGNED, + ]); + $this->boolean($ticket->isNewItem())->isFalse(); + + $ticket2 = new \Ticket(); + $ticket2->add([ + 'name' => "test dashboard card SLA / tech for second group", + 'content' => 'foo', + '_groups_id_assign' => $group2->getID(), + 'sla_id_tto' => $slaTto->getID(), + 'sla_id_ttr' => $slaTtr->getID(), + 'status' => \Ticket::ASSIGNED, + ]); + $this->boolean($ticket2->isNewItem())->isFalse(); + + $ticket3 = new \Ticket(); + $ticket3->add([ + 'name' => "test dashboard card SLA / tech for second group", + 'content' => 'foo', + '_groups_id_assign' => $group2->getID(), + 'sla_id_tto' => $slaTto->getID(), + 'sla_id_ttr' => $slaTtr->getID(), + 'status' => \Ticket::ASSIGNED, + ]); + + $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnicianGroup(); + $expected = [ + 'label' => "Tickets by SLA status and by technician group", + 'data' => [ + 'labels' => ['second group sla test', 'group sla test'], + 'series' => [ + [ + 'name' => 'Late own and resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late own', + 'data' => [0, 0] + ], + [ + 'name' => 'On time', + 'data' => [2, 1] + ] + ] + ], + 'icon' => 'fas fa-stopwatch' + ]; + $this->array($output)->isEqualTo($expected); + + $DB->update( + $ticket::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + ], + [ + 'id' => $ticket->getID() + ] + ); + $DB->update( + $ticket2::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + ], + [ + 'id' => $ticket2->getID() + ] + ); + $ticket->getFromDB($ticket->getID()); + $ticket2->getFromDB($ticket2->getID()); + + $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnicianGroup(); + $expected = [ + 'label' => "Tickets by SLA status and by technician group", + 'data' => [ + 'labels' => ['group sla test', 'second group sla test'], + 'series' => [ + [ + 'name' => 'Late own and resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late own', + 'data' => [1, 1] + ], + [ + 'name' => 'On time', + 'data' => [0, 1] + ] + ] + ], + 'icon' => 'fas fa-stopwatch' + ]; + $this->array($output)->isEqualTo($expected); + + $DB->update( + $ticket::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 60, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket->getID() + ] + ); + $DB->update( + $ticket2::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 60, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket2->getID() + ] + ); + $ticket->getFromDB($ticket->getID()); + $ticket2->getFromDB($ticket2->getID()); + $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnicianGroup(); + $expected = [ + 'label' => "Tickets by SLA status and by technician group", + 'data' => [ + 'labels' => ['group sla test', 'second group sla test'], + 'series' => [ + [ + 'name' => 'Late own and resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late resolve', + 'data' => [1, 1] + ], + [ + 'name' => 'Late own', + 'data' => [0, 0] + ], + [ + 'name' => 'On time', + 'data' => [0, 1] + ] + ] + ], + 'icon' => 'fas fa-stopwatch' + ]; + $this->array($output)->isEqualTo($expected); + + $DB->update( + $ticket::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket->getID() + ] + ); + $DB->update( + $ticket2::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket2->getID() + ] + ); + $DB->update( + $ticket3::getTable(), + [ + 'date' => '2021-01-01 00:00', + 'time_to_own' => '2021-01-01 01:00', + 'takeintoaccount_delay_stat' => 50000, + 'solvedate' => '2021-02-01 00:00', + 'time_to_resolve' => '2021-01-02 00:00' + ], + [ + 'id' => $ticket3->getID() + ] + ); + $ticket->getFromDB($ticket->getID()); + $ticket2->getFromDB($ticket2->getID()); + $ticket3->getFromDB($ticket3->getID()); + $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnicianGroup(); + $expected = [ + 'label' => "Tickets by SLA status and by technician group", + 'data' => [ + 'labels' => ['second group sla test', 'group sla test'], + 'series' => [ + [ + 'name' => 'Late own and resolve', + 'data' => [2, 1] + ], + [ + 'name' => 'Late resolve', + 'data' => [0, 0] + ], + [ + 'name' => 'Late own', + 'data' => [0, 0] + ], + [ + 'name' => 'On time', + 'data' => [0, 0] + ] + ] + ], + 'icon' => 'fas fa-stopwatch' + ]; + $this->array($output)->isEqualTo($expected); + } public function itemProvider() { return [ diff --git a/tests/units/Glpi/Dashboard/Widget.php b/tests/functional/Glpi/Dashboard/Widget.php similarity index 100% rename from tests/units/Glpi/Dashboard/Widget.php rename to tests/functional/Glpi/Dashboard/Widget.php diff --git a/tests/units/Glpi/Features/Clonable.php b/tests/functional/Glpi/Features/Clonable.php similarity index 100% rename from tests/units/Glpi/Features/Clonable.php rename to tests/functional/Glpi/Features/Clonable.php diff --git a/tests/units/Glpi/Features/Dcbreadcrumb.php b/tests/functional/Glpi/Features/Dcbreadcrumb.php similarity index 100% rename from tests/units/Glpi/Features/Dcbreadcrumb.php rename to tests/functional/Glpi/Features/Dcbreadcrumb.php diff --git a/tests/units/Glpi/Http/Firewall.php b/tests/functional/Glpi/Http/Firewall.php similarity index 100% rename from tests/units/Glpi/Http/Firewall.php rename to tests/functional/Glpi/Http/Firewall.php diff --git a/tests/units/Glpi/Http/ProxyRouter.php b/tests/functional/Glpi/Http/ProxyRouter.php similarity index 100% rename from tests/units/Glpi/Http/ProxyRouter.php rename to tests/functional/Glpi/Http/ProxyRouter.php diff --git a/tests/units/Glpi/Inventory/Conf.php b/tests/functional/Glpi/Inventory/Conf.php similarity index 100% rename from tests/units/Glpi/Inventory/Conf.php rename to tests/functional/Glpi/Inventory/Conf.php diff --git a/tests/units/Glpi/Inventory/Request.php b/tests/functional/Glpi/Inventory/Request.php similarity index 100% rename from tests/units/Glpi/Inventory/Request.php rename to tests/functional/Glpi/Inventory/Request.php diff --git a/tests/units/Glpi/RichText/RichText.php b/tests/functional/Glpi/RichText/RichText.php similarity index 100% rename from tests/units/Glpi/RichText/RichText.php rename to tests/functional/Glpi/RichText/RichText.php diff --git a/tests/units/Glpi/System/Diagnostic/DatabaseKeysChecker.php b/tests/functional/Glpi/System/Diagnostic/DatabaseKeysChecker.php similarity index 100% rename from tests/units/Glpi/System/Diagnostic/DatabaseKeysChecker.php rename to tests/functional/Glpi/System/Diagnostic/DatabaseKeysChecker.php diff --git a/tests/units/Glpi/System/Diagnostic/DatabaseSchemaConsistencyChecker.php b/tests/functional/Glpi/System/Diagnostic/DatabaseSchemaConsistencyChecker.php similarity index 100% rename from tests/units/Glpi/System/Diagnostic/DatabaseSchemaConsistencyChecker.php rename to tests/functional/Glpi/System/Diagnostic/DatabaseSchemaConsistencyChecker.php diff --git a/tests/units/Glpi/System/Diagnostic/DatabaseSchemaIntegrityChecker.php b/tests/functional/Glpi/System/Diagnostic/DatabaseSchemaIntegrityChecker.php similarity index 100% rename from tests/units/Glpi/System/Diagnostic/DatabaseSchemaIntegrityChecker.php rename to tests/functional/Glpi/System/Diagnostic/DatabaseSchemaIntegrityChecker.php diff --git a/tests/units/Glpi/System/Requirement/DataDirectoriesProtectedPath.php b/tests/functional/Glpi/System/Requirement/DataDirectoriesProtectedPath.php similarity index 100% rename from tests/units/Glpi/System/Requirement/DataDirectoriesProtectedPath.php rename to tests/functional/Glpi/System/Requirement/DataDirectoriesProtectedPath.php diff --git a/tests/units/Glpi/System/Requirement/DbConfiguration.php b/tests/functional/Glpi/System/Requirement/DbConfiguration.php similarity index 100% rename from tests/units/Glpi/System/Requirement/DbConfiguration.php rename to tests/functional/Glpi/System/Requirement/DbConfiguration.php diff --git a/tests/units/Glpi/System/Requirement/DbEngine.php b/tests/functional/Glpi/System/Requirement/DbEngine.php similarity index 100% rename from tests/units/Glpi/System/Requirement/DbEngine.php rename to tests/functional/Glpi/System/Requirement/DbEngine.php diff --git a/tests/units/Glpi/System/Requirement/DbTimezones.php b/tests/functional/Glpi/System/Requirement/DbTimezones.php similarity index 100% rename from tests/units/Glpi/System/Requirement/DbTimezones.php rename to tests/functional/Glpi/System/Requirement/DbTimezones.php diff --git a/tests/units/Glpi/System/Requirement/DirectoriesWriteAccess.php b/tests/functional/Glpi/System/Requirement/DirectoriesWriteAccess.php similarity index 100% rename from tests/units/Glpi/System/Requirement/DirectoriesWriteAccess.php rename to tests/functional/Glpi/System/Requirement/DirectoriesWriteAccess.php diff --git a/tests/units/Glpi/System/Requirement/DirectoryWriteAccess.php b/tests/functional/Glpi/System/Requirement/DirectoryWriteAccess.php similarity index 100% rename from tests/units/Glpi/System/Requirement/DirectoryWriteAccess.php rename to tests/functional/Glpi/System/Requirement/DirectoryWriteAccess.php diff --git a/tests/units/Glpi/System/Requirement/Extension.php b/tests/functional/Glpi/System/Requirement/Extension.php similarity index 100% rename from tests/units/Glpi/System/Requirement/Extension.php rename to tests/functional/Glpi/System/Requirement/Extension.php diff --git a/tests/units/Glpi/System/Requirement/ExtensionClass.php b/tests/functional/Glpi/System/Requirement/ExtensionClass.php similarity index 100% rename from tests/units/Glpi/System/Requirement/ExtensionClass.php rename to tests/functional/Glpi/System/Requirement/ExtensionClass.php diff --git a/tests/units/Glpi/System/Requirement/ExtensionConstant.php b/tests/functional/Glpi/System/Requirement/ExtensionConstant.php similarity index 100% rename from tests/units/Glpi/System/Requirement/ExtensionConstant.php rename to tests/functional/Glpi/System/Requirement/ExtensionConstant.php diff --git a/tests/units/Glpi/System/Requirement/ExtensionFunction.php b/tests/functional/Glpi/System/Requirement/ExtensionFunction.php similarity index 100% rename from tests/units/Glpi/System/Requirement/ExtensionFunction.php rename to tests/functional/Glpi/System/Requirement/ExtensionFunction.php diff --git a/tests/units/Glpi/System/Requirement/ExtensionGroup.php b/tests/functional/Glpi/System/Requirement/ExtensionGroup.php similarity index 100% rename from tests/units/Glpi/System/Requirement/ExtensionGroup.php rename to tests/functional/Glpi/System/Requirement/ExtensionGroup.php diff --git a/tests/units/Glpi/System/Requirement/InstallationNotOverriden.php b/tests/functional/Glpi/System/Requirement/InstallationNotOverriden.php similarity index 100% rename from tests/units/Glpi/System/Requirement/InstallationNotOverriden.php rename to tests/functional/Glpi/System/Requirement/InstallationNotOverriden.php diff --git a/tests/units/Glpi/System/Requirement/LogsWriteAccess.php b/tests/functional/Glpi/System/Requirement/LogsWriteAccess.php similarity index 100% rename from tests/units/Glpi/System/Requirement/LogsWriteAccess.php rename to tests/functional/Glpi/System/Requirement/LogsWriteAccess.php diff --git a/tests/units/Glpi/System/Requirement/MemoryLimit.php b/tests/functional/Glpi/System/Requirement/MemoryLimit.php similarity index 100% rename from tests/units/Glpi/System/Requirement/MemoryLimit.php rename to tests/functional/Glpi/System/Requirement/MemoryLimit.php diff --git a/tests/units/Glpi/System/Requirement/MysqliMysqlnd.php b/tests/functional/Glpi/System/Requirement/MysqliMysqlnd.php similarity index 100% rename from tests/units/Glpi/System/Requirement/MysqliMysqlnd.php rename to tests/functional/Glpi/System/Requirement/MysqliMysqlnd.php diff --git a/tests/units/Glpi/System/Requirement/PhpSupportedVersion.php b/tests/functional/Glpi/System/Requirement/PhpSupportedVersion.php similarity index 100% rename from tests/units/Glpi/System/Requirement/PhpSupportedVersion.php rename to tests/functional/Glpi/System/Requirement/PhpSupportedVersion.php diff --git a/tests/units/Glpi/System/Requirement/PhpVersion.php b/tests/functional/Glpi/System/Requirement/PhpVersion.php similarity index 100% rename from tests/units/Glpi/System/Requirement/PhpVersion.php rename to tests/functional/Glpi/System/Requirement/PhpVersion.php diff --git a/tests/units/Glpi/System/Requirement/ProtectedWebAccess.php b/tests/functional/Glpi/System/Requirement/ProtectedWebAccess.php similarity index 100% rename from tests/units/Glpi/System/Requirement/ProtectedWebAccess.php rename to tests/functional/Glpi/System/Requirement/ProtectedWebAccess.php diff --git a/tests/units/Glpi/System/Requirement/SeLinux.php b/tests/functional/Glpi/System/Requirement/SeLinux.php similarity index 100% rename from tests/units/Glpi/System/Requirement/SeLinux.php rename to tests/functional/Glpi/System/Requirement/SeLinux.php diff --git a/tests/units/Glpi/System/Requirement/SessionsConfiguration.php b/tests/functional/Glpi/System/Requirement/SessionsConfiguration.php similarity index 100% rename from tests/units/Glpi/System/Requirement/SessionsConfiguration.php rename to tests/functional/Glpi/System/Requirement/SessionsConfiguration.php diff --git a/tests/units/Glpi/System/Requirement/SessionsSecurityConfiguration.php b/tests/functional/Glpi/System/Requirement/SessionsSecurityConfiguration.php similarity index 100% rename from tests/units/Glpi/System/Requirement/SessionsSecurityConfiguration.php rename to tests/functional/Glpi/System/Requirement/SessionsSecurityConfiguration.php diff --git a/tests/units/Glpi/Toolbox/DataExport.php b/tests/functional/Glpi/Toolbox/DataExport.php similarity index 100% rename from tests/units/Glpi/Toolbox/DataExport.php rename to tests/functional/Glpi/Toolbox/DataExport.php diff --git a/tests/units/Glpi/Toolbox/DatabaseSchema.php b/tests/functional/Glpi/Toolbox/DatabaseSchema.php similarity index 100% rename from tests/units/Glpi/Toolbox/DatabaseSchema.php rename to tests/functional/Glpi/Toolbox/DatabaseSchema.php diff --git a/tests/units/Glpi/Toolbox/Filesystem.php b/tests/functional/Glpi/Toolbox/Filesystem.php similarity index 100% rename from tests/units/Glpi/Toolbox/Filesystem.php rename to tests/functional/Glpi/Toolbox/Filesystem.php diff --git a/tests/units/Glpi/Toolbox/FrontEnd.php b/tests/functional/Glpi/Toolbox/FrontEnd.php similarity index 100% rename from tests/units/Glpi/Toolbox/FrontEnd.php rename to tests/functional/Glpi/Toolbox/FrontEnd.php diff --git a/tests/units/Glpi/Toolbox/Sanitizer.php b/tests/functional/Glpi/Toolbox/Sanitizer.php similarity index 100% rename from tests/units/Glpi/Toolbox/Sanitizer.php rename to tests/functional/Glpi/Toolbox/Sanitizer.php diff --git a/tests/units/Glpi/Toolbox/URL.php b/tests/functional/Glpi/Toolbox/URL.php similarity index 100% rename from tests/units/Glpi/Toolbox/URL.php rename to tests/functional/Glpi/Toolbox/URL.php diff --git a/tests/units/Glpi/Toolbox/VersionParser.php b/tests/functional/Glpi/Toolbox/VersionParser.php similarity index 100% rename from tests/units/Glpi/Toolbox/VersionParser.php rename to tests/functional/Glpi/Toolbox/VersionParser.php diff --git a/tests/units/Html.php b/tests/functional/Html.php similarity index 100% rename from tests/units/Html.php rename to tests/functional/Html.php diff --git a/tests/units/Migration.php b/tests/functional/Migration.php similarity index 100% rename from tests/units/Migration.php rename to tests/functional/Migration.php diff --git a/tests/units/QueryParam.php b/tests/functional/QueryParam.php similarity index 100% rename from tests/units/QueryParam.php rename to tests/functional/QueryParam.php diff --git a/tests/units/RuleAsset.php b/tests/functional/RuleAsset.php similarity index 100% rename from tests/units/RuleAsset.php rename to tests/functional/RuleAsset.php diff --git a/tests/units/RuleRight.php b/tests/functional/RuleRight.php similarity index 100% rename from tests/units/RuleRight.php rename to tests/functional/RuleRight.php diff --git a/tests/functional/Session.php b/tests/functional/Session.php index 365cf1d4bb9..986c7eb59ef 100644 --- a/tests/functional/Session.php +++ b/tests/functional/Session.php @@ -39,6 +39,41 @@ class Session extends \DbTestCase { + protected function testUniqueSessionNameProvider(): iterable + { + // Same host, different path + yield [ + \Session::buildSessionName("/var/www/localhost/glpi1", 'localhost', '80'), + \Session::buildSessionName("/var/www/localhost/glpi2", 'localhost', '80'), + \Session::buildSessionName("/var/www/localhost/glpi3", 'localhost', '80'), + \Session::buildSessionName("/var/www/localhost/glpi4", 'localhost', '80'), + ]; + + // Same path, different full domains + yield [ + \Session::buildSessionName("/var/www/glpi", 'test.localhost', '80'), + \Session::buildSessionName("/var/www/glpi", 'preprod.localhost', '80'), + \Session::buildSessionName("/var/www/glpi", 'prod.localhost', '80'), + \Session::buildSessionName("/var/www/glpi", 'localhost', '80'), + ]; + + // Same host and path but different ports + yield [ + \Session::buildSessionName("/var/www/glpi", 'localhost', '80'), + \Session::buildSessionName("/var/www/glpi", 'localhost', '8000'), + \Session::buildSessionName("/var/www/glpi", 'localhost', '8008'), + ]; + } + + /** + * @dataProvider testUniqueSessionNameProvider + */ + public function testUniqueSessionName( + ...$cookie_names + ): void { + // Each cookie name must be unique + $this->array($cookie_names)->isEqualTo(array_unique($cookie_names)); + } public function testAddMessageAfterRedirect() { $err_msg = 'Something is broken. Weird.'; diff --git a/tests/units/ShareDashboardDropdown.php b/tests/functional/ShareDashboardDropdown.php similarity index 100% rename from tests/units/ShareDashboardDropdown.php rename to tests/functional/ShareDashboardDropdown.php diff --git a/tests/run_tests.sh b/tests/run_tests.sh index c5410ea4fba..a9406c98383 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -46,7 +46,6 @@ TESTS_SUITES=( "lint_twig" "install" "update" - "units" "functional" "cache" "ldap" @@ -147,7 +146,6 @@ Available tests suites: - lint_twig - install - update - - units - functional - cache - ldap @@ -265,10 +263,6 @@ run_single_test () { && docker compose exec -T app .github/actions/test_update-from-9.5.sh \ || LAST_EXIT_CODE=$? ;; - "units") - docker compose exec -T app .github/actions/test_tests-units.sh $TEST_ARGS \ - || LAST_EXIT_CODE=$? - ;; "functional") docker compose exec -T app .github/actions/test_tests-functional.sh $TEST_ARGS \ || LAST_EXIT_CODE=$? diff --git a/tests/units/CronTask.php b/tests/units/CronTask.php deleted file mode 100644 index 417c17dd4f5..00000000000 --- a/tests/units/CronTask.php +++ /dev/null @@ -1,107 +0,0 @@ -. - * - * --------------------------------------------------------------------- - */ - -namespace tests\units; - -use RecursiveDirectoryIterator; -use RecursiveIteratorIterator; - -/* Test for inc/crontask.class.php */ - -class Crontask extends \GLPITestCase -{ - public function testCronTemp() - { - - //create some files - $Data = [ - [ - 'name' => GLPI_TMP_DIR . '/recent_file.txt', - 'content' => 'content1', - ], - [ - 'name' => GLPI_TMP_DIR . '/file1.txt', - 'content' => 'content1', - ], - [ - 'name' => GLPI_TMP_DIR . '/file2.txt', - 'content' => 'content2', - ], - [ - 'name' => GLPI_TMP_DIR . '/auto_orient/file3.txt', - 'content' => 'content3', - ], - [ - 'name' => GLPI_TMP_DIR . '/auto_orient/file4.txt', - 'content' => 'content4', - ] - ]; - - //create auto_orient directory - if (!file_exists(GLPI_TMP_DIR . '/auto_orient/')) { - mkdir(GLPI_TMP_DIR . '/auto_orient/', 0755, true); - } - - foreach ($Data as $Row) { - $file = fopen($Row['name'], 'c'); - fwrite($file, $Row['content']); - fclose($file); - - //change filemtime (except recent_file.txt) - if ($Row['name'] != GLPI_TMP_DIR . '/recent_file.txt') { - touch($Row['name'], time() - (HOUR_TIMESTAMP * 2)); - } - } - - // launch Cron for cleaning _tmp directory - $mode = - \CronTask::MODE_EXTERNAL; // force - \CronTask::launch($mode, 5, 'temp'); - - $nb_file = $this->getFileCountRecursively(GLPI_TMP_DIR); - $this->variable($nb_file)->isEqualTo(1); //recent_file.txt - } - - - public function getFileCountRecursively($path) - { - - $dir = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS); - $files = new RecursiveIteratorIterator( - $dir, - RecursiveIteratorIterator::CHILD_FIRST - ); - return iterator_count($files); - } -} diff --git a/tests/units/Glpi/ContentTemplates/TemplateManager.php b/tests/units/Glpi/ContentTemplates/TemplateManager.php deleted file mode 100644 index 02b16a2db09..00000000000 --- a/tests/units/Glpi/ContentTemplates/TemplateManager.php +++ /dev/null @@ -1,168 +0,0 @@ -. - * - * --------------------------------------------------------------------- - */ - -namespace tests\units\Glpi\ContentTemplates; - -use GLPITestCase; -use Twig\Sandbox\SecurityPolicy; - -class TemplateManager extends GLPITestCase -{ - protected function testTemplatesProvider(): array - { - return [ - [ - 'content' => "{{ test_var }}", - 'params' => ['test_var' => 'test_value'], - 'expected' => "

test_value

", - ], - [ - 'content' => "Test var: {{ test_var }}", - 'params' => ['test_var' => 'test_value'], - 'expected' => "

Test var: test_value

", - ], - [ - 'content' => "Test condition: {% if test_condition == true %}TRUE{% else %}FALSE{% endif %}", - 'params' => ['test_condition' => 'true'], - 'expected' => "

Test condition: TRUE

", - ], - [ - 'content' => "Test condition: {% if test_condition == true %}TRUE{% else %}FALSE{% endif %}", - 'params' => ['test_condition' => 'false'], - 'expected' => "

Test condition: TRUE

", - ], - [ - 'content' => "Test for: {% for item in items %}{{ item }} {% else %}no items{% endfor %}", - 'params' => ['items' => ['a', 'b', 'c', 'd', 'e']], - 'expected' => "

Test for: a b c d e

", - ], - [ - 'content' => "Test for: {% for item in items %}{{ item }} {% else %}no items{% endfor %}", - 'params' => ['items' => []], - 'expected' => "

Test for: no items

", - ], - [ - 'content' => "Test forbidden tag: {% set var = 'value' %}", - 'params' => [], - 'expected' => "", - 'error' => 'Invalid twig template (Tag "set" is not allowed in "template" at line 1.)', - ], - [ - 'content' => "Test syntax error {{", - 'params' => [], - 'expected' => "", - 'error' => 'Invalid twig template syntax', - ], - [ - 'content' => '<h1>Test sanitized template</h1><hr />{{content|raw}}', - 'params' => ['content' => '

Item content

'], - 'expected' => '

Test sanitized template


Item content

', - 'error' => null, - ], - [ - 'content' => '<h1>Test sanitized template 2</h1><hr />{{content|raw}}', - 'params' => ['content' => 'Item content should not be unsanitized: <--'], - 'expected' => '

Test sanitized template 2


Item content should not be unsanitized: <--', - 'error' => null, - ], - [ - 'content' => "<p>Test sanitized template {% if count > 5 %}<b>++</b>{% endif %}</p>", - 'params' => ['count' => 25], - 'expected' => "

Test sanitized template ++

", - 'error' => null, - ], - [ - 'content' => '<h1 onclick="alert(1);">Test safe HTML2</h1><hr />{{content|raw}}', - 'params' => ['content' => 'Fill this form:'], - 'expected' => '

Test safe HTML2


Fill this form:', - 'error' => null, - ], - ]; - } - - /** - * @dataProvider testTemplatesProvider - */ - public function testRender( - string $content, - array $params, - string $expected, - ?string $error = null - ): void { - $manager = $this->newTestedInstance(); - - $html = null; - - if ($error !== null) { - $this->exception( - function () use ($manager, $content, $params, &$html) { - $html = $manager->render($content, $params); - } - ); - return; - } else { - $html = $manager->render($content, $params); - } - - $this->string($html)->isEqualTo($expected); - } - - /** - * @dataProvider testTemplatesProvider - */ - public function testValidate( - string $content, - array $params, - string $expected, - ?string $error = null - ): void { - $manager = $this->newTestedInstance(); - $err_msg = null; - $is_valid = $manager->validate($content, $err_msg); - $this->boolean($is_valid)->isEqualTo(empty($error)); - - // Handle error if neeced - if ($error !== null) { - $this->string($err_msg)->contains($error); - } - } - - public function testGetSecurityPolicy(): void - { - // Not much to test here, maybe keepk this for code coverage ? - $manager = $this->newTestedInstance(); - $this->object($manager->getSecurityPolicy())->isInstanceOf(SecurityPolicy::class); - } -} diff --git a/tests/units/Glpi/Dashboard/Provider.php b/tests/units/Glpi/Dashboard/Provider.php deleted file mode 100644 index 9048d1e6ddc..00000000000 --- a/tests/units/Glpi/Dashboard/Provider.php +++ /dev/null @@ -1,603 +0,0 @@ -. - * - * --------------------------------------------------------------------- - */ - -namespace tests\units\Glpi\Dashboard; - -use DbTestCase; -use Group; -use SLA; -use Slm; -use Ticket; - -/* Test for src/Dashboard/Provider.php */ - -class Provider extends DbTestCase -{ - public function testNbTicketsByAgreementStatusAndTechnician() - { - global $DB; - - // Prepare context - $slm = new Slm(); - $slm->add([ - 'name' => 'SLM', - ]); - - $slaTto = new SLA(); - $slaTto->add([ - 'name' => 'sla tto', - 'type' => '1', // TTO - 'number_time' => 4, - 'definition_time' => 'hour', - 'slms_id' => $slm->getID(), - ]); - - $slaTtr = new SLA(); - $slaTtr->add([ - 'name' => 'sla ttr', - 'type' => '0', // TTR - 'number_time' => 4, - 'definition_time' => 'hour', - 'slms_id' => $slm->getID(), - ]); - - $ticket = new Ticket(); - $ticket->add([ - 'name' => "test dashboard card SLA / tech", - 'content' => 'foo', - '_users_id_assign' => 2, // glpi - 'sla_id_tto' => $slaTto->getID(), - 'sla_id_ttr' => $slaTtr->getID(), - 'status' => Ticket::ASSIGNED, - ]); - $this->boolean($ticket->isNewItem())->isFalse(); - - $ticket2 = new Ticket(); - $ticket2->add([ - 'name' => "test dashboard card SLA / tech", - 'content' => 'foo', - '_users_id_assign' => 4, // tech - 'sla_id_tto' => $slaTto->getID(), - 'sla_id_ttr' => $slaTtr->getID(), - 'status' => Ticket::ASSIGNED, - ]); - $this->boolean($ticket2->isNewItem())->isFalse(); - - $ticket3 = new Ticket(); - $ticket3->add([ - 'name' => "test dashboard card SLA / tech", - 'content' => 'foo', - '_users_id_assign' => 4, // tech - 'sla_id_tto' => $slaTto->getID(), - 'sla_id_ttr' => $slaTtr->getID(), - 'status' => Ticket::ASSIGNED, - ]); - $this->boolean($ticket3->isNewItem())->isFalse(); - - $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnician(); - $expected = [ - 'label' => "Tickets by SLA status and by technician", - 'data' => [ - 'labels' => ['tech', 'glpi'], - 'series' => [ - [ - 'name' => 'Late own and resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late own', - 'data' => [0, 0] - ], - [ - 'name' => 'On time', - 'data' => [2, 1] - ] - ] - ], - 'icon' => 'fas fa-stopwatch' - ]; - $this->array($output)->isEqualTo($expected); - - $DB->update( - $ticket::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - ], - [ - 'id' => $ticket->getID() - ] - ); - $DB->update( - $ticket2::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - ], - [ - 'id' => $ticket2->getID() - ] - ); - $ticket->getFromDB($ticket->getID()); - $ticket2->getFromDB($ticket2->getID()); - - $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnician(); - $expected = [ - 'label' => "Tickets by SLA status and by technician", - 'data' => [ - 'labels' => ['glpi', 'tech'], - 'series' => [ - [ - 'name' => 'Late own and resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late own', - 'data' => [1, 1] - ], - [ - 'name' => 'On time', - 'data' => [0, 1] - ] - ] - ], - 'icon' => 'fas fa-stopwatch' - ]; - $this->array($output)->isEqualTo($expected); - - $DB->update( - $ticket::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 60, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket->getID() - ] - ); - $DB->update( - $ticket2::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 60, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket2->getID() - ] - ); - $ticket->getFromDB($ticket->getID()); - $ticket2->getFromDB($ticket2->getID()); - $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnician(); - $expected = [ - 'label' => "Tickets by SLA status and by technician", - 'data' => [ - 'labels' => ['glpi', 'tech'], - 'series' => [ - [ - 'name' => 'Late own and resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late resolve', - 'data' => [1, 1] - ], - [ - 'name' => 'Late own', - 'data' => [0, 0] - ], - [ - 'name' => 'On time', - 'data' => [0, 1] - ] - ] - ], - 'icon' => 'fas fa-stopwatch' - ]; - $this->array($output)->isEqualTo($expected); - - $DB->update( - $ticket::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket->getID() - ] - ); - $DB->update( - $ticket2::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket2->getID() - ] - ); - $DB->update( - $ticket3::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket3->getID() - ] - ); - $ticket->getFromDB($ticket->getID()); - $ticket2->getFromDB($ticket2->getID()); - $ticket3->getFromDB($ticket3->getID()); - $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnician(); - $expected = [ - 'label' => "Tickets by SLA status and by technician", - 'data' => [ - 'labels' => ['tech', 'glpi'], - 'series' => [ - [ - 'name' => 'Late own and resolve', - 'data' => [2, 1] - ], - [ - 'name' => 'Late resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late own', - 'data' => [0, 0] - ], - [ - 'name' => 'On time', - 'data' => [0, 0] - ] - ] - ], - 'icon' => 'fas fa-stopwatch' - ]; - $this->array($output)->isEqualTo($expected); - } - - - public function testNbTicketsByAgreementStatusAndTechnicianGroup() - { - global $DB; - - // Prepare context - $slm = new Slm(); - $slm->add([ - 'name' => 'SLM', - ]); - - $slaTto = new SLA(); - $slaTto->add([ - 'name' => 'sla tto', - 'type' => '1', // TTO - 'number_time' => 4, - 'definition_time' => 'hour', - 'slms_id' => $slm->getID(), - ]); - - $slaTtr = new SLA(); - $slaTtr->add([ - 'name' => 'sla ttr', - 'type' => '0', // TTR - 'number_time' => 4, - 'definition_time' => 'hour', - 'slms_id' => $slm->getID(), - ]); - - $group = new Group(); - $group->add([ - 'entities_id' => 0, - 'name' => 'group sla test', - 'level' => 1, - 'groups_id' => 0, - ]); - $this->boolean($group->isNewItem())->isFalse(); - - $group2 = new Group(); - $group2->add([ - 'entities_id' => 0, - 'name' => 'second group sla test', - 'level' => 1, - 'groups_id' => 0, - ]); - $this->boolean($group2->isNewItem())->isFalse(); - - $ticket = new Ticket(); - $ticket->add([ - 'name' => "test dashboard card SLA / tech", - 'content' => 'foo', - '_groups_id_assign' => $group->getID(), - 'sla_id_tto' => $slaTto->getID(), - 'sla_id_ttr' => $slaTtr->getID(), - 'status' => Ticket::ASSIGNED, - ]); - $this->boolean($ticket->isNewItem())->isFalse(); - - $ticket2 = new Ticket(); - $ticket2->add([ - 'name' => "test dashboard card SLA / tech for second group", - 'content' => 'foo', - '_groups_id_assign' => $group2->getID(), - 'sla_id_tto' => $slaTto->getID(), - 'sla_id_ttr' => $slaTtr->getID(), - 'status' => Ticket::ASSIGNED, - ]); - $this->boolean($ticket2->isNewItem())->isFalse(); - - $ticket3 = new Ticket(); - $ticket3->add([ - 'name' => "test dashboard card SLA / tech for second group", - 'content' => 'foo', - '_groups_id_assign' => $group2->getID(), - 'sla_id_tto' => $slaTto->getID(), - 'sla_id_ttr' => $slaTtr->getID(), - 'status' => Ticket::ASSIGNED, - ]); - - $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnicianGroup(); - $expected = [ - 'label' => "Tickets by SLA status and by technician group", - 'data' => [ - 'labels' => ['second group sla test', 'group sla test'], - 'series' => [ - [ - 'name' => 'Late own and resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late own', - 'data' => [0, 0] - ], - [ - 'name' => 'On time', - 'data' => [2, 1] - ] - ] - ], - 'icon' => 'fas fa-stopwatch' - ]; - $this->array($output)->isEqualTo($expected); - - $DB->update( - $ticket::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - ], - [ - 'id' => $ticket->getID() - ] - ); - $DB->update( - $ticket2::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - ], - [ - 'id' => $ticket2->getID() - ] - ); - $ticket->getFromDB($ticket->getID()); - $ticket2->getFromDB($ticket2->getID()); - - $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnicianGroup(); - $expected = [ - 'label' => "Tickets by SLA status and by technician group", - 'data' => [ - 'labels' => ['group sla test', 'second group sla test'], - 'series' => [ - [ - 'name' => 'Late own and resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late own', - 'data' => [1, 1] - ], - [ - 'name' => 'On time', - 'data' => [0, 1] - ] - ] - ], - 'icon' => 'fas fa-stopwatch' - ]; - $this->array($output)->isEqualTo($expected); - - $DB->update( - $ticket::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 60, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket->getID() - ] - ); - $DB->update( - $ticket2::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 60, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket2->getID() - ] - ); - $ticket->getFromDB($ticket->getID()); - $ticket2->getFromDB($ticket2->getID()); - $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnicianGroup(); - $expected = [ - 'label' => "Tickets by SLA status and by technician group", - 'data' => [ - 'labels' => ['group sla test', 'second group sla test'], - 'series' => [ - [ - 'name' => 'Late own and resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late resolve', - 'data' => [1, 1] - ], - [ - 'name' => 'Late own', - 'data' => [0, 0] - ], - [ - 'name' => 'On time', - 'data' => [0, 1] - ] - ] - ], - 'icon' => 'fas fa-stopwatch' - ]; - $this->array($output)->isEqualTo($expected); - - $DB->update( - $ticket::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket->getID() - ] - ); - $DB->update( - $ticket2::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket2->getID() - ] - ); - $DB->update( - $ticket3::getTable(), - [ - 'date' => '2021-01-01 00:00', - 'time_to_own' => '2021-01-01 01:00', - 'takeintoaccount_delay_stat' => 50000, - 'solvedate' => '2021-02-01 00:00', - 'time_to_resolve' => '2021-01-02 00:00' - ], - [ - 'id' => $ticket3->getID() - ] - ); - $ticket->getFromDB($ticket->getID()); - $ticket2->getFromDB($ticket2->getID()); - $ticket3->getFromDB($ticket3->getID()); - $output = \Glpi\Dashboard\Provider::nbTicketsByAgreementStatusAndTechnicianGroup(); - $expected = [ - 'label' => "Tickets by SLA status and by technician group", - 'data' => [ - 'labels' => ['second group sla test', 'group sla test'], - 'series' => [ - [ - 'name' => 'Late own and resolve', - 'data' => [2, 1] - ], - [ - 'name' => 'Late resolve', - 'data' => [0, 0] - ], - [ - 'name' => 'Late own', - 'data' => [0, 0] - ], - [ - 'name' => 'On time', - 'data' => [0, 0] - ] - ] - ], - 'icon' => 'fas fa-stopwatch' - ]; - $this->array($output)->isEqualTo($expected); - } -} diff --git a/tests/units/Session.php b/tests/units/Session.php deleted file mode 100644 index a20275bb474..00000000000 --- a/tests/units/Session.php +++ /dev/null @@ -1,77 +0,0 @@ -. - * - * --------------------------------------------------------------------- - */ - -namespace tests\units; - -use DbTestCase; - -class Session extends DbTestCase -{ - protected function testUniqueSessionNameProvider(): iterable - { - // Same host, different path - yield [ - \Session::buildSessionName("/var/www/localhost/glpi1", 'localhost', '80'), - \Session::buildSessionName("/var/www/localhost/glpi2", 'localhost', '80'), - \Session::buildSessionName("/var/www/localhost/glpi3", 'localhost', '80'), - \Session::buildSessionName("/var/www/localhost/glpi4", 'localhost', '80'), - ]; - - // Same path, different full domains - yield [ - \Session::buildSessionName("/var/www/glpi", 'test.localhost', '80'), - \Session::buildSessionName("/var/www/glpi", 'preprod.localhost', '80'), - \Session::buildSessionName("/var/www/glpi", 'prod.localhost', '80'), - \Session::buildSessionName("/var/www/glpi", 'localhost', '80'), - ]; - - // Same host and path but different ports - yield [ - \Session::buildSessionName("/var/www/glpi", 'localhost', '80'), - \Session::buildSessionName("/var/www/glpi", 'localhost', '8000'), - \Session::buildSessionName("/var/www/glpi", 'localhost', '8008'), - ]; - } - - /** - * @dataProvider testUniqueSessionNameProvider - */ - public function testUniqueSessionName( - ...$cookie_names - ): void { - // Each cookie name must be unique - $this->array($cookie_names)->isEqualTo(array_unique($cookie_names)); - } -} diff --git a/tools/dup_tests.sh b/tools/dup_tests.sh deleted file mode 100755 index 70f4786bbb8..00000000000 --- a/tools/dup_tests.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# -# --------------------------------------------------------------------- -# -# GLPI - Gestionnaire Libre de Parc Informatique -# -# http://glpi-project.org -# -# @copyright 2015-2024 Teclib' and contributors. -# @copyright 2003-2014 by the INDEPNET Development Team. -# @licence https://www.gnu.org/licenses/gpl-3.0.html -# -# --------------------------------------------------------------------- -# -# LICENSE -# -# This file is part of GLPI. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# --------------------------------------------------------------------- -# - -units_dir=./tests/units -func_dir=./tests/functional - -find "$units_dir" -type f -name "*.php" | while read i;do - filename="$(basename "${i}")" - find "$func_dir" -type f -name "$filename" -done - -find "$func_dir" -type f -name "*.php" | while read i;do - filename="$(basename "${i}")" - find "$units_dir" -type f -name "$filename" -done diff --git a/tools/genphpcov.sh b/tools/genphpcov.sh deleted file mode 100755 index c04e1847115..00000000000 --- a/tools/genphpcov.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sh - -# -# --------------------------------------------------------------------- -# -# GLPI - Gestionnaire Libre de Parc Informatique -# -# http://glpi-project.org -# -# @copyright 2015-2024 Teclib' and contributors. -# @copyright 2003-2014 by the INDEPNET Development Team. -# @licence https://www.gnu.org/licenses/gpl-3.0.html -# -# --------------------------------------------------------------------- -# -# LICENSE -# -# This file is part of GLPI. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# --------------------------------------------------------------------- -# - -cd $(dirname $0)/.. -if ! which atoum &>/dev/null -then - echo -e "\natoum not found, see https://atoum.org/\n" - exit 1 - -elif php -m | grep -qi xdebug -then - # PHP 5 + xdebug - atoum \ - --debug \ - --max-children-number 1 \ - --bootstrap-file tests/bootstrap.php \ - --directories tests/units \ - --no-code-coverage-for-classes DbTestCase DbFunction Autoload NotificationSettingInstance \ - --no-code-coverage-for-namespaces atoum\\atoum -else - echo -e "\nYou need PHP with XDebug\n" - exit 2 -fi