Skip to content

Commit

Permalink
[TASK] Add test for sorting the products in product teaser
Browse files Browse the repository at this point in the history
Relates: 205
  • Loading branch information
extcode committed Oct 9, 2024
1 parent 9305dad commit c45dc2a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Tests/Acceptance/ProductTeaserCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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');
}
}
37 changes: 37 additions & 0 deletions Tests/Acceptance/Support/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Extcode\CartProducts\Tests\Acceptance\Support;

/*
* This file is part of the package extcode/cart-products.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Codeception\Module;
use Codeception\Module\WebDriver;
use Exception;

class Helper extends Module
{
public function seeAboveInPageSource($above, $below): void
{
$text = $this->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;
}
}
4 changes: 2 additions & 2 deletions Tests/Fixtures/ContentDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
'pid' => '11',
'CType' => 'list',
'list_type' => 'cartproducts_teaserproducts',
'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><T3FlexForms><data><sheet index="sDEF"><language index="lDEF"><field index="settings.templateLayout"><value index="vDEF">table</value></field><field index="settings.showPageUids"><value index="vDEF"></value></field><field index="settings.productUids"><value index="vDEF">1,2,3</value></field></language></sheet></data></T3FlexForms>',
'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><T3FlexForms><data><sheet index="sDEF"><language index="lDEF"><field index="settings.templateLayout"><value index="vDEF">table</value></field><field index="settings.showPageUids"><value index="vDEF"></value></field><field index="settings.productUids"><value index="vDEF">1,2,10,3</value></field></language></sheet></data></T3FlexForms>',
],
3 => [
'uid' => '4',
'pid' => '11',
'CType' => 'list',
'list_type' => 'cartproducts_teaserproducts',
'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><T3FlexForms><data><sheet index="sDEF"><language index="lDEF"><field index="settings.templateLayout"><value index="vDEF">table</value></field><field index="settings.showPageUids"><value index="vDEF"></value></field><field index="settings.productUids"><value index="vDEF">7,9</value></field></language></sheet></data></T3FlexForms>',
'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><T3FlexForms><data><sheet index="sDEF"><language index="lDEF"><field index="settings.templateLayout"><value index="vDEF">table</value></field><field index="settings.showPageUids"><value index="vDEF"></value></field><field index="settings.productUids"><value index="vDEF">7,11,9</value></field></language></sheet></data></T3FlexForms>',
'sys_language_uid' => 2,
'l18n_parent' => 3,
'l10n_source' => 3,
Expand Down
24 changes: 24 additions & 0 deletions Tests/Fixtures/ProductsDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 => [
Expand Down
3 changes: 3 additions & 0 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ suites:
moz:firefoxOptions:
args:
- '-headless'
-
Extcode\CartProducts\Tests\Acceptance\Support\Helper:
depends: 'WebDriver'

step_decorators:
- 'Codeception\Step\Retry'

0 comments on commit c45dc2a

Please sign in to comment.