Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Pages/v9/BackOffice/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PrestaFlow\Library\Pages\v9\BackOffice;

use PrestaFlow\Library\Pages\Common\BackOffice\Page as BasePage;

class Page extends BasePage
{
}
9 changes: 9 additions & 0 deletions src/Pages/v9/FrontOffice/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PrestaFlow\Library\Pages\v9\FrontOffice;

use PrestaFlow\Library\Pages\Common\FrontOffice\Page as BasePage;

class Page extends BasePage
{
}
4 changes: 3 additions & 1 deletion src/Tests/TestsSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,9 @@ public function loadGlobals()
],
];

$this->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'));
}

Expand Down
6 changes: 6 additions & 0 deletions src/Traits/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
34 changes: 34 additions & 0 deletions tests/Unit/Pages/VersionBasePagesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace PrestaFlow\Tests\Unit\Pages;

use PHPUnit\Framework\TestCase;
use PrestaFlow\Library\Pages\Common\BackOffice\Page as CommonBackOfficePage;
use PrestaFlow\Library\Pages\Common\FrontOffice\Page as CommonFrontOfficePage;

/**
* Every version namespace keeps its area base pages. importPage('FrontOffice')
* resolves to Pages\v<major>\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");
}
}
85 changes: 85 additions & 0 deletions tests/Unit/Tests/SuiteVersionWiringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace PrestaFlow\Tests\Unit\Tests;

use PHPUnit\Framework\TestCase;
use PrestaFlow\Library\Tests\TestsSuite;

/**
* The per-suite version override has to reach a real suite, not only a bare
* trait on which the test calls resolveVersion() itself: loadGlobals() used to
* read PRESTAFLOW_PS_VERSION directly, so $psVersion and onVersion() changed
* nothing and importPage() kept loading the environment's namespace.
*/
final class SuiteVersionWiringTest extends TestCase
{
private ?string $savedEnv = null;

protected function setUp(): void
{
parent::setUp();
$this->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']
);
}
}
Loading