From ffbe4b7e33b279d66efcb963dc5006d936baaaf6 Mon Sep 17 00:00:00 2001 From: rmartin Date: Fri, 19 Jan 2024 08:50:21 +0100 Subject: [PATCH 1/2] projet method to test compatibility with version --- lizmap/modules/lizmap/lib/Project/Project.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lizmap/modules/lizmap/lib/Project/Project.php b/lizmap/modules/lizmap/lib/Project/Project.php index fa3412f31e..f5bf351328 100644 --- a/lizmap/modules/lizmap/lib/Project/Project.php +++ b/lizmap/modules/lizmap/lib/Project/Project.php @@ -2313,6 +2313,19 @@ public function needsUpdateWarning() return false; } + /** + * test if provided version (int format 30520). + * + * @param int $targetVersion the desired version (maj.min) as int (00) + */ + public function isCompatibleWithVersion(int $targetVersion): bool + { + // the projet version written for N are supported until N+2 + $maxSupportedVersion = $this->getLizmapWebClientTargetVersion() + 200; + + return $maxSupportedVersion >= $targetVersion; + } + /** * Check acl rights on the project. * From 99d0d7931e34ca48341754c766e8cba9246f830a Mon Sep 17 00:00:00 2001 From: rmartin Date: Fri, 19 Jan 2024 11:02:09 +0100 Subject: [PATCH 2/2] [unit-test] projet:isCompatibleWithVersion --- tests/units/classes/Project/ProjectTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/units/classes/Project/ProjectTest.php b/tests/units/classes/Project/ProjectTest.php index c830ba6d0c..b77691f9f0 100644 --- a/tests/units/classes/Project/ProjectTest.php +++ b/tests/units/classes/Project/ProjectTest.php @@ -411,4 +411,21 @@ public function testCheckAcl($aclData, $options, $expectedRet) $proj->setCfg($config); $this->assertEquals($expectedRet, $proj->checkAcl()); } + + public function testVersion() { + $rep = new Project\Repository('key', array(), null, null, null); + $context = new ContextForTests(); + /** + * no "lizmap_web_client_target_version" value in metadata, + * value will be set as 30200 + */ + $file = __DIR__.'/Ressources/events.qgs.cfg'; + $data = json_decode(file_get_contents($file)); + $config = new Project\ProjectConfig($data); + $proj = new ProjectForTests($context); + $proj->setRepo($rep); + $proj->setCfg($config); + $this->assertTrue($proj->isCompatibleWithVersion(30400), 'n+2 version still compatible'); + $this->assertFalse($proj->isCompatibleWithVersion(30500), '>n+3 version break compatibility'); + } }