From c45dc2ab1d57f773c5b67b30b19208e889725678 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Wed, 9 Oct 2024 13:20:22 +0200 Subject: [PATCH] [TASK] Add test for sorting the products in product teaser Relates: 205 --- Tests/Acceptance/ProductTeaserCest.php | 12 +++++++++ Tests/Acceptance/Support/Helper.php | 37 ++++++++++++++++++++++++++ Tests/Fixtures/ContentDatabase.php | 4 +-- Tests/Fixtures/ProductsDatabase.php | 24 +++++++++++++++++ codeception.dist.yml | 3 +++ 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 Tests/Acceptance/Support/Helper.php diff --git a/Tests/Acceptance/ProductTeaserCest.php b/Tests/Acceptance/ProductTeaserCest.php index 54fb8e8e..f237fe89 100644 --- a/Tests/Acceptance/ProductTeaserCest.php +++ b/Tests/Acceptance/ProductTeaserCest.php @@ -9,6 +9,7 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\CartProducts\Tests\Acceptance\Support\Helper; use Extcode\CartProducts\Tests\Acceptance\Support\Tester; class ProductTeaserCest @@ -23,6 +24,12 @@ public function testProductTeaserViewForSimpleProducts(Tester $I): void $I->see('19,99 €'); $I->see('Simple Product 3'); $I->see('29,99 €'); + $I->see('Simple Product 5'); + $I->see('29,99 €'); + + $I->seeAboveInPageSource('Simple Product 1', 'Simple Product 2'); + $I->seeAboveInPageSource('Simple Product 2', 'Simple Product 5'); + $I->seeAboveInPageSource('Simple Product 5', 'Simple Product 3'); } public function testTranslatedProductTeaserViewForSimpleProducts(Tester $I): void @@ -33,5 +40,10 @@ public function testTranslatedProductTeaserViewForSimpleProducts(Tester $I): voi $I->see('9,99 €'); $I->see('Einfaches Produkt 3'); $I->see('29,99 €'); + $I->see('Einfaches Produkt 5'); + $I->see('29,99 €'); + + $I->seeAboveInPageSource('Einfaches Produkt 1', 'Einfaches Produkt 5'); + $I->seeAboveInPageSource('Einfaches Produkt 5', 'Einfaches Produkt 3'); } } diff --git a/Tests/Acceptance/Support/Helper.php b/Tests/Acceptance/Support/Helper.php new file mode 100644 index 00000000..85f5ea37 --- /dev/null +++ b/Tests/Acceptance/Support/Helper.php @@ -0,0 +1,37 @@ +getWebDriver()->grabTextFrom('body'); + + $this->assertRegExp("/$above.*$below/s", $text); + } + + private function getWebDriver(): WebDriver + { + $webDriver = $this->moduleContainer->getModule('WebDriver'); + + if (!$webDriver instanceof WebDriver) { + throw new Exception('Could not retrieve WebDriver module.', 1728471395); + } + + return $webDriver; + } +} \ No newline at end of file diff --git a/Tests/Fixtures/ContentDatabase.php b/Tests/Fixtures/ContentDatabase.php index f184a1b7..57b72deb 100644 --- a/Tests/Fixtures/ContentDatabase.php +++ b/Tests/Fixtures/ContentDatabase.php @@ -28,14 +28,14 @@ 'pid' => '11', 'CType' => 'list', 'list_type' => 'cartproducts_teaserproducts', - 'pi_flexform' => 'table1,2,3', + 'pi_flexform' => 'table1,2,10,3', ], 3 => [ 'uid' => '4', 'pid' => '11', 'CType' => 'list', 'list_type' => 'cartproducts_teaserproducts', - 'pi_flexform' => 'table7,9', + 'pi_flexform' => 'table7,11,9', 'sys_language_uid' => 2, 'l18n_parent' => 3, 'l10n_source' => 3, diff --git a/Tests/Fixtures/ProductsDatabase.php b/Tests/Fixtures/ProductsDatabase.php index 740cc7ce..3948dde4 100644 --- a/Tests/Fixtures/ProductsDatabase.php +++ b/Tests/Fixtures/ProductsDatabase.php @@ -112,6 +112,30 @@ 'sys_language_uid' => 2, 'l10n_parent' => 3, ], + 9 => [ + 'uid' => '10', + 'pid' => '7', + 'product_type' => 'simple', + 'sku' => 'simple-product-5', + 'title' => 'Simple Product 5', + 'teaser' => '', + 'description' => '', + 'path_segment' => 'simple-product-5', + 'price' => 29.99, + ], + 10 => [ + 'uid' => '11', + 'pid' => '7', + 'product_type' => 'simple', + 'sku' => 'einfaches-produkt-5', + 'title' => 'Einfaches Produkt 5', + 'teaser' => '', + 'description' => '', + 'path_segment' => 'einfaches-produkt-5', + 'price' => 29.99, + 'sys_language_uid' => 2, + 'l10n_parent' => 10, + ], ], 'tx_cartproducts_domain_model_product_bevariantattribute' => [ 0 => [ diff --git a/codeception.dist.yml b/codeception.dist.yml index 84d2727a..f397d77a 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -40,6 +40,9 @@ suites: moz:firefoxOptions: args: - '-headless' + - + Extcode\CartProducts\Tests\Acceptance\Support\Helper: + depends: 'WebDriver' step_decorators: - 'Codeception\Step\Retry'