Skip to content

Commit

Permalink
Testing Hooks with ps_qualityassurance
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Mar 27, 2024
1 parent 9e8d2d6 commit 5cb6ed2
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ title: Processes

## Pull Request Management

* [Testing Hooks with `ps_qualityassurance`](./test-hooks-with-ps_qualityassurance)
* [Testing Pull Request](./pr-management)

## Testing with vagrant

* [How to test Pull Requests](./test-pr-and-branches)
* [Testing Pull Request with Vagrant](./test-pr-and-branches)

## Software Development in Test

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
title: Testing Hooks with `ps_qualityassurance`
---

# Testing Hooks with `ps_qualityassurance`

Hooks are not easily testable. So a module [`ps_qualityassurance`](https://github.com/PrestaShop/ps_qualityassurance) has been created to test this module.

## Installation

### Fetch the ZIP module

* Go to the [releases page of the module](https://github.com/PrestaShop/ps_qualityassurance/releases)
* Download the ZIP asset of the module linked to the latest release

### Install the module

* Go to your BackOffice
* Go to the "Modules" > "Module Manager" page
* Click on the "Upload a module" button
* Select the previous downloaded file
* The module is installed.

![The module is installed.](./installed-module.png)
{class="text-center"}

## Usage

### Test an `action` Hook

#### Context

In this example, we try to check if the hook `actionProductPriceCalculation` is called in frontoffice.

![Hook actionProductPriceCalculation](./hook-actionProductPriceCalculation.png)
{class="text-center"}

We can see that the price is passed as reference. We will modify the price with `ps_qualityassurance`.

#### Example

* Go the configuration page of the module
* Click on the tab "Register Hook"
* For the hook name, use `actionProductPriceCalculation`
* For the content, use
```php
if ($params['use_tax']) {
$params['price'] = 42.00;
} else {
$params['price'] = 35.00;
}
```
* Save
* Go to the frontoffice
* The hook runs well
![The hook runs well](./hooked-actionProductPriceCalculation.png)
{class="text-center"}

### Test a `display` Hook

#### Context

In this example, we try to check if the hook `displayProductListReviews` is called in frontoffice.

![Hook displayProductListReviews](./hook-displayProductListReviews.png)
{class="text-center"}

We can see that the product is passed as parameter. We will use the product for displaying a new text with `ps_qualityassurance`.

#### Example

* Go the configuration page of the module
* Click on the tab "Register Hook"
* For the hook name, use `displayProductListReviews`
* For the content, use
```php
return 'Your product "' . $params['product']['name'] . '" has the ID ' . $params['product']['id'] . '.';
```
* Save
* Go to the frontoffice
* Go to a category page
* The hook runs well
![The hook runs well](./hooked-displayProductListReviews.png)
{class="text-center"}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5cb6ed2

Please sign in to comment.