Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing Hooks with ps_qualityassurance #260

Merged
merged 2 commits into from
Mar 27, 2024
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
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,86 @@
---
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;
}
```
* Register the hook
* 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'] . '.';
```
* Register the hook
* 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.
Loading