From 593ab9a5f68c57bc1e387f320dfd921fe499fccd Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Wed, 5 Mar 2025 18:39:47 +0100 Subject: [PATCH 1/2] ESLint files, and upgrade it to 9.20.1 in pre-commit, add PHP-CS-Fixer --- .pre-commit-config.yaml | 16 ++++++++-------- eslint.config.mjs | 10 ++++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 977e9cfb7d..fdbb0b561e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,12 +28,12 @@ repos: files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx types: [ file ] additional_dependencies: - - eslint@9.19.0 + - eslint@9.21.0 -# - repo: local -# hooks: -# - id: php-cs-fixer -# name: PHP CS Fixer -# # To match value in Makefile -# entry: ghcr.io/php-cs-fixer/php-cs-fixer:3.69-php8.1 fix --config .php-cs-fixer.dist.php --allow-risky=yes -# language: docker_image + - repo: local + hooks: + - id: php-cs-fixer + name: PHP CS Fixer + # To match value in Makefile + entry: ghcr.io/php-cs-fixer/php-cs-fixer:3.69-php8.1 fix --config .php-cs-fixer.dist.php --allow-risky=yes + language: docker_image diff --git a/eslint.config.mjs b/eslint.config.mjs index 6df534452d..2586acccee 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -69,7 +69,7 @@ export default [ }, rules: { "@stylistic/js/indent": [ - 'error', 4, { + "error", 4, { "SwitchCase": 1, "ignoredNodes": ["TemplateLiteral *"], } @@ -78,7 +78,13 @@ export default [ "error", 290, 4], // It's a temporary value, until we fix some. "no-prototype-builtins": "off", "no-undef": "off", - 'jsdoc/require-description': 'warn', + "jsdoc/require-description": "warn", + "jsdoc/tag-lines": [ + "error"|"warn", + "always",{ + "applyToEndTag":false + } + ], }, }, { files: [ From 7ed0e173959e8794c9e39f35189c7030ea28dcfc Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Thu, 6 Mar 2025 17:36:47 +0100 Subject: [PATCH 2/2] Pre-commit all files, with the new PHP-CS-Fixer rule --- .php-cs-fixer.dist.php | 122 ++++---- docker/lizmapConfig.ini.php.dist | 2 +- docker/localconfig.ini.php.dist | 2 +- docker/update-config.php | 87 +++--- extra-modules/lizmapdemo/install/install.php | 32 ++- .../lizmapdemo/install/install_1_6.php | 15 +- lizmap/app/system/admin/auth.coord.ini.php | 2 +- lizmap/app/system/admin/config.ini.php | 2 +- lizmap/app/system/cmdline/auth.coord.ini.php | 2 +- lizmap/app/system/cmdline/script.ini.php | 2 +- lizmap/app/system/framework.ini.php | 2 +- lizmap/app/system/index/auth.coord.ini.php | 2 +- lizmap/app/system/index/config.ini.php | 2 +- lizmap/app/system/mainconfig.ini.php | 2 +- lizmap/application.init.php | 45 +-- lizmap/console.php | 9 +- lizmap/dev.php | 7 +- lizmap/install/configurator.php | 9 +- lizmap/install/installer.php | 9 +- .../install/tools/update_packages_version.php | 25 +- lizmap/install/uninstall/uninstaller.ini.php | 2 +- .../proj4php/classes/proj4php.class.php | 1 + lizmap/var/config/lizmapConfig.ini.php.dist | 2 +- lizmap/var/config/localconfig.ini.php.dist | 2 +- lizmap/var/config/profiles.ini.php.dist | 2 +- lizmap/www/admin.php | 20 +- lizmap/www/index.php | 20 +- tests/docker-conf/phpfpm/initpgsql.php | 3 +- tests/docker-conf/phpfpm/lizmapConfig.ini.php | 2 +- tests/docker-conf/phpfpm/localconfig.ini.php | 2 +- .../phpfpm/profiles-sqlite.ini.php | 2 +- tests/docker-conf/phpfpm/profiles.ini.php | 2 +- tests/docker-conf/phpfpm/resetpgsql.php | 3 +- tests/end2end/playwright/pages/printpage.js | 2 +- tests/end2end/playwright/print.spec.js | 4 +- tests/units/bootstrap.php | 11 +- tests/units/classes/App/FileToolsTest.php | 10 +- tests/units/classes/App/XmlToolsTest.php | 59 ++-- .../Form/QgisFormControlPropertiesTest.php | 59 ++-- .../classes/Form/QgisFormControlTest.php | 169 ++++++------ tests/units/classes/Form/QgisFormTest.php | 63 +++-- tests/units/classes/Log/ConfigTest.php | 9 +- tests/units/classes/Log/ItemTest.php | 36 ++- .../classes/Project/ProjectConfigTest.php | 31 ++- .../classes/Project/ProjectMainDataTest.php | 6 +- tests/units/classes/Project/ProjectTest.php | 96 ++++--- .../Project/Qgis/AttributeTableConfigTest.php | 15 +- .../Project/Qgis/BaseQgisObjectTest.php | 7 +- .../Project/Qgis/LayerTreeGroupTest.php | 33 +-- .../Project/Qgis/LayerTreeLayerTest.php | 25 +- .../Project/Qgis/LayerTreeRootTest.php | 20 +- .../classes/Project/Qgis/LayoutItemTest.php | 21 +- .../Project/Qgis/MapLayerStyleManagerTest.php | 18 +- .../classes/Project/Qgis/MapLayerTest.php | 91 +++--- .../units/classes/Project/Qgis/ParserTest.php | 58 ++-- .../Project/Qgis/ProjectGuiPropertiesTest.php | 103 +++---- .../classes/Project/Qgis/ProjectInfoTest.php | 129 ++++----- .../Project/Qgis/ProjectPropertiesTest.php | 35 +-- .../Project/Qgis/ProjectRelationTest.php | 5 +- .../Project/Qgis/ProjectVariablesTest.php | 19 +- .../Qgis/ProjectVisibilityPresetTest.php | 41 +-- .../Project/Qgis/RasterLayerPipeTest.php | 5 +- .../classes/Project/Qgis/RasterLayerTest.php | 25 +- .../classes/Project/Qgis/RendererV2Test.php | 8 +- .../Project/Qgis/SpatialRefSysTest.php | 18 +- .../VectorLayerConstraintExpressionTest.php | 9 +- .../Qgis/VectorLayerConstraintTest.php | 5 +- .../Qgis/VectorLayerEditWidgetTest.php | 49 ++-- .../Project/Qgis/VectorLayerFieldTest.php | 23 +- .../classes/Project/Qgis/VectorLayerTest.php | 36 +-- .../units/classes/Project/QgisProjectTest.php | 261 ++++++++++-------- .../units/classes/Request/OGCRequestTest.php | 37 ++- .../classes/Request/ProxyResponseTest.php | 11 +- tests/units/classes/Request/ProxyTest.php | 79 ++++-- .../QgisServerMetadataRequestMatcherTest.php | 7 +- .../units/classes/Request/WFSRequestTest.php | 95 +++++-- .../units/classes/Request/WMSRequestTest.php | 60 ++-- .../units/classes/Request/WMTSRequestTest.php | 19 +- tests/units/classes/lizmapRepositoryTest.php | 68 ++--- tests/units/classes/lizmapServicesTest.php | 26 +- tests/units/classes/lizmapWktTest.php | 36 ++- .../units/classes/qgisExpressionUtilsTest.php | 58 ++-- tests/units/edition/qgisAttributeFormTest.php | 4 +- tests/units/listRules.php | 35 +-- tests/units/rector.php | 32 ++- tests/units/testslib/ContextForTests.php | 65 ++--- tests/units/testslib/LizmapTilerForTests.php | 5 +- tests/units/testslib/OGCRequestForTests.php | 4 +- .../units/testslib/ProjectForOGCForTests.php | 5 +- tests/units/testslib/ProxyForTests.php | 1 - tests/units/testslib/QgisForm2ForTests.php | 4 +- .../testslib/QgisFormControlForTests.php | 1 - tests/units/testslib/QgisFormForTests.php | 6 +- tests/units/testslib/QgisProjectForTests.php | 10 +- tests/units/testslib/WFSRequestForTests.php | 8 +- tests/units/testslib/WMSRequestForTests.php | 1 - tests/units/testslib/WMTSRequestForTests.php | 1 - tests/units/testslib/jTplForTests.php | 11 +- 98 files changed, 1496 insertions(+), 1250 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 0b09e07c9f..90bc38875e 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,63 +1,67 @@ notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php') - ->in(array( - __DIR__.'/lizmap/modules/action', - __DIR__.'/lizmap/modules/admin', - __DIR__.'/lizmap/modules/dataviz', - __DIR__.'/lizmap/modules/filter', - __DIR__.'/lizmap/modules/lizmap', - __DIR__.'/lizmap/modules/view', - __DIR__.'/lizmap/plugins/', - __DIR__.'/lizmap/app/responses', - __DIR__.'/lizmap/scripts/', - )) - //->exclude(__DIR__.'/lizmap/modules/proj4php/classes/') - ; +use PhpCsFixer\Config; +use PhpCsFixer\Finder; + +$finder = Finder::create() + // ->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php') + ->in(array( + __DIR__.'/lizmap/modules/action', + __DIR__.'/lizmap/modules/admin', + __DIR__.'/lizmap/modules/dataviz', + __DIR__.'/lizmap/modules/filter', + __DIR__.'/lizmap/modules/lizmap', + __DIR__.'/lizmap/modules/view', + __DIR__.'/lizmap/plugins/', + __DIR__.'/lizmap/app/responses', + __DIR__.'/lizmap/scripts/', + )) + // ->exclude(__DIR__.'/lizmap/modules/proj4php/classes/') +; + +$config = new Config(); -$config = new PhpCsFixer\Config(); return $config - ->setCacheFile(__DIR__.'/.php-cs-fixer.cache') - ->setRules([ - '@PSR2' => true, - '@Symfony' => true, - '@PhpCsFixer' => true, - 'array_syntax' => array('syntax'=>'long'), - 'method_argument_space'=> ['on_multiline' => 'ensure_fully_multiline'], - 'new_with_braces'=> true, - 'no_whitespace_in_blank_line'=> true, - 'no_whitespace_before_comma_in_array'=> true, - 'no_useless_return' => true, - 'no_unneeded_final_method'=> false, - 'no_unset_cast' => false, - 'no_leading_import_slash'=> true, - 'no_leading_namespace_whitespace'=> true, - 'no_extra_blank_lines'=> true, - 'no_empty_statement'=> true, - 'no_empty_comment'=> true, - 'object_operator_without_whitespace' => true, - 'ordered_class_elements' => false, - 'phpdoc_var_without_name' => true, - 'phpdoc_types' => true, - 'phpdoc_trim_consecutive_blank_line_separation' => true, - 'phpdoc_no_useless_inheritdoc' => true, - 'phpdoc_no_empty_return' => true, - 'phpdoc_add_missing_param_annotation' => true, - 'protected_to_private' => false, - 'semicolon_after_instruction' => true, - 'short_scalar_cast' => true, - 'simplified_null_return' => false, - 'simple_to_complex_string_variable' => false, - 'standardize_not_equals' => true, - 'standardize_increment' => true, - 'whitespace_after_comma_in_array' => true, - 'yoda_style'=>array( - 'always_move_variable' => false, - 'equal' => false, - 'identical' => false, - 'less_and_greater' => null, - ) - ]) - ->setFinder($finder) - ; + ->setCacheFile(__DIR__.'/.php-cs-fixer.cache') + ->setRules(array( + '@PSR2' => true, + '@Symfony' => true, + '@PhpCsFixer' => true, + 'array_syntax' => array('syntax' => 'long'), + 'method_argument_space' => array('on_multiline' => 'ensure_fully_multiline'), + 'new_with_braces' => true, + 'no_whitespace_in_blank_line' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_useless_return' => true, + 'no_unneeded_final_method' => false, + 'no_unset_cast' => false, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_extra_blank_lines' => true, + 'no_empty_statement' => true, + 'no_empty_comment' => true, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => false, + 'phpdoc_var_without_name' => true, + 'phpdoc_types' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_no_empty_return' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'protected_to_private' => false, + 'semicolon_after_instruction' => true, + 'short_scalar_cast' => true, + 'simplified_null_return' => false, + 'simple_to_complex_string_variable' => false, + 'standardize_not_equals' => true, + 'standardize_increment' => true, + 'whitespace_after_comma_in_array' => true, + 'yoda_style' => array( + 'always_move_variable' => false, + 'equal' => false, + 'identical' => false, + 'less_and_greater' => null, + ), + )) + ->setFinder($finder) +; diff --git a/docker/lizmapConfig.ini.php.dist b/docker/lizmapConfig.ini.php.dist index ffc157f078..df7c97b652 100644 --- a/docker/lizmapConfig.ini.php.dist +++ b/docker/lizmapConfig.ini.php.dist @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line hideSensitiveServicesProperties=1 diff --git a/docker/localconfig.ini.php.dist b/docker/localconfig.ini.php.dist index 15555d4305..0896dfb61d 100644 --- a/docker/localconfig.ini.php.dist +++ b/docker/localconfig.ini.php.dist @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line ;theme= diff --git a/docker/update-config.php b/docker/update-config.php index 4172d16a56..e1ef98993d 100644 --- a/docker/update-config.php +++ b/docker/update-config.php @@ -1,20 +1,19 @@ #!/usr/bin/env php import($includeConfig); } @@ -29,17 +28,19 @@ function load_include_config($varname, $iniFileModifier) } /** - * connect to Postgresql with the given profile + * connect to Postgresql with the given profile. + * * @param array + * @param mixed $profile */ -function pgSqlConnect ($profile) +function pgSqlConnect($profile) { $str = ''; // Service is PostgreSQL way to store credentials in a file : // http://www.postgresql.org/docs/9.1/static/libpq-pgservice.html // If given, no need to add host, user, database, port and password - if(isset($profile['service']) && $profile['service'] != ''){ + if (isset($profile['service']) && $profile['service'] != '') { $str = 'service=\''.$profile['service'].'\''.$str; // Database name may be given, even if service is used @@ -47,11 +48,11 @@ function pgSqlConnect ($profile) if (isset($profile['database']) && $profile['database'] != '') { $str .= ' dbname=\''.$profile['database'].'\''; } - } - else { + } else { // we do a distinction because if the host is given == TCP/IP connection else unix socket - if($profile['host'] != '') + if ($profile['host'] != '') { $str = 'host=\''.$profile['host'].'\''.$str; + } if (isset($profile['port'])) { $str .= ' port=\''.$profile['port'].'\''; @@ -82,16 +83,17 @@ function pgSqlConnect ($profile) if (isset($profile['force_new']) && $profile['force_new']) { $cnx = pg_connect($str, PGSQL_CONNECT_FORCE_NEW); - } - else { + } else { $cnx = pg_connect($str); } // let's do the connection if ($cnx) { pg_close($cnx); + return true; } + return false; } @@ -99,12 +101,15 @@ function pgSqlConnect ($profile) * Try to connect to the postgresql database. * * @param IniModifier $profilesConfig - * @param string $profileName The profile to use - * @param int $nbRetries + * @param string $profileName The profile to use + * @param int $nbRetries + * @param mixed $wait + * * @return bool + * * @throws Exception */ -function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $wait=2) +function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries = 10, $wait = 2) { $origProfileName = $profileName; $profileAlias = $profilesConfig->getValue($profileName, 'jdb'); @@ -113,17 +118,18 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w } $profile = $profilesConfig->getValues('jdb:'.$profileName); if ($profile === null) { - throw new Exception("Database profile jdb:$profileName not found"); + throw new Exception("Database profile jdb:{$profileName} not found"); } $profile = (new jDbParameters($profile))->getParameters(); if ($profile['driver'] != 'pgsql') { return true; } $profile['timeout'] = 30; - echo "trying to connect to the Postgresql database ".$profile['database']." at ".$profile['host']." with the profile $origProfileName...\n"; - for($i=0; $i < $nbRetries; $i++) { + echo 'trying to connect to the Postgresql database '.$profile['database'].' at '.$profile['host']." with the profile {$origProfileName}...\n"; + for ($i = 0; $i < $nbRetries; ++$i) { if (pgSqlConnect($profile)) { echo " Ok, Postgresql is alive.\n"; + return true; } // if there is nothing on the host/port, pg_connect fails immediately, @@ -134,28 +140,29 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w } echo "Error: cannot connect to the Postgresql database.\n"; echo "Lizmap cannot starts.\n"; + return false; } /** - * lizmapConfig.ini.php + * lizmapConfig.ini.php. */ -$lizmapConfig = new \Jelix\IniFile\IniModifier('/www/lizmap/var/config/lizmapConfig.ini.php'); +$lizmapConfig = new IniModifier('/www/lizmap/var/config/lizmapConfig.ini.php'); $lizmapConfig->setValue('wmsServerURL', getenv('LIZMAP_WMSSERVERURL'), 'services'); $lizmapConfig->setValue('lizmapPluginAPIURL', getenv('LIZMAP_LIZMAPPLUGINAPIURL'), 'services'); $lizmapConfig->setValue('rootRepositories', getenv('LIZMAP_ROOT_REPOSITORIES'), 'services'); $lizmapConfig->setValue('relativeWMSPath', true, 'services'); -foreach(array( - 'cacheExpiration' => 'LIZMAP_CACHEEXPIRATION', - 'debugMode' => 'LIZMAP_DEBUGMODE', - 'cacheStorageType' => 'LIZMAP_CACHESTORAGETYPE', - 'cacheRedisDb' => 'LIZMAP_CACHEREDISDB', - 'cacheRedisKeyPrefix' => 'LIZMAP_CACHEREDISKEYPREFIX', - 'cacheRedisHost' => 'LIZMAP_CACHEREDISHOST', - 'cacheRedisPort' => 'LIZMAP_CACHEREDISPORT', - ) as $key => $envValue +foreach (array( + 'cacheExpiration' => 'LIZMAP_CACHEEXPIRATION', + 'debugMode' => 'LIZMAP_DEBUGMODE', + 'cacheStorageType' => 'LIZMAP_CACHESTORAGETYPE', + 'cacheRedisDb' => 'LIZMAP_CACHEREDISDB', + 'cacheRedisKeyPrefix' => 'LIZMAP_CACHEREDISKEYPREFIX', + 'cacheRedisHost' => 'LIZMAP_CACHEREDISHOST', + 'cacheRedisPort' => 'LIZMAP_CACHEREDISPORT', +) as $key => $envValue ) { if (getenv($envValue) !== false) { $lizmapConfig->setValue($key, getenv($envValue), 'services'); @@ -174,10 +181,10 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w $lizmapConfig->save(); /** - * localconfig.ini.php + * localconfig.ini.php. */ -$localConfig = new \Jelix\IniFile\IniModifier('/www/lizmap/var/config/localconfig.ini.php'); -$mainConfig = new \Jelix\IniFile\IniModifier('/www/lizmap/app/system/mainconfig.ini.php'); +$localConfig = new IniModifier('/www/lizmap/var/config/localconfig.ini.php'); +$mainConfig = new IniModifier('/www/lizmap/app/system/mainconfig.ini.php'); // Let's modify the install configuration of jcommunity, to not create a default // admin account (no `defaultusers` parameter). We're relying on @@ -186,7 +193,6 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w unset($jCommunityInstallParams['defaultusers']); $localConfig->setValue('jcommunity.installparam', $jCommunityInstallParams, 'modules'); - if ($logger_metric !== false) { $localConfig->setValue('metric', $logger_metric, 'logger'); } @@ -201,8 +207,7 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w if (getenv('LIZMAP_PROXYURL_HTTPS_PORT') !== false) { $config['forceHTTPSPort'] = getenv('LIZMAP_PROXYURL_HTTPS_PORT'); $localConfig->setValue('forceHTTPSPort', getenv('LIZMAP_PROXYURL_HTTPS_PORT')); - } - else { + } else { $localConfig->setValue('forceHTTPSPort', 443); } } @@ -236,7 +241,7 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w $localConfig->save(); /** - * profiles.ini.php + * profiles.ini.php. */ $profilesConfig = new IniModifier('/www/lizmap/var/config/profiles.ini.php'); @@ -260,9 +265,9 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w // its table and so on. // Try with the default profile if (!checkAndWaitPostgresql($profilesConfig, 'default', $retries, $waits)) { - exit (1); + exit(1); } // try with the lizlog profile, it may be a different database. if (!checkAndWaitPostgresql($profilesConfig, 'lizlog', $retries, $waits)) { - exit (1); + exit(1); } diff --git a/extra-modules/lizmapdemo/install/install.php b/extra-modules/lizmapdemo/install/install.php index b5d951e0aa..ae5039ef20 100644 --- a/extra-modules/lizmapdemo/install/install.php +++ b/extra-modules/lizmapdemo/install/install.php @@ -1,4 +1,9 @@ database()->useDbProfile('auth'); // create group - jAcl2DbUserGroup:: createGroup('lizadmins'); - jAcl2DbUserGroup:: createGroup('Intranet demos group', 'intranet'); + jAcl2DbUserGroup::createGroup('lizadmins'); + jAcl2DbUserGroup::createGroup('Intranet demos group', 'intranet'); // create user in jAuth require_once JELIX_LIB_PATH.'auth/jAuth.class.php'; - require_once JELIX_LIB_PATH.'plugins/auth/db/db.auth.php'; - //$configIni = $helpers->getEntryPointsById('index')->getConfigIni(); + require_once JELIX_LIB_PATH.'plugins/auth/db/db.auth.php'; + // $configIni = $helpers->getEntryPointsById('index')->getConfigIni(); - /** @var $authConfig \Jelix\IniFile\IniModifier */ - //list($authConfig, $authSection) = $helpers->getCoordPluginConfig('auth', $configIni); + /** @var \Jelix\IniFile\IniModifier $authConfig */ + // list($authConfig, $authSection) = $helpers->getCoordPluginConfig('auth', $configIni); /*$driver = $authConfig->getValue('driver', $authSection); $driverConfig = $authConfig->getValues($driver);*/ @@ -33,9 +38,9 @@ public function install(Jelix\Installer\Module\API\InstallHelpers $helpers) $authConfig = jAuth::loadConfig(); $driver = $authConfig['driver']; $driverConfig = jAuth::getDriverConfig(); - if ($driver == 'Db' || - (isset($driverConfig['compatiblewithdb']) && - $driverConfig['compatiblewithdb']) + if ($driver == 'Db' + || (isset($driverConfig['compatiblewithdb']) + && $driverConfig['compatiblewithdb']) ) { $daoSelector = $driverConfig['dao']; $daoProfile = $driverConfig['profile']; @@ -130,7 +135,7 @@ public function install(Jelix\Installer\Module\API\InstallHelpers $helpers) // declare the repositories of demo in the configuration $lizmapConfFile = jApp::varConfigPath('lizmapConfig.ini.php'); - $ini = new \Jelix\IniFile\IniModifier($lizmapConfFile); + $ini = new IniModifier($lizmapConfFile); $sourceDemo = realpath(__DIR__.'/../qgis-projects/').'/'; @@ -139,8 +144,7 @@ public function install(Jelix\Installer\Module\API\InstallHelpers $helpers) jFile::copyDirectoryContent($sourceDemo, $rootRepo, true); $demoPath = $rootRepo.'/demoqgis'; $demoIntranetPath = $rootRepo.'/demoqgis_intranet'; - } - else { + } else { $demoPath = $sourceDemo.'demoqgis'; $demoIntranetPath = $sourceDemo.'demoqgis_intranet'; } diff --git a/extra-modules/lizmapdemo/install/install_1_6.php b/extra-modules/lizmapdemo/install/install_1_6.php index f3d27315a2..0f5052f44b 100644 --- a/extra-modules/lizmapdemo/install/install_1_6.php +++ b/extra-modules/lizmapdemo/install/install_1_6.php @@ -1,4 +1,5 @@ useDbProfile('auth'); // create group - jAcl2DbUserGroup:: createGroup('lizadmins'); - jAcl2DbUserGroup:: createGroup('Intranet demos group', 'intranet'); + jAcl2DbUserGroup::createGroup('lizadmins'); + jAcl2DbUserGroup::createGroup('Intranet demos group', 'intranet'); // create user in jAuth require_once JELIX_LIB_PATH.'auth/jAuth.class.php'; + require_once JELIX_LIB_PATH.'plugins/auth/db/db.auth.php'; $authconfig = $this->config->getValue('auth', 'coordplugins'); $confIni = parse_ini_file(jApp::configPath($authconfig), true); $authConfig = jAuth::loadConfig($confIni); $driverConfig = $authConfig[$authConfig['driver']]; - if ($authConfig['driver'] == 'Db' || - (isset($driverConfig['compatiblewithdb']) && - $driverConfig['compatiblewithdb']) + if ($authConfig['driver'] == 'Db' + || (isset($driverConfig['compatiblewithdb']) + && $driverConfig['compatiblewithdb']) ) { $daoSelector = $driverConfig['dao']; $daoProfile = $driverConfig['profile']; @@ -135,8 +137,7 @@ public function install() jFile::copyDirectoryContent($sourceDemo, $rootRepo, true); $demoPath = $rootRepo.'/demoqgis'; $demoIntranetPath = $rootRepo.'/demoqgis_intranet'; - } - else { + } else { $demoPath = $sourceDemo.'demoqgis'; $demoIntranetPath = $sourceDemo.'demoqgis_intranet'; } diff --git a/lizmap/app/system/admin/auth.coord.ini.php b/lizmap/app/system/admin/auth.coord.ini.php index f283e39276..4abc697a93 100644 --- a/lizmap/app/system/admin/auth.coord.ini.php +++ b/lizmap/app/system/admin/auth.coord.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line ;============= Main parameters diff --git a/lizmap/app/system/admin/config.ini.php b/lizmap/app/system/admin/config.ini.php index c2e50c1c76..f6913b7373 100644 --- a/lizmap/app/system/admin/config.ini.php +++ b/lizmap/app/system/admin/config.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line diff --git a/lizmap/app/system/cmdline/auth.coord.ini.php b/lizmap/app/system/cmdline/auth.coord.ini.php index a033913934..15208ab931 100644 --- a/lizmap/app/system/cmdline/auth.coord.ini.php +++ b/lizmap/app/system/cmdline/auth.coord.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line ;============= Main parameters diff --git a/lizmap/app/system/cmdline/script.ini.php b/lizmap/app/system/cmdline/script.ini.php index da5f463a3d..400d754b8f 100644 --- a/lizmap/app/system/cmdline/script.ini.php +++ b/lizmap/app/system/cmdline/script.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line diff --git a/lizmap/app/system/framework.ini.php b/lizmap/app/system/framework.ini.php index f1417d4de6..96141182e2 100644 --- a/lizmap/app/system/framework.ini.php +++ b/lizmap/app/system/framework.ini.php @@ -1,4 +1,4 @@ -; +; ; ============================================================================= ; WARNING: DON'T CHANGE ANYTHING IN THIS FILE. IF YOU WANT TO ADD/ MODIFY SOME ; OPTIONS, SET THEM INTO var/config/localframework.ini.php. diff --git a/lizmap/app/system/index/auth.coord.ini.php b/lizmap/app/system/index/auth.coord.ini.php index 2f2ae1868c..51a01d685a 100644 --- a/lizmap/app/system/index/auth.coord.ini.php +++ b/lizmap/app/system/index/auth.coord.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line ;============= Main parameters diff --git a/lizmap/app/system/index/config.ini.php b/lizmap/app/system/index/config.ini.php index 192fde0ad0..66d6fdb2f7 100644 --- a/lizmap/app/system/index/config.ini.php +++ b/lizmap/app/system/index/config.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line diff --git a/lizmap/app/system/mainconfig.ini.php b/lizmap/app/system/mainconfig.ini.php index f685470c6f..56dce32830 100644 --- a/lizmap/app/system/mainconfig.ini.php +++ b/lizmap/app/system/mainconfig.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line ;this file doesn't list all possible properties. See lib/jelix/core/defaultconfig.ini.php for that diff --git a/lizmap/application.init.php b/lizmap/application.init.php index b7b846607c..06b36bcb10 100644 --- a/lizmap/application.init.php +++ b/lizmap/application.init.php @@ -1,38 +1,39 @@ getArgument('file'); if (!file_exists($file)) { - throw new \Exception('Unknown file'); + throw new Exception('Unknown file'); } $lizmapModulesDir = $input->getArgument('lizmap-modules'); if ($lizmapModulesDir && !file_exists($lizmapModulesDir)) { - throw new \Exception('Unknown lizmap-modules directory'); + throw new Exception('Unknown lizmap-modules directory'); } $composerJson = json_decode(file_get_contents($file), true); if (!is_array($composerJson)) { - throw new \Exception('Bad JSON content into the given file'); + throw new Exception('Bad JSON content into the given file'); } if (!isset($composerJson['require']) || !is_array($composerJson['require'])) { return 0; } - foreach($composerJson['require'] as $packageName => $packageVersion) - { + foreach ($composerJson['require'] as $packageName => $packageVersion) { if (isset(self::$packagesVersions[$packageName])) { $composerJson['require'][$packageName] = self::$packagesVersions[$packageName]; } @@ -106,19 +103,19 @@ protected function execute(InputInterface $input, OutputInterface $output) protected function updateLizmapModules(array &$composerJson, string $lizmapModulesDir) { - $dir = new \DirectoryIterator($lizmapModulesDir); + $dir = new DirectoryIterator($lizmapModulesDir); foreach ($dir as $dirContent) { if (!$dirContent->isDot() && $dirContent->isDir()) { $moduleName = $dirContent->getFilename(); if (isset(self::$moduleDirPackages[$moduleName])) { $package = self::$moduleDirPackages[$moduleName]; - $composerJson['require'][$package] = self::$packagesVersions[$package]; - \Jelix\FileUtilities\Directory::remove($dirContent->getPathname()); + $composerJson['require'][$package] = self::$packagesVersions[$package]; + Directory::remove($dirContent->getPathname()); } } } - unset($dir); - unset($dirContent); + unset($dir, $dirContent); + } } diff --git a/lizmap/install/uninstall/uninstaller.ini.php b/lizmap/install/uninstall/uninstaller.ini.php index fa39568024..286ddbe669 100644 --- a/lizmap/install/uninstall/uninstaller.ini.php +++ b/lizmap/install/uninstall/uninstaller.ini.php @@ -1,3 +1,3 @@ -; +; ; for security reasons , don't remove or modify the first line ; don't modify this file if you don't know what you do. it is generated automatically by jInstaller diff --git a/lizmap/modules/proj4php/classes/proj4php.class.php b/lizmap/modules/proj4php/classes/proj4php.class.php index e0751a7f6b..ee03ad178a 100644 --- a/lizmap/modules/proj4php/classes/proj4php.class.php +++ b/lizmap/modules/proj4php/classes/proj4php.class.php @@ -1,4 +1,5 @@ +; ;for security reasons , don't remove or modify the previous line ;Services diff --git a/lizmap/var/config/localconfig.ini.php.dist b/lizmap/var/config/localconfig.ini.php.dist index c5f5a715aa..4598c16454 100644 --- a/lizmap/var/config/localconfig.ini.php.dist +++ b/lizmap/var/config/localconfig.ini.php.dist @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line ; put here configuration variables that are specific to this installation diff --git a/lizmap/var/config/profiles.ini.php.dist b/lizmap/var/config/profiles.ini.php.dist index 3adbaa61b8..dc303c1825 100644 --- a/lizmap/var/config/profiles.ini.php.dist +++ b/lizmap/var/config/profiles.ini.php.dist @@ -1,4 +1,4 @@ -; +; ;for security reasons, don't remove or modify the first line [jdb] diff --git a/lizmap/www/admin.php b/lizmap/www/admin.php index 6e6b3a4159..c087f91086 100644 --- a/lizmap/www/admin.php +++ b/lizmap/www/admin.php @@ -1,15 +1,17 @@ +; ;for security reasons , don't remove or modify the first line hideSensitiveServicesProperties=0 ;Services diff --git a/tests/docker-conf/phpfpm/localconfig.ini.php b/tests/docker-conf/phpfpm/localconfig.ini.php index ec886f906d..4856344b70 100644 --- a/tests/docker-conf/phpfpm/localconfig.ini.php +++ b/tests/docker-conf/phpfpm/localconfig.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line ; put here configuration variables that are specific to this installation diff --git a/tests/docker-conf/phpfpm/profiles-sqlite.ini.php b/tests/docker-conf/phpfpm/profiles-sqlite.ini.php index d4f9cd626c..60255d607f 100644 --- a/tests/docker-conf/phpfpm/profiles-sqlite.ini.php +++ b/tests/docker-conf/phpfpm/profiles-sqlite.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons, don't remove or modify the first line [jdb] diff --git a/tests/docker-conf/phpfpm/profiles.ini.php b/tests/docker-conf/phpfpm/profiles.ini.php index 0ce98bbe4f..676cb98801 100644 --- a/tests/docker-conf/phpfpm/profiles.ini.php +++ b/tests/docker-conf/phpfpm/profiles.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons, don't remove or modify the first line [jdb] diff --git a/tests/docker-conf/phpfpm/resetpgsql.php b/tests/docker-conf/phpfpm/resetpgsql.php index 547c930e07..cff39c3971 100644 --- a/tests/docker-conf/phpfpm/resetpgsql.php +++ b/tests/docker-conf/phpfpm/resetpgsql.php @@ -3,12 +3,13 @@ echo "Delete all tables from the postgresql database lizmap\n"; $tryAgain = true; -while($tryAgain) { +while ($tryAgain) { $cnx = @pg_connect("host='pgsql' port='5432' dbname='lizmap' user='lizmap' password='lizmap1234!' "); if (!$cnx) { echo " postgresql is not ready yet\n"; sleep(1); + continue; } $tryAgain = false; diff --git a/tests/end2end/playwright/pages/printpage.js b/tests/end2end/playwright/pages/printpage.js index 0e507fd53c..6d5ae6f1b8 100644 --- a/tests/end2end/playwright/pages/printpage.js +++ b/tests/end2end/playwright/pages/printpage.js @@ -80,4 +80,4 @@ export class PrintPage extends ProjectPage { // check message await expect(this.page.locator('div.alert')).toHaveCount(1); } -} \ No newline at end of file +} diff --git a/tests/end2end/playwright/print.spec.js b/tests/end2end/playwright/print.spec.js index d396265636..c10c8f6899 100644 --- a/tests/end2end/playwright/print.spec.js +++ b/tests/end2end/playwright/print.spec.js @@ -426,9 +426,9 @@ test.describe( // opacity notes: // setting the opacity to 60% on `Group_a` causes: - // - `single_wms_points_group` layer to have a final total opacity of 24% (0.4*0.6) + // - `single_wms_points_group` layer to have a final total opacity of 24% (0.4*0.6) // -> OPACITIES PARAM = 255*0.24 ~= 61 - // - `single_wms_polygons_group_as_layer` layer to have a final total opacity of 48% (0.8*0.6) + // - `single_wms_polygons_group_as_layer` layer to have a final total opacity of 48% (0.8*0.6) // -> OPACITIES PARAM = 255*0.48 ~= 122 // other layers have opacity 100%, except for `raster` layer which has a 80% opacity by default, // resulting in a OPACITIES PARAM = 255*0.8 = 204 diff --git a/tests/units/bootstrap.php b/tests/units/bootstrap.php index 7a196c5f08..35fb232a64 100644 --- a/tests/units/bootstrap.php +++ b/tests/units/bootstrap.php @@ -1,16 +1,17 @@ version; ini_set('user_agent', $userAgent); diff --git a/tests/units/classes/App/FileToolsTest.php b/tests/units/classes/App/FileToolsTest.php index 31614588de..a29945c0aa 100644 --- a/tests/units/classes/App/FileToolsTest.php +++ b/tests/units/classes/App/FileToolsTest.php @@ -1,11 +1,17 @@ $value) { @@ -24,7 +28,8 @@ public function arrayToXml(array $array, SimpleXMLElement &$xml) } } - function testXmlFromString(): void { + public function testXmlFromString(): void + { $data = array( 'properties' => array( 'WMSServiceTitle' => 'title', @@ -61,7 +66,8 @@ function testXmlFromString(): void { $this->assertStringContainsString('Fatal', $xml); } - function testXmlFromFile(): void { + public function testXmlFromFile(): void + { $xml_path = __DIR__.'/../Project/Ressources/WMSInfotest.qgs'; $xml = App\XmlTools::xmlFromFile($xml_path); @@ -78,7 +84,8 @@ function testXmlFromFile(): void { $this->assertStringContainsString('Fatal', $xml); } - function testXmlReaderFromString(): void { + public function testXmlReaderFromString(): void + { $data = array( 'properties' => array( 'WMSServiceTitle' => 'title', @@ -103,20 +110,20 @@ function testXmlReaderFromString(): void { $xml = App\XmlTools::xmlReaderFromString($xml_str); $this->assertTrue(is_object($xml)); $this->assertEquals($xml_str, ''."\n".$xml->readOuterXml()."\n"); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('qgis', $xml->localName); $this->assertEquals(0, $xml->depth); // first child element $xml->read(); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('properties', $xml->localName); $this->assertEquals(1, $xml->depth); // Go to next sibling $xml->next(); // No sibling we are at the end of the parent element - $this->assertEquals(\XMLReader::END_ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::END_ELEMENT, $xml->nodeType); $this->assertEquals('qgis', $xml->localName); $this->assertEquals(0, $xml->depth); @@ -127,17 +134,17 @@ function testXmlReaderFromString(): void { $xml = App\XmlTools::xmlReaderFromString($xml_str_invalid); $this->assertTrue(is_object($xml)); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('qgis', $xml->localName); // The validate parser option must be enabled for // this method to work properly - $xml->setParserProperty(\XMLReader::VALIDATE, true); + $xml->setParserProperty(XMLReader::VALIDATE, true); $this->assertTrue($xml->isValid()); // first child element $xml->read(); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('properties', $xml->localName); $this->assertEquals(1, $xml->depth); @@ -147,41 +154,43 @@ function testXmlReaderFromString(): void { // But the XML is invalid here $this->assertFalse($xml->isValid()); // And we are some where else - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('WMSContactPerson', $xml->localName); $this->assertEquals(2, $xml->depth); } - function testXmlReaderFromStringException(): void { + public function testXmlReaderFromStringException(): void + { $this->expectExceptionMessage('Fatal Error 5: Line: 1 Column: 7 Extra content at the end of the document'); App\XmlTools::xmlReaderFromString(''); } - function testXmlReaderFromFile(): void { + public function testXmlReaderFromFile(): void + { $xml_path = __DIR__.'/../Project/Ressources/WMSInfotest.qgs'; // Open the document with XML Reader at the root element document $xml = App\XmlTools::xmlReaderFromFile($xml_path); $this->assertTrue(is_object($xml)); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('qgis', $xml->localName); $this->assertEquals(0, $xml->depth); // next element $xml->read(); - $this->assertEquals(\XMLReader::SIGNIFICANT_WHITESPACE, $xml->nodeType); + $this->assertEquals(XMLReader::SIGNIFICANT_WHITESPACE, $xml->nodeType); // next element $xml->read(); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('homePath', $xml->localName); $this->assertEquals(1, $xml->depth); // Go to next sibling $xml->next(); - $this->assertEquals(\XMLReader::SIGNIFICANT_WHITESPACE, $xml->nodeType); + $this->assertEquals(XMLReader::SIGNIFICANT_WHITESPACE, $xml->nodeType); // Go to next sibling $xml->next(); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('title', $xml->localName); $this->assertEquals(1, $xml->depth); @@ -190,30 +199,30 @@ function testXmlReaderFromFile(): void { // Open the document with XML Reader at the root element document $xml = App\XmlTools::xmlReaderFromFile($xml_path_invalid); $this->assertTrue(is_object($xml)); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('qgis', $xml->localName); $this->assertEquals(0, $xml->depth); // The validate parser option must be enabled for // this method to work properly - $xml->setParserProperty(\XMLReader::VALIDATE, true); + $xml->setParserProperty(XMLReader::VALIDATE, true); $this->assertTrue($xml->isValid()); // next element $xml->read(); - $this->assertEquals(\XMLReader::SIGNIFICANT_WHITESPACE, $xml->nodeType); + $this->assertEquals(XMLReader::SIGNIFICANT_WHITESPACE, $xml->nodeType); // next element $xml->read(); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('homePath', $xml->localName); $this->assertEquals(1, $xml->depth); // Go to next sibling $xml->next(); - $this->assertEquals(\XMLReader::SIGNIFICANT_WHITESPACE, $xml->nodeType); + $this->assertEquals(XMLReader::SIGNIFICANT_WHITESPACE, $xml->nodeType); // Go to next sibling $xml->next(); - $this->assertEquals(\XMLReader::ELEMENT, $xml->nodeType); + $this->assertEquals(XMLReader::ELEMENT, $xml->nodeType); $this->assertEquals('title', $xml->localName); $this->assertEquals(1, $xml->depth); } diff --git a/tests/units/classes/Form/QgisFormControlPropertiesTest.php b/tests/units/classes/Form/QgisFormControlPropertiesTest.php index 437d6931f4..6c0ee82a36 100644 --- a/tests/units/classes/Form/QgisFormControlPropertiesTest.php +++ b/tests/units/classes/Form/QgisFormControlPropertiesTest.php @@ -1,18 +1,20 @@ false, 'UseHtml' => false, - 'Editable' => true + 'Editable' => true, ) ); $this->assertTrue($properties->isEditable()); - # TextEdit - not editable + // TextEdit - not editable $properties = new QgisFormControlProperties( 'id', 'TextEdit', @@ -33,12 +35,12 @@ function testIsEditable(): void { array( 'IsMultiline' => false, 'UseHtml' => false, - 'Editable' => false + 'Editable' => false, ) ); $this->assertFalse($properties->isEditable()); - # TextEdit - field editable + // TextEdit - field editable $properties = new QgisFormControlProperties( 'id', 'TextEdit', @@ -46,12 +48,12 @@ function testIsEditable(): void { array( 'IsMultiline' => false, 'UseHtml' => false, - 'fieldEditable' => true + 'fieldEditable' => true, ) ); $this->assertTrue($properties->isEditable()); - # TextEdit - field not editable + // TextEdit - field not editable $properties = new QgisFormControlProperties( 'id', 'TextEdit', @@ -59,51 +61,52 @@ function testIsEditable(): void { array( 'IsMultiline' => false, 'UseHtml' => false, - 'fieldEditable' => false + 'fieldEditable' => false, ) ); $this->assertFalse($properties->isEditable()); - # UniqueValues - editable + // UniqueValues - editable $properties = new QgisFormControlProperties( 'author', 'UniqueValues', 'input', array( - 'Editable' => true + 'Editable' => true, ) ); $this->assertTrue($properties->isEditable()); - # UniqueValues - not editable + // UniqueValues - not editable $properties = new QgisFormControlProperties( 'author', 'UniqueValues', 'input', array( - 'Editable' => false + 'Editable' => false, ) ); $this->assertFalse($properties->isEditable()); - # ValueMap + // ValueMap $properties = new QgisFormControlProperties( 'checked', 'ValueMap', 'menulist', array( 'valueMap' => array( - 'true' => 'Yes', - 'false' => 'No', - '{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}' => '', + 'true' => 'Yes', + 'false' => 'No', + '{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}' => '', ), - 'Editable' => 1 + 'Editable' => 1, ) ); $this->assertTrue($properties->isEditable()); } - function testGetEditAttribute(): void { + public function testGetEditAttribute(): void + { $properties = new QgisFormControlProperties( 'risque', @@ -130,7 +133,8 @@ function testGetEditAttribute(): void { $this->assertEquals($properties->getEditAttribute('referencedlayerid'), 'risque_66cb8d43_86b7_4583_9217_f7ead54463c3'); } - function testGetValueRelationData(): void { + public function testGetValueRelationData(): void + { $properties = new QgisFormControlProperties( 'tram_id', @@ -162,7 +166,8 @@ function testGetValueRelationData(): void { $this->assertTrue($valueRelationData['fieldEditable']); } - function testGetRelationReference(): void { + public function testGetRelationReference(): void + { $properties = new QgisFormControlProperties( 'risque', @@ -186,14 +191,14 @@ function testGetRelationReference(): void { $this->assertFalse($relationReferenceData['mapIdentification']); $this->assertTrue(is_array($relationReferenceData['filters'])); $this->assertCount(0, $relationReferenceData['filters']); - $this->assertEquals($relationReferenceData['filterExpression'], Null); + $this->assertEquals($relationReferenceData['filterExpression'], null); $this->assertFalse($relationReferenceData['chainFilters']); $this->assertEquals($relationReferenceData['referencedLayerName'], 'risque'); $this->assertEquals($relationReferenceData['referencedLayerId'], 'risque_66cb8d43_86b7_4583_9217_f7ead54463c3'); - # AllowNULL / not AllowNull - # referencedLayerName / not ReferencedLayerName - # referencedLayerId / not ReferencedLayerId + // AllowNULL / not AllowNull + // referencedLayerName / not ReferencedLayerName + // referencedLayerId / not ReferencedLayerId $properties = new QgisFormControlProperties( 'risque', 'RelationReference', @@ -216,7 +221,7 @@ function testGetRelationReference(): void { $this->assertFalse($relationReferenceData['mapIdentification']); $this->assertTrue(is_array($relationReferenceData['filters'])); $this->assertCount(0, $relationReferenceData['filters']); - $this->assertEquals($relationReferenceData['filterExpression'], Null); + $this->assertEquals($relationReferenceData['filterExpression'], null); $this->assertFalse($relationReferenceData['chainFilters']); $this->assertEquals($relationReferenceData['referencedLayerName'], 'risque'); $this->assertEquals($relationReferenceData['referencedLayerId'], 'risque_66cb8d43_86b7_4583_9217_f7ead54463c3'); diff --git a/tests/units/classes/Form/QgisFormControlTest.php b/tests/units/classes/Form/QgisFormControlTest.php index ad1217eab5..5d852da2ef 100644 --- a/tests/units/classes/Form/QgisFormControlTest.php +++ b/tests/units/classes/Form/QgisFormControlTest.php @@ -1,29 +1,30 @@ datatype = new \jDatatypeDecimal(); - + $ctrl = new jFormsControlInput('test'); + $ctrl->datatype = new jDatatypeDecimal(); $control = new QgisFormControlForTests(); - $properties = new \Lizmap\Form\QgisFormControlProperties( + $properties = new QgisFormControlProperties( 'test', 'Immutable', 'intput', array( - 'Editable' => true + 'Editable' => true, ) ); $control->fieldDataType = 'Immutable'; @@ -34,13 +35,13 @@ public function testSetControlMainProperties(): void $this->assertTrue($control->isReadOnly); $this->assertFalse($control->required); - $control->ctrl->datatype = new \jDatatypeString(); - $properties = new \Lizmap\Form\QgisFormControlProperties( + $control->ctrl->datatype = new jDatatypeString(); + $properties = new QgisFormControlProperties( 'test', 'TextEdit', 'intput', array( - 'Editable' => false + 'Editable' => false, ) ); $control->fieldDataType = 'date'; @@ -50,15 +51,15 @@ public function testSetControlMainProperties(): void $this->assertFalse($control->required); $this->assertInstanceOf(jDatatypeDate::class, $control->ctrl->datatype); - $properties = new \Lizmap\Form\QgisFormControlProperties( + $properties = new QgisFormControlProperties( 'test', 'TextEdit', 'intput', array( - 'Editable' => true + 'Editable' => true, ) ); - $control->ctrl->datatype = new \jDatatypeString(); + $control->ctrl->datatype = new jDatatypeString(); $control->fieldDataType = 'decimal'; $control->isReadOnly = false; $control->required = true; @@ -72,13 +73,13 @@ public function testSetControlMainProperties(): void public function testConstructGeometry(): void { $appContext = new ContextForTests(); - # DB properties - Point + // DB properties - Point $prop = (object) array( 'type' => 'Point', - 'autoIncrement' => False, - 'notNull' => True, + 'autoIncrement' => false, + 'notNull' => true, ); - # QGIS Constraints + // QGIS Constraints $constraints = array( 'constraints' => 0, 'notNull' => false, @@ -95,42 +96,42 @@ public function testConstructGeometry(): void $this->assertFalse($control->isReadOnly); $this->assertTrue($control->required); - # DB properties - MultiPoint + // DB properties - MultiPoint $prop->type = 'MultiPoint'; $control = new QgisFormControl('geom', null, $prop, null, $constraints, $appContext); $this->assertEquals($control->fieldDataType, 'geometry'); - # DB properties - LINE + // DB properties - LINE $prop->type = 'LINE'; $control = new QgisFormControl('geom', null, $prop, null, $constraints, $appContext); $this->assertEquals($control->fieldDataType, 'geometry'); - # DB properties - LineString + // DB properties - LineString $prop->type = 'LineString'; $control = new QgisFormControl('geom', null, $prop, null, $constraints, $appContext); $this->assertEquals($control->fieldDataType, 'geometry'); - # DB properties - MultiLineString + // DB properties - MultiLineString $prop->type = 'MultiLineString'; $control = new QgisFormControl('geom', null, $prop, null, $constraints, $appContext); $this->assertEquals($control->fieldDataType, 'geometry'); - # DB properties - Polygon + // DB properties - Polygon $prop->type = 'Polygon'; $control = new QgisFormControl('geom', null, $prop, null, $constraints, $appContext); $this->assertEquals($control->fieldDataType, 'geometry'); - # DB properties - MultiPolygon + // DB properties - MultiPolygon $prop->type = 'MultiPolygon'; $control = new QgisFormControl('geom', null, $prop, null, $constraints, $appContext); $this->assertEquals($control->fieldDataType, 'geometry'); - # DB properties - Geometry + // DB properties - Geometry $prop->type = 'Geometry'; $control = new QgisFormControl('geom', null, $prop, null, $constraints, $appContext); $this->assertEquals($control->fieldDataType, 'geometry'); - # DB properties - GeometryCollection + // DB properties - GeometryCollection $prop->type = 'GeometryCollection'; $control = new QgisFormControl('geom', null, $prop, null, $constraints, $appContext); $this->assertEquals($control->fieldDataType, 'geometry'); @@ -139,28 +140,28 @@ public function testConstructGeometry(): void public function testConstructPrimaryKey(): void { $appContext = new ContextForTests(); - # DB properties - Text + // DB properties - Text $prop = (object) array( 'type' => 'int', - 'autoIncrement' => True, - 'notNull' => True, + 'autoIncrement' => true, + 'notNull' => true, ); - # QGIS properties - $properties = new \Lizmap\Form\QgisFormControlProperties( + // QGIS properties + $properties = new QgisFormControlProperties( 'id', 'TextEdit', 'input', array( 'IsMultiline' => false, 'UseHtml' => false, - 'Editable' => true + 'Editable' => true, ) ); - # QGIS Constraints - # constraints is the number of contraints, 0 for no constraints - # notNull defined if the not null contraint is activated - # unique defined if the unique contraint is activated - # exp defined if the expression contraint is activated + // QGIS Constraints + // constraints is the number of contraints, 0 for no constraints + // notNull defined if the not null contraint is activated + // unique defined if the unique contraint is activated + // exp defined if the expression contraint is activated $constraints = array( 'constraints' => 0, 'notNull' => false, @@ -177,15 +178,15 @@ public function testConstructPrimaryKey(): void $this->assertFalse($control->isReadOnly); $this->assertFalse($control->required); - # QGIS properties - not editable - $properties = new \Lizmap\Form\QgisFormControlProperties( + // QGIS properties - not editable + $properties = new QgisFormControlProperties( 'id', 'TextEdit', 'input', array( 'IsMultiline' => false, 'UseHtml' => false, - 'Editable' => false + 'Editable' => false, ) ); $control = new QgisFormControl('id', $properties, $prop, null, $constraints, $appContext); @@ -196,28 +197,28 @@ public function testConstructPrimaryKey(): void public function testConstructInput(): void { $appContext = new ContextForTests(); - # DB properties - Text + // DB properties - Text $prop = (object) array( 'type' => 'text', - 'autoIncrement' => False, - 'notNull' => False, + 'autoIncrement' => false, + 'notNull' => false, ); - # QGIS properties - $properties = new \Lizmap\Form\QgisFormControlProperties( + // QGIS properties + $properties = new QgisFormControlProperties( 'label', 'TextEdit', 'input', array( 'IsMultiline' => false, 'UseHtml' => false, - 'Editable' => true + 'Editable' => true, ) ); - # QGIS Constraints - # constraints is the number of contraints, 0 for no constraints - # notNull defined if the not null contraint is activated - # unique defined if the unique contraint is activated - # exp defined if the expression contraint is activated + // QGIS Constraints + // constraints is the number of contraints, 0 for no constraints + // notNull defined if the not null contraint is activated + // unique defined if the unique contraint is activated + // exp defined if the expression contraint is activated $constraints = array( 'constraints' => 0, 'notNull' => false, @@ -234,38 +235,38 @@ public function testConstructInput(): void $this->assertFalse($control->isReadOnly); $this->assertFalse($control->required); - # DB properties - Text - not null - $prop->notNull = True; - # QGIS constraints + // DB properties - Text - not null + $prop->notNull = true; + // QGIS constraints $constraints['constraints'] = 0; - $constraints['notNull'] = False; + $constraints['notNull'] = false; $control = new QgisFormControl('label', $properties, $prop, null, $constraints, $appContext); $this->assertTrue($control->required); - # DB properties - Text - $prop->notNull = False; - # QGIS constraints - not null + // DB properties - Text + $prop->notNull = false; + // QGIS constraints - not null $constraints['constraints'] = 1; - $constraints['notNull'] = True; + $constraints['notNull'] = true; $control = new QgisFormControl('label', $properties, $prop, null, $constraints, $appContext); $this->assertTrue($control->required); - # DB properties - Text - $prop->notNull = False; - # QGIS properties - $properties = new \Lizmap\Form\QgisFormControlProperties( + // DB properties - Text + $prop->notNull = false; + // QGIS properties + $properties = new QgisFormControlProperties( 'label', 'TextEdit', 'input', array( 'IsMultiline' => false, 'UseHtml' => false, - 'Editable' => false + 'Editable' => false, ) ); - # QGIS constraints + // QGIS constraints $constraints['constraints'] = 0; - $constraints['notNull'] = False; + $constraints['notNull'] = false; $control = new QgisFormControl('label', $properties, $prop, null, $constraints, $appContext); $this->assertTrue($control->isReadOnly); $this->assertFalse($control->required); @@ -274,14 +275,14 @@ public function testConstructInput(): void public function testConstructCheckbox(): void { $appContext = new ContextForTests(); - # DB properties - Bool + // DB properties - Bool $prop = (object) array( 'type' => 'bool', - 'autoIncrement' => False, - 'notNull' => True, + 'autoIncrement' => false, + 'notNull' => true, ); - # QGIS properties - $properties = new \Lizmap\Form\QgisFormControlProperties( + // QGIS properties + $properties = new QgisFormControlProperties( 'checked', 'CheckBox', 'checkbox', @@ -290,7 +291,7 @@ public function testConstructCheckbox(): void 'UncheckedState' => 'f', ) ); - # QGIS Constraints + // QGIS Constraints $constraints = array( 'constraints' => 0, 'notNull' => false, @@ -309,10 +310,10 @@ public function testConstructCheckbox(): void $this->assertFalse($control->isReadOnly); $this->assertFalse($control->required); - # DB properties - int + // DB properties - int $prop->type = 'int'; - # QGIS properties - $properties = new \Lizmap\Form\QgisFormControlProperties( + // QGIS properties + $properties = new QgisFormControlProperties( 'checked', 'CheckBox', 'checkbox', @@ -327,10 +328,10 @@ public function testConstructCheckbox(): void $this->assertEquals($control->ctrl->valueOnCheck, '1'); $this->assertEquals($control->ctrl->valueOnUncheck, '0'); - # DB properties - text + // DB properties - text $prop->type = 'text'; - # QGIS properties - $properties = new \Lizmap\Form\QgisFormControlProperties( + // QGIS properties + $properties = new QgisFormControlProperties( 'checked', 'CheckBox', 'checkbox', @@ -345,21 +346,21 @@ public function testConstructCheckbox(): void $this->assertEquals($control->ctrl->valueOnCheck, 'y'); $this->assertEquals($control->ctrl->valueOnUncheck, 'n'); - # Test Rework ValueMap to CheckBox for nor null boolean field + // Test Rework ValueMap to CheckBox for nor null boolean field $prop->type = 'boolean'; - $prop->notNull = True; - # QGIS properties - $properties = new \Lizmap\Form\QgisFormControlProperties( + $prop->notNull = true; + // QGIS properties + $properties = new QgisFormControlProperties( 'checked', 'ValueMap', 'menulist', array( 'valueMap' => array( - 'true' => 'Yes', - 'false' => 'No', - '{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}' => '', + 'true' => 'Yes', + 'false' => 'No', + '{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}' => '', ), - 'Editable' => 1 + 'Editable' => 1, ) ); diff --git a/tests/units/classes/Form/QgisFormTest.php b/tests/units/classes/Form/QgisFormTest.php index 62da9aa9f9..c1872dd1d0 100644 --- a/tests/units/classes/Form/QgisFormTest.php +++ b/tests/units/classes/Form/QgisFormTest.php @@ -1,7 +1,9 @@ check; } - public function addControl() - { - } + public function addControl() {} - public function setReadOnly() - { - } + public function setReadOnly() {} public function getSelector() { @@ -42,9 +40,7 @@ public function getData() return $this->data; } - public function setErrorOn() - { - } + public function setErrorOn() {} public function getControl($ref) { @@ -52,6 +48,11 @@ public function getControl($ref) } } +/** + * @internal + * + * @coversNothing + */ class QgisFormTest extends TestCase { protected $appContext; @@ -67,9 +68,10 @@ protected function setUpEnv($projectKey, $layerId, $fields) $layer->fields = $fields; $layer->setId($layerId); $proj = new ProjectForTests($appContext); - $proj->setRepo(new \Lizmap\Project\Repository('key', array(), null, null, $appContext)); + $proj->setRepo(new Repository('key', array(), null, null, $appContext)); $proj->setKey($projectKey); $layer->setProject($proj); + return $layer; } @@ -77,8 +79,8 @@ protected function readFormCache($file) { $formCache = json_decode(file_get_contents($file), true); $properties = array(); - foreach($formCache as $ref => $props) { - $prop = new \Lizmap\Form\QgisFormControlProperties( + foreach ($formCache as $ref => $props) { + $prop = new QgisFormControlProperties( $ref, $props['fieldEditType'], $props['markup'], @@ -89,11 +91,10 @@ protected function readFormCache($file) } $properties[$ref] = $prop; } + return $properties; } - - public static function getConstructData() { $fields = (object) array( @@ -126,17 +127,18 @@ public static function getConstructData() ); return array( - array('test','date', $fields), - array('montpellier','line', $fields2), - array('not','existing', null), + array('test', 'date', $fields), + array('montpellier', 'line', $fields2), + array('not', 'existing', null), ); } /** * @dataProvider getConstructData * - * @param mixed $file * @param mixed $fields + * @param mixed $projectKey + * @param mixed $layer */ public function testConstruct($projectKey, $layer, $fields): void { @@ -193,7 +195,7 @@ public function testGetAttributeEditorForm(): void $form->setFormName(null); $attributeForm = $form->getAttributesEditorForm(); $this->assertNotNull($attributeForm); - $this->assertInstanceOf(\qgisAttributeEditorElement::class, $attributeForm); + $this->assertInstanceOf(qgisAttributeEditorElement::class, $attributeForm); $form->setFormName(null); $form->setLayer($layerFalse); $attributeForm = $form->getAttributesEditorForm(); @@ -255,6 +257,7 @@ public static function getCheckData() * @param mixed $evaluateExpression * @param mixed $constraints * @param mixed $expectedResult + * @param mixed $allowWithoutGeom */ public function testCheck($dbFieldsInfo, $check, $data, $evaluateExpression, $constraints, $allowWithoutGeom, $expectedResult): void { @@ -263,7 +266,7 @@ public function testCheck($dbFieldsInfo, $check, $data, $evaluateExpression, $co foreach ($mockFuncs as $method) { if ($method === 'evaluateExpression') { $formMock->method($method)->willReturn($evaluateExpression); - } else if ($method === 'getConstraints') { + } elseif ($method === 'getConstraints') { $formMock->method($method)->willReturn($constraints); } else { $formMock->method($method)->willReturn(null); @@ -275,17 +278,17 @@ public function testCheck($dbFieldsInfo, $check, $data, $evaluateExpression, $co $jForm->check = $check; $jForm->data = $data; $jForm->controls = array(); - foreach(array_keys((array)$dbFieldsInfo->dataFields) as $key) { - $jForm->controls[$key] = new \jFormsControlInput($key); + foreach (array_keys((array) $dbFieldsInfo->dataFields) as $key) { + $jForm->controls[$key] = new jFormsControlInput($key); } $layer = new QgisLayerForTests(); $layer->eCapabilities = (object) array('capabilities' => (object) array('modifyGeometry' => 'True', 'allow_without_geom' => $allowWithoutGeom)); $layer->dbFieldValues = array(); - $testCfg = new Project\ProjectConfig(new StdClass()); + $testCfg = new Project\ProjectConfig(new stdClass()); $proj = new ProjectForTests(); - $proj->setRepo(new \Lizmap\Project\Repository('key', array(), null, null, null)); + $proj->setRepo(new Repository('key', array(), null, null, null)); $proj->setCfg($testCfg); $layer->setProject($proj); @@ -305,9 +308,9 @@ public function testSaveToDbInsert(): void 'geometryColumn' => 'geometry', ); $controls = array( - 'pkuid' => new \jFormsControlInput('pkuid'), - 'field' => new \jFormsControlInput('field'), - 'geometry' => new \jFormsControlInput('geometry'), + 'pkuid' => new jFormsControlInput('pkuid'), + 'field' => new jFormsControlInput('field'), + 'geometry' => new jFormsControlInput('geometry'), ); $values = array( 'pkuid' => true, @@ -341,9 +344,9 @@ public function testSaveToDbUpdate(): void 'geometryColumn' => 'geometry', ); $controls = array( - 'pkuid' => new \jFormsControlInput('pkuid'), - 'field' => new \jFormsControlInput('field'), - 'geometry' => new \jFormsControlUpload('geometry'), + 'pkuid' => new jFormsControlInput('pkuid'), + 'field' => new jFormsControlInput('field'), + 'geometry' => new jFormsControlUpload('geometry'), ); $values = array( 'pkuid' => true, diff --git a/tests/units/classes/Log/ConfigTest.php b/tests/units/classes/Log/ConfigTest.php index bc635d2377..bda860660d 100644 --- a/tests/units/classes/Log/ConfigTest.php +++ b/tests/units/classes/Log/ConfigTest.php @@ -1,17 +1,20 @@ context) { return; @@ -105,7 +108,7 @@ public function testSave($data, $expectedData, $changedProp, $changedValue, $exp $iniFile = __DIR__.'/../../tmp/logConfig.ini.php'; file_put_contents($iniFile, ''); - $ini = new \Jelix\IniFile\IniModifier($iniFile); + $ini = new IniModifier($iniFile); $testLizmapLogConfig = new ConfigForTests($data, $this->context, $iniFile); if ($changedProp) { $data['general'][$changedProp] = $changedValue; diff --git a/tests/units/classes/Log/ItemTest.php b/tests/units/classes/Log/ItemTest.php index bb143a6429..9d46965900 100644 --- a/tests/units/classes/Log/ItemTest.php +++ b/tests/units/classes/Log/ItemTest.php @@ -3,11 +3,16 @@ use Lizmap\Logger as Log; use PHPUnit\Framework\TestCase; +/** + * @internal + * + * @coversNothing + */ class ItemTest extends TestCase { - protected $context = null; + protected $context; - public function setUp() : void + public function setUp(): void { if (!$this->context) { $this->context = new ContextForTests(); @@ -22,12 +27,13 @@ public static function getConstructData() 'logDetail' => 'detail', 'logIp' => 'Ip', 'logEmail' => 'Email', - 'unknownProp' => 'whatever' + 'unknownProp' => 'whatever', ); $data2 = array( 'label' => 'test', - 'logCounter' => null + 'logCounter' => null, ); + return array( array($data1), array($data2), @@ -37,6 +43,8 @@ public static function getConstructData() /** * @dataProvider getConstructData + * + * @param mixed $config */ public function testConstruct($config): void { @@ -64,8 +72,9 @@ public static function getLogDetailData() ); $data2 = array( 'key' => '1234', - 'unknownProp' => 'test' + 'unknownProp' => 'test', ); + return array( array($data1), array($data1), @@ -76,13 +85,15 @@ public static function getLogDetailData() /** * @dataProvider getLogDetailData + * + * @param mixed $data */ public function testInsertLogDetail($data): void { $context = new ContextForTests(); $context->setResult(array( 'getDao' => $context, - 'createDaoRecord' => (object)array( + 'createDaoRecord' => (object) array( 'key' => null, 'user' => null, 'content' => null, @@ -90,7 +101,7 @@ public function testInsertLogDetail($data): void 'project' => null, 'ip' => null, 'email' => null, - ) + ), )); $item = new Log\Item('test', array(), $context); $item->insertLogDetail($data); @@ -103,16 +114,15 @@ public function testInsertLogDetail($data): void $this->assertNull($resultRecord->project); $this->assertNull($resultRecord->ip); $this->assertNull($resultRecord->email); - return ; - } + return; + } foreach ($data as $key => $value) { if (in_array($key, $item->getRecordKeys())) { - $this->assertEquals($value, $resultRecord->$key); - } - else { - $this->assertFalse(isset($resultRecord->$key)); + $this->assertEquals($value, $resultRecord->{$key}); + } else { + $this->assertFalse(isset($resultRecord->{$key})); } } } diff --git a/tests/units/classes/Project/ProjectConfigTest.php b/tests/units/classes/Project/ProjectConfigTest.php index e87393d80d..920a5db231 100644 --- a/tests/units/classes/Project/ProjectConfigTest.php +++ b/tests/units/classes/Project/ProjectConfigTest.php @@ -1,9 +1,11 @@ metadata = new stdClass(); $expected->layouts = new stdClass(); $expected->warnings = new stdClass(); + return array( array($json, $expected), ); @@ -50,7 +53,7 @@ public function testConstructCache(): void foreach ($cachedProperties as $prop) { if (property_exists($data, $prop)) { $meth = 'get'.ucfirst($prop); - $this->assertEquals($data->$prop, $testCfg->$meth(), 'failed Prop = '.$prop); + $this->assertEquals($data->{$prop}, $testCfg->{$meth}(), 'failed Prop = '.$prop); } } } @@ -145,7 +148,7 @@ public function testGetEditionLayerByLayerId($eLayers, $id, $eLayerName): void { $testCfg = new Project\ProjectConfig($eLayers); if ($eLayerName) { - $this->assertSame($eLayers->editionLayers->$eLayerName, $testCfg->getEditionLayerByLayerId($id)); + $this->assertSame($eLayers->editionLayers->{$eLayerName}, $testCfg->getEditionLayerByLayerId($id)); } else { $this->assertNull($testCfg->getEditionLayerByLayerId($id)); } @@ -154,7 +157,7 @@ public function testGetEditionLayerByLayerId($eLayers, $id, $eLayerName): void public static function getOptionsValues() { return array( - array('mapScales', [ + array('mapScales', array( 1000, 2500, 5000, @@ -162,18 +165,18 @@ public static function getOptionsValues() 25000, 50000, 100000, - 150000 - ]), + 150000, + )), array('minScale', 1000), array('maxScale', 150000), - array('initialExtent', [ + array('initialExtent', array( 417006.613738, 5394910.3409, 447158.048911, - 5414844.99481 - ]), - array('osmMapnik', "True"), - array('measure', "True"), + 5414844.99481, + )), + array('osmMapnik', 'True'), + array('measure', 'True'), array('atlasDuration', 5), ); } @@ -192,8 +195,6 @@ public function testGetOption($option, $expectedValue): void $this->assertEquals($expectedValue, $testCfg->getOption($option)); } - /** - */ public function testGetBooleanOption(): void { $file = __DIR__.'/Ressources/events.qgs.cfg'; @@ -204,11 +205,11 @@ public function testGetBooleanOption(): void } /** - * Test an empty project config + * Test an empty project config. */ public function testEmptyConfig(): void { - $testCfg = new Project\ProjectConfig(new StdClass()); + $testCfg = new Project\ProjectConfig(new stdClass()); $this->assertEquals(new stdClass(), $testCfg->getLayers()); $this->assertNull($testCfg->getLayer('SousQuartiers')); $this->assertEquals(new stdClass(), $testCfg->getAttributeLayers()); diff --git a/tests/units/classes/Project/ProjectMainDataTest.php b/tests/units/classes/Project/ProjectMainDataTest.php index c2b3e3ae23..7f39dff1fe 100644 --- a/tests/units/classes/Project/ProjectMainDataTest.php +++ b/tests/units/classes/Project/ProjectMainDataTest.php @@ -1,9 +1,11 @@ assertFalse($p->needsUpdateError()); $this->assertTrue($p->getAcl()); $this->assertFalse($p->getHidden()); - //$this->assertEquals(array(), $p->getData()); + // $this->assertEquals(array(), $p->getData()); $file = __DIR__.'/Ressources/montpellier_intranet.qgs'; $p = new Project\ProjectMainData('tests', 'montpellier_intranet', $file, 30200, $context); diff --git a/tests/units/classes/Project/ProjectTest.php b/tests/units/classes/Project/ProjectTest.php index ee2d86e567..2f80c95536 100644 --- a/tests/units/classes/Project/ProjectTest.php +++ b/tests/units/classes/Project/ProjectTest.php @@ -6,6 +6,7 @@ /** * @internal + * * @coversNothing */ class ProjectTest extends TestCase @@ -83,10 +84,14 @@ public static function getRelativeQgisPathData() public function testGetRelativeQgisPath($relative, $root, $file, $expectedPath): void { $services = new lizmapServices( - array('services' => - array('relativeWMSPath' => $relative, - 'rootRepositories' => $root) - ), (object) array(), false, null, null); + array('services' => array('relativeWMSPath' => $relative, + 'rootRepositories' => $root), + ), + (object) array(), + false, + null, + null + ); $proj = new ProjectForTests(); $proj->setRepo(new Project\Repository(null, array('path' => ''), null, null, null)); $proj->setServices($services); @@ -134,7 +139,7 @@ public static function getAttributeLayersData() */ public function testHasAttributeLayer($only, $attributeLayers, $expectedReturn): void { - $config = new Project\ProjectConfig((object)array('attributeLayers' => $attributeLayers)); + $config = new Project\ProjectConfig((object) array('attributeLayers' => $attributeLayers)); $proj = new ProjectForTests(); $proj->setCfg($config); $this->assertEquals($expectedReturn, $proj->hasAttributeLayers($only)); @@ -272,7 +277,7 @@ public static function getFiltersData() $aclData2 = array( 'userIsConnected' => false, ); - //$filter1 = '"descr" IN ( \'admin\' , \'groups\' , \'lizmap\' , \'all\' )'; + // $filter1 = '"descr" IN ( \'admin\' , \'groups\' , \'lizmap\' , \'all\' )'; $filter1 = '( "descr" = \'admin\' OR "descr" LIKE \'admin,%\' OR "descr" LIKE \'%,admin\' OR "descr" LIKE \'%,admin,%\''; $filter1 .= ' OR '; $filter1 .= '"descr" = \'groups\' OR "descr" LIKE \'groups,%\' OR "descr" LIKE \'%,groups\' OR "descr" LIKE \'%,groups,%\''; @@ -281,7 +286,7 @@ public static function getFiltersData() $filter1 .= ' OR '; $filter1 .= '"descr" = \'all\' OR "descr" LIKE \'all,%\' OR "descr" LIKE \'%,all\' OR "descr" LIKE \'%,all,%\' )'; - //$filter2 = '"Group" = \'all\''; + // $filter2 = '"Group" = \'all\''; $filter2 = '( "descr" = \'all\' OR "descr" LIKE \'all,%\' OR "descr" LIKE \'%,all\' OR "descr" LIKE \'%,all,%\' )'; return array( @@ -311,7 +316,7 @@ public function testGetLoginFilters($aclData, $expectedFilters): void $testQgis->setPath($file); $testQgis->readXMLProjectTest($file); - $cfg = json_decode(file_get_contents( __DIR__.'/Ressources/embed_parent_filtered.qgs.cfg')); + $cfg = json_decode(file_get_contents(__DIR__.'/Ressources/embed_parent_filtered.qgs.cfg')); $config = new Project\ProjectConfig($cfg); $proj->setCfg($config); $proj->setQgis($testQgis); @@ -320,9 +325,11 @@ public function testGetLoginFilters($aclData, $expectedFilters): void // Test $expectedFilters = array( - 'edition_layer_embed_point' => array_merge((array)$cfg->loginFilteredLayers->edition_layer_embed_point, - array('layername' => 'edition_layer_embed_point', - 'filter' => $expectedFilters)), + 'edition_layer_embed_point' => array_merge( + (array) $cfg->loginFilteredLayers->edition_layer_embed_point, + array('layername' => 'edition_layer_embed_point', + 'filter' => $expectedFilters) + ), ); $filters = $proj->getLoginFilters(array('edition_layer_embed_point')); $this->assertEquals($expectedFilters, $filters); @@ -369,7 +376,7 @@ public function testGetLoginFiltersNotMultiple($aclData, $expectedFilters): void $testQgis->setPath($file); $testQgis->readXMLProjectTest($file); - $cfg = json_decode(file_get_contents( __DIR__.'/Ressources/embed_parent_filtered.qgs.cfg')); + $cfg = json_decode(file_get_contents(__DIR__.'/Ressources/embed_parent_filtered.qgs.cfg')); $config = new Project\ProjectConfig($cfg); $proj->setCfg($config); $proj->setQgis($testQgis); @@ -378,9 +385,11 @@ public function testGetLoginFiltersNotMultiple($aclData, $expectedFilters): void // test $expectedFilters = array( - 'edition_layer_embed_line' => array_merge((array)$cfg->loginFilteredLayers->edition_layer_embed_line, - array('layername' => 'edition_layer_embed_line', - 'filter' => $expectedFilters)), + 'edition_layer_embed_line' => array_merge( + (array) $cfg->loginFilteredLayers->edition_layer_embed_line, + array('layername' => 'edition_layer_embed_line', + 'filter' => $expectedFilters) + ), ); $filters = $proj->getLoginFilters(array('edition_layer_embed_line')); $this->assertEquals($expectedFilters, $filters); @@ -489,55 +498,63 @@ public function testCheckAcl($aclData, $options, $expectedRet): void $rep = new Project\Repository('key', array(), null, null, null); $context = new ContextForTests(); $context->setResult($aclData); - $config = new Project\ProjectConfig((object)array('options' => $options)); + $config = new Project\ProjectConfig((object) array('options' => $options)); $proj = new ProjectForTests($context); $proj->setRepo($rep); $proj->setCfg($config); $this->assertEquals($expectedRet, $proj->checkAcl()); } - public static function userFiles4Projets() { + public static function userFiles4Projets() + { $eventsBaseURL = 'view~media:getMedia?repository=repo1&project=events&'; + return array( array( 'montpellier', 'montpellier', array('path' => __DIR__.'/../../../qgis-projects/demoqgis'), array( - 'css'=> array(), + 'css' => array(), 'mjs' => array(), - 'js' => array() - ), + 'js' => array(), ), + ), array( 'events', 'repo1', array('path' => __DIR__.'/Ressources/root4Repository/repo1'), - array('css'=> array( - 'view~media:getCssFile?repository=repo1&project=events&path=media/js/events/style1.css' - ), + array('css' => array( + 'view~media:getCssFile?repository=repo1&project=events&path=media/js/events/style1.css', + ), 'mjs' => array( - 'view~media:getMedia?repository=repo1&project=events&path=media/js/events/mjs.mjs' + 'view~media:getMedia?repository=repo1&project=events&path=media/js/events/mjs.mjs', ), 'js' => array( - $eventsBaseURL.'path=media/js/default/jsdefaultinrepo.js', - $eventsBaseURL.'path=../media/js/default/jsdefaultinroot.js', - $eventsBaseURL.'path=media/js/events/subfolder/jsinsubfolder.js', - $eventsBaseURL.'path=media/js/events/jsprojetinrepo.js', - $eventsBaseURL.'path=../media/js/events/jsprojetinroot.js', - ) - ) - ) - , + $eventsBaseURL.'path=media/js/default/jsdefaultinrepo.js', + $eventsBaseURL.'path=../media/js/default/jsdefaultinroot.js', + $eventsBaseURL.'path=media/js/events/subfolder/jsinsubfolder.js', + $eventsBaseURL.'path=media/js/events/jsprojetinrepo.js', + $eventsBaseURL.'path=../media/js/events/jsprojetinroot.js', + ), + ), + ), ); } /** * @dataProvider userFiles4Projets + * + * @param mixed $repoName */ - public function testFinder(string $projectName, $repoName, array $projectData, array $expectedFiles): void { - $repo = new Project\Repository($repoName, $projectData - , null, null, null + public function testFinder(string $projectName, $repoName, array $projectData, array $expectedFiles): void + { + $repo = new Project\Repository( + $repoName, + $projectData, + null, + null, + null ); $project = new ProjectForTests(); @@ -545,11 +562,10 @@ public function testFinder(string $projectName, $repoName, array $projectData, a $project->setKey($projectName); $finder = new ProjectFilesFinder(); $listFiles = $finder->listFileURLS($project, true); - foreach($listFiles as $fileExt => $list) { + foreach ($listFiles as $fileExt => $list) { // remove mtime=XXX From URLs - $urlsWithoutMtime = array_map( function ($url) { - $urlok = preg_replace('/&mtime=[0-9]*/', '', $url); - return $urlok; + $urlsWithoutMtime = array_map(function ($url) { + return preg_replace('/&mtime=[0-9]*/', '', $url); }, $list); // sorting to ensure list are in same order sort($urlsWithoutMtime); diff --git a/tests/units/classes/Project/Qgis/AttributeTableConfigTest.php b/tests/units/classes/Project/Qgis/AttributeTableConfigTest.php index 6d617a2cc1..326de343f0 100644 --- a/tests/units/classes/Project/Qgis/AttributeTableConfigTest.php +++ b/tests/units/classes/Project/Qgis/AttributeTableConfigTest.php @@ -1,11 +1,12 @@ false, ), ); - foreach($columns as $idx => $data) { - foreach($data as $prop => $value) { - $this->assertEquals($value, $config->columns[$idx]->$prop, $idx.' '.$prop); + foreach ($columns as $idx => $data) { + foreach ($data as $prop => $value) { + $this->assertEquals($value, $config->columns[$idx]->{$prop}, $idx.' '.$prop); } } @@ -175,8 +176,8 @@ public function testFromXmlReader(): void 'name' => 'fid', ), ); - foreach($columns as $idx => $data) { - foreach($data as $prop => $value) { + foreach ($columns as $idx => $data) { + foreach ($data as $prop => $value) { $this->assertEquals($value, $configKeyArray['columns'][$idx][$prop], $idx.' '.$prop); } } diff --git a/tests/units/classes/Project/Qgis/BaseQgisObjectTest.php b/tests/units/classes/Project/Qgis/BaseQgisObjectTest.php index 99b0945cdd..f928be701b 100644 --- a/tests/units/classes/Project/Qgis/BaseQgisObjectTest.php +++ b/tests/units/classes/Project/Qgis/BaseQgisObjectTest.php @@ -1,18 +1,18 @@ The instance properties*/ + /** @var array The instance properties */ protected $properties = array( 'name', 'parent', 'children', ); - /** @var Array The not null properties */ + /** @var array The not null properties */ protected $mandatoryProperties = array( 'name', ); @@ -20,6 +20,7 @@ class Person extends Qgis\BaseQgisObject /** * @internal + * * @coversNothing */ class BaseQgisObjectTest extends TestCase diff --git a/tests/units/classes/Project/Qgis/LayerTreeGroupTest.php b/tests/units/classes/Project/Qgis/LayerTreeGroupTest.php index b8751237ba..f8483d40a8 100644 --- a/tests/units/classes/Project/Qgis/LayerTreeGroupTest.php +++ b/tests/units/classes/Project/Qgis/LayerTreeGroupTest.php @@ -1,18 +1,19 @@