Native module suites
On this page
The library ships nine demo suites, one per PrestaShop native module. Each one changes a setting in the BackOffice and checks the effect on the FrontOffice (or the other way round: a customer acts on the FrontOffice, the merchant sees it in the BackOffice).
They have three uses:
- a demo: run one against a shop and show what PrestaFlow tests, end to end;
- examples: copy one as the starting point of a suite for your own module;
- regression tests: after an upgrade of PrestaShop, of a module or of the theme, they tell you whether the BackOffice setting still reaches the shop.
#Coverage
| PrestaShop | Themes |
|---|---|
| 9 | Classic and Hummingbird |
| 8 | Classic |
| 1.7 | Classic |
Every suite starts with the EnsureModule fixture, so the
module is installed and enabled before anything else runs.
#The suites
The suites live in src/Tests/Suites/Modules/ of the library. Each one belongs
to the modules and demo groups, plus a group of its own.
| Suite | Module | Group | What it proves |
|---|---|---|---|
WishlistTest |
blockwishlist |
wishlist |
What a customer adds to a wishlist shows in the merchant's statistics |
NewsletterTest |
ps_emailsubscription |
newsletter |
A visitor subscribes from the footer, the merchant finds the address |
SearchTest |
ps_searchbar |
search |
A search alias set by the merchant finds the product |
FacetedSearchTest |
ps_facetedsearch |
facetedsearch |
Product counts set in the BackOffice show on the filters, and a filter narrows the list |
ProductCommentsTest |
productcomments |
productcomments |
A customer's review goes online once the merchant approves it |
ContactFormTest |
contactform |
contactform |
A contact created by the merchant becomes a subject, and a message sent with it lands in Customer Service |
CustomTextTest |
ps_customtext |
customtext |
The text written in the BackOffice is the one the home page shows |
FeaturedProductsTest |
ps_featuredproducts |
featuredproducts |
The number of products set in the BackOffice is the number the home page shows |
ImageSliderTest |
ps_imageslider |
imageslider |
A slide disabled in the BackOffice leaves the home carousel, and comes back once enabled |
#What they share
- No hardcoded labels. They compare counts, ids and what the page shows, in
the run's locale (
PRESTAFLOW_LOCALE). No theme name is assumed either. - Re-runnable. What a suite creates carries a name unique to the run, or is removed first when an interrupted run left it behind. A second run starts from the same state as the first.
- The shop is put back. A setting the suite changes is restored at the end,
as it was before the run.
CustomTextTest,FeaturedProductsTestandImageSliderTestrun that last step even when an earlier one failed. - Self-sufficient. No demo customer is needed.
WishlistTestandProductCommentsTestcreate their own customer account on the first run; the other suites act as a visitor.
#Details worth knowing
WishlistTestempties the customer's default list, adds three products from the catalogue, finds them in "My wishlists", then in the module's Statistics tab. Statistics are computed per shop, so the suite sets a single-shop context first.NewsletterTestturns the verification e-mail off, so a subscription is immediate. Subscribing the same address twice must be refused.SearchTestadds the aliaspfdemoaliasin Shop Parameters > Search > Aliases, then removes it. The merchant's other aliases of the same word are kept.FacetedSearchTestuses the categoryPRESTAFLOW_CATEGORYwhen set, otherwise the first category of the shop that shows filters.ProductCommentsTestuses the productPRESTAFLOW_PRODUCT(a product page path or URL) when set, otherwise the first product that can be bought. It skips before touching any setting when the product page has no review form. The module refuses a second review from the same customer on the same product within 30 seconds (PRODUCT_COMMENTS_MINIMAL_TIME): two runs closer than that fail with the module's own message.ContactFormTestcreates the contact "PrestaFlow demo" without an e-mail address, so nothing is mailed. The thread and the contact are deleted at the end.CustomTextTestappends a unique marker paragraph to the text of every language, then puts the original text back.FeaturedProductsTestandImageSliderTestonly change a number or the state of one slide. A run interrupted between the change and the restore leaves the change in place: the suite cannot tell it from a merchant's choice.ImageSliderTestcompares slide titles as the BackOffice lists them, so it expects the BackOffice and the FrontOffice in the same language.
#Running them
The suites ship with the library, so you can run them straight from vendor/
with the usual environment
(shop URLs, BackOffice account, locale, theme).
All nine:
1composer prestaflow:default -- vendor/prestaflow/php-library/src/Tests/Suites/Modules
One module, by its group:
1composer prestaflow:default -- vendor/prestaflow/php-library/src/Tests/Suites/Modules --group=wishlist
Several modules: --group can be repeated, and a suite runs when it belongs to
any of them.
1composer prestaflow:default -- vendor/prestaflow/php-library/src/Tests/Suites/Modules --group=newsletter --group=search
If your own suites also use the demo or modules groups, the same
--group=demo runs them together with the library's. See
Working with groups.
On a multilingual shop, set PRESTAFLOW_PREFIX_LOCALE=true so the FrontOffice
URLs carry the language.
#EnsureModule
EnsureModule makes sure a module is installed and enabled, through the Module
Manager. It is a fixture, like EnsureTestAccount
and SwitchTheme: it
guarantees the end state, so a module already installed and enabled is a
legitimate pass.
A module that is not on the shop at all fails at once, with its name, instead of surfacing later as a click on a selector that matches nothing.
Parameters
1public $params = [2 'locale' => 'en',3 // Technical name (blockwishlist, ps_emailsubscription…). Required.4 'module' => null,5];
Usage
1$this2->describe('My module')3->scenario(\PrestaFlow\Library\Scenarios\EnsureModule::class, [4 'module' => 'ps_customtext',5 'locale' => $this->getLocale(),6]);
It signs in to the BackOffice with the project's account (PRESTAFLOW_BO_*),
and leaves that session open for the steps that follow.
On PrestaShop 1.7 the Module Manager only lists installed modules. A disabled module is enabled, but a module that is not installed fails at "present on the shop": install it first (Modules > Module selection).
To check a single module without writing a suite, run the wrapper suite with
PRESTAFLOW_MODULE (default blockwishlist):
1PRESTAFLOW_MODULE=ps_imageslider composer prestaflow:default -- vendor/prestaflow/php-library/src/Tests/Suites/Scenarios/EnsureModule.php
#Module Manager and module pages
The suites drive the BackOffice through page objects you can use in your own suites:
BackOffice\Modules, the Module Manager:goTo(),searchModule($name),isListed($name),isInstalled($name),isEnabled($name),install($name),enable($name),getConfigurationUrl($name)andopenConfiguration($name). Modules are found by their technical name, and their state is read from the card's data attributes, not from translated button labels.- One configuration page per module:
BackOffice\Modules\Blockwishlist,EmailSubscription,FacetedSearch,ProductComments,CustomText,FeaturedProductsandImageSlider. - On the FrontOffice:
FrontOffice\Wishlist("My wishlists") and the newsletter block of the footer (subscribeNewsletter($email)onFrontOffice).
Always open a module's configuration with openConfiguration(). Its URL carries
a security token: a URL you build by hand (controller=AdminModules&configure=…)
is answered with an "Invalid security token" page.
#Copy a suite
To test your own module, copy the pattern: the fixture first, then the
BackOffice setting, then its effect on the FrontOffice, then put the setting
back. skipWhenFailed(false) keeps the last step running when an earlier one
failed.
1namespace Tests\Modules; 2 3use PrestaFlow\Library\Expects\Expect; 4use PrestaFlow\Library\Scenarios\EnsureModule; 5use PrestaFlow\Library\Tests\TestsSuite; 6 7class MyModuleTest extends TestsSuite 8{ 9 protected $groups = ['modules', 'mymodule'];10 11 public function init()12 {13 $this14 ->describe('My module: the setting changed in the BackOffice shows on the home page')15 // The last step restores the shop: a failing step must not skip it.16 ->skipWhenFailed(false)17 ->scenario(EnsureModule::class, ['module' => 'mymodule', 'locale' => $this->getLocale()]);18 19 $this->importPage('BackOffice\Modules');20 $this->importPage('FrontOffice\Home');21 22 extract($this->pages);23 24 $openConfiguration = function () use ($backOfficeModulesPage) {25 // EnsureModule left a valid BackOffice session.26 $backOfficeModulesPage->goToPage('index');27 $backOfficeModulesPage->goTo();28 $backOfficeModulesPage->searchModule('mymodule');29 30 Expect::that($backOfficeModulesPage->openConfiguration('mymodule'))->equals(true);31 };32 33 $this34 ->it('change the setting', function () use ($openConfiguration) {35 $openConfiguration();36 // Remember the current value with $this->store(), then change it.37 })38 ->it('the home page shows the effect', function () use ($frontOfficeHomePage) {39 $frontOfficeHomePage->goToPage('home');40 // Expect::that(...) on what the home page shows.41 })42 ->it('put the setting back', function () use ($openConfiguration) {43 $openConfiguration();44 // Restore the value read with $this->retrieve().45 });46 }47}
The nine suites in vendor/prestaflow/php-library/src/Tests/Suites/Modules/
are complete examples of each step: read them before writing yours.