From 37d7a6b8e2cb9469d4838ade5ec1db79e6b46cc6 Mon Sep 17 00:00:00 2001 From: Jonathan Danse Date: Mon, 28 Sep 2026 16:24:17 +0200 Subject: [PATCH] fix(pages): restore the v9 area base pages, and let a suite's own version apply Two defects shipped in 1.8.0. The Common-to-v9 migration deleted Pages\v9\FrontOffice\Page and Pages\v9\BackOffice\Page. importPage('FrontOffice') resolves to the first on PrestaShop 9, so it failed with "Class not found" there, which made VisualTestsSuite unusable on 9, and every custom page extending either class broke. Both are back as thin subclasses of the Common bases, like their v7 and v8 counterparts. $psVersion and onVersion() never reached a real suite: loadGlobals() took PRESTAFLOW_PS_VERSION as is, and only resolveVersion() knows about the overrides. The existing tests called resolveVersion() themselves, so they passed. loadGlobals() now resolves the version, and onVersion() resolves it again once the globals are loaded, so the pages imported next come from the pinned namespace. Co-Authored-By: Claude Opus 5.5 --- src/Pages/v9/BackOffice/Page.php | 9 +++ src/Pages/v9/FrontOffice/Page.php | 9 +++ src/Tests/TestsSuite.php | 4 +- src/Traits/Version.php | 6 ++ tests/Unit/Pages/VersionBasePagesTest.php | 34 +++++++++ tests/Unit/Tests/SuiteVersionWiringTest.php | 85 +++++++++++++++++++++ 6 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 src/Pages/v9/BackOffice/Page.php create mode 100644 src/Pages/v9/FrontOffice/Page.php create mode 100644 tests/Unit/Pages/VersionBasePagesTest.php create mode 100644 tests/Unit/Tests/SuiteVersionWiringTest.php diff --git a/src/Pages/v9/BackOffice/Page.php b/src/Pages/v9/BackOffice/Page.php new file mode 100644 index 0000000..33b015c --- /dev/null +++ b/src/Pages/v9/BackOffice/Page.php @@ -0,0 +1,9 @@ +exctractVersions(Env::get('PRESTAFLOW_PS_VERSION', '8.1.0')); + // Not the environment alone: a suite may pin its version through + // $psVersion or onVersion(), which resolveVersion() lets win. + $this->resolveVersion(); $this->setLocale(Env::get('PRESTAFLOW_LOCALE', 'en')); } diff --git a/src/Traits/Version.php b/src/Traits/Version.php index 6d32b31..cfc5ba5 100644 --- a/src/Traits/Version.php +++ b/src/Traits/Version.php @@ -37,6 +37,12 @@ public function onVersion(string $version): self $this->psVersionOverride = $version; + // Once the globals are loaded, the version has already been resolved: + // resolve it again so the pages imported next use this one. + if (!empty($this->globals)) { + $this->resolveVersion(); + } + return $this; } diff --git a/tests/Unit/Pages/VersionBasePagesTest.php b/tests/Unit/Pages/VersionBasePagesTest.php new file mode 100644 index 0000000..422375e --- /dev/null +++ b/tests/Unit/Pages/VersionBasePagesTest.php @@ -0,0 +1,34 @@ +\FrontOffice\Page, and custom pages extend these + * classes: the v9 pair went missing in the Common-to-v9 migration, which broke + * both on PrestaShop 9 (VisualTestsSuite included). + */ +final class VersionBasePagesTest extends TestCase +{ + public static function areaBases(): array + { + $cases = []; + foreach (['v7', 'v8', 'v9'] as $version) { + $cases["$version FrontOffice"] = ["PrestaFlow\\Library\\Pages\\$version\\FrontOffice\\Page", CommonFrontOfficePage::class]; + $cases["$version BackOffice"] = ["PrestaFlow\\Library\\Pages\\$version\\BackOffice\\Page", CommonBackOfficePage::class]; + } + + return $cases; + } + + /** @dataProvider areaBases */ + public function test_each_version_has_its_area_base_page(string $fqcn, string $parent): void + { + $this->assertTrue(class_exists($fqcn), "$fqcn is missing"); + $this->assertTrue(is_subclass_of($fqcn, $parent), "$fqcn must extend $parent"); + } +} diff --git a/tests/Unit/Tests/SuiteVersionWiringTest.php b/tests/Unit/Tests/SuiteVersionWiringTest.php new file mode 100644 index 0000000..ea74462 --- /dev/null +++ b/tests/Unit/Tests/SuiteVersionWiringTest.php @@ -0,0 +1,85 @@ +savedEnv = $_ENV['PRESTAFLOW_PS_VERSION'] ?? null; + $_ENV['PRESTAFLOW_PS_VERSION'] = '9.0.0'; + putenv('PRESTAFLOW_PS_VERSION=9.0.0'); + } + + protected function tearDown(): void + { + if ($this->savedEnv === null) { + unset($_ENV['PRESTAFLOW_PS_VERSION']); + putenv('PRESTAFLOW_PS_VERSION'); + } else { + $_ENV['PRESTAFLOW_PS_VERSION'] = $this->savedEnv; + putenv('PRESTAFLOW_PS_VERSION=' . $this->savedEnv); + } + parent::tearDown(); + } + + public function test_the_environment_version_applies_without_an_override(): void + { + $suite = new class (loadGlobals: true, getBrowser: false) extends TestsSuite {}; + + $this->assertSame('9', $suite->getMajorVersion(namespace: true)); + $this->assertSame('9.0.0', $suite->getGlobals()['PS_VERSION']); + } + + public function test_the_ps_version_property_wins_over_the_environment(): void + { + $suite = new class (loadGlobals: true, getBrowser: false) extends TestsSuite { + protected $psVersion = '1.7.8.11'; + }; + + $this->assertSame('7', $suite->getMajorVersion(namespace: true)); + $this->assertSame('1.7.8.11', $suite->getGlobals()['PS_VERSION']); + } + + public function test_on_version_takes_effect_without_calling_resolve_version(): void + { + $suite = new class (loadGlobals: true, getBrowser: false) extends TestsSuite {}; + + $suite->onVersion('8.2.0'); + + $this->assertSame('8', $suite->getMajorVersion(namespace: true)); + $this->assertSame('8.2.0', $suite->getGlobals()['PS_VERSION']); + } + + public function test_on_version_in_init_decides_the_namespace_import_page_loads(): void + { + $suite = new class (loadGlobals: true, getBrowser: false) extends TestsSuite { + public function init() + { + $this->onVersion('8.2.0'); + $this->importPage('FrontOffice\Home'); + + return $this; + } + }; + + $suite->init(); + + $this->assertInstanceOf( + \PrestaFlow\Library\Pages\v8\FrontOffice\Home\Page::class, + $suite->pages['frontOfficeHomePage'] + ); + } +}