Skip to content

Commit b992b7a

Browse files
Add e2e_testing env
1 parent 17df44b commit b992b7a

File tree

15 files changed

+140
-22
lines changed

15 files changed

+140
-22
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
app:
3+
container_name: "glpi-test-app-e2e"
4+
image: "ghcr.io/glpi-project/${PHP_IMAGE:-githubactions-php-apache:8.3}"
5+
environment:
6+
CODE_COVERAGE: "${CODE_COVERAGE:-false}"
7+
CI: true # Will be used to alter some configuration when running on github vs locally.
8+
PLAYWRIGHT_BROWSERS_PATH: /opt/pw-browsers # Custom browser path to prevent some rights issues.
9+
GLPI_BASE_URL: http://localhost:80 # Default URL for GLPI. Used for e2e tests.
10+
PHP: php
11+
GLPI_ENVIRONMENT_TYPE: e2e_testing
12+
volumes:
13+
- type: "bind"
14+
source: "${APPLICATION_ROOT}"
15+
target: "/var/www/glpi"
16+
- type: "bind"
17+
source: "${APP_CONTAINER_HOME}"
18+
target: "/home/www-data"

.github/actions/docker-compose-app.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ services:
44
image: "ghcr.io/glpi-project/${PHP_IMAGE:-githubactions-php-apache:8.3}"
55
environment:
66
CODE_COVERAGE: "${CODE_COVERAGE:-false}"
7-
CI: true # Will be used to alter some configuration when running on github vs locally.
8-
PLAYWRIGHT_BROWSERS_PATH: /opt/pw-browsers # Custom browser path to prevent some rights issues.
9-
GLPI_BASE_URL: http://localhost:80 # Default URL for GLPI. Used for e2e tests.
107
volumes:
118
- type: "bind"
129
source: "${APPLICATION_ROOT}"

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ jobs:
283283
runs-on: "ubuntu-latest"
284284
timeout-minutes: 60
285285
env:
286-
COMPOSE_FILE: ".github/actions/docker-compose-app.yml:.github/actions/docker-compose-services.yml"
286+
COMPOSE_FILE: ".github/actions/docker-compose-app-e2e.yml:.github/actions/docker-compose-services.yml"
287287
APPLICATION_ROOT: "${{ github.workspace }}"
288288
DB_IMAGE: "githubactions-mariadb:10.11"
289289
PHP_IMAGE: "githubactions-php-apache:8.3"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ ctrf/
5858
/playwright/.cache/
5959
/tests/playwright/.env.local
6060
!/tests/playwright/.env
61+
/tests/playwright/glpi_config/*
62+
/tests/playwright/glpi_files/*

Makefile

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ help: ## Show this help message
2323
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-25s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
2424
.PHONY: help
2525

26-
install: init-override build up vendor db-install test-db-install ## Install the project
26+
install: init-override build up vendor db-install test-db-install e2e-db-install ## Install the project
2727
.PHONY: install
2828

2929
## —— Docker ———————————————————————————————————————————————————————————————————
@@ -119,8 +119,31 @@ test-db-update: ## Update testing's database
119119
-n \
120120
--allow-unstable \
121121
--force \
122-
--skip-db-checks
123-
.PHONY: db-update
122+
--skip-db-checks \
123+
--env=testing
124+
.PHONY: test-db-update
125+
126+
e2e-db-install: ## Install e2e testing's database
127+
@$(CONSOLE) database:install \
128+
-r -f \
129+
--db-host=db \
130+
--db-port=3306 \
131+
--db-name=glpi_e2e \
132+
--db-user=root \
133+
--db-password=glpi \
134+
--no-interaction \
135+
--no-telemetry \
136+
--env=e2e_testing
137+
.PHONY: e2e-db-install
138+
139+
e2e-db-update: ## Update e2e testing's database
140+
@$(CONSOLE) database:update \
141+
-n \
142+
--allow-unstable \
143+
--force \
144+
--skip-db-checks \
145+
--env=e2e_testing
146+
.PHONY: e2e-db-update
124147

125148
## —— Dependencies —————————————————————————————————————————————————————————————
126149
composer: ## Run a composer command, example: make composer c='require mypackage/package'

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
- "custom_php_ini:/usr/local/etc/php/custom_conf.d/:rw"
1212
ports:
1313
- "8080:80"
14+
- "8090:8090"
1415
- "9637:9637"
1516
depends_on:
1617
- db

install/empty_data.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public function getEmptyData(): array
7575
$tables = [];
7676

7777
// API need to be enabled to ease e2e testing
78-
$add_e2e_data = Environment::get()->shouldAddExtraE2EDataDuringInstallation();
79-
$enable_api = $add_e2e_data ? "1" : "0";
80-
$enable_api_login_credentials = $add_e2e_data ? "1" : "0";
78+
$add_cypress_data = Environment::get()->shouldAddExtraCypressDataDuringInstallation();
79+
$enable_api = $add_cypress_data ? "1" : "0";
80+
$enable_api_login_credentials = $add_cypress_data ? "1" : "0";
8181

8282
$tables['glpi_apiclients'] = [
8383
[
@@ -9422,7 +9422,7 @@ public function getEmptyData(): array
94229422
];
94239423

94249424
// Test environment data
9425-
if ($add_e2e_data) {
9425+
if ($add_cypress_data) {
94269426
$root_entity = array_filter($tables['glpi_entities'], static fn($e) => $e['id'] === 0);
94279427
$root_entity = current($root_entity);
94289428

playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { config } from 'dotenv' ;
33
import { Config } from './tests/playwright/utils/Config';
44

55
// Load .env file so it is available everywhere.
6+
config({path: './tests/playwright/.env'});
67
config({path: './tests/playwright/.env.local'});
78

89
/**

src/Glpi/Application/Environment.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ enum Environment: string
5858
*/
5959
case TESTING = 'testing';
6060

61+
/**
62+
* E2E Testing environment.
63+
* Separate from testing as it commit data to the database which may interfere
64+
* with regular tests that expect a static database.
65+
*/
66+
case E2E_TESTING = 'e2e_testing';
67+
6168
/**
6269
* Development environment.
6370
* Suitable for developer machines and development servers.
@@ -151,6 +158,16 @@ public function getConstantsOverride(string $root_dir): array
151158
$root_dir . '/tests/fixtures/plugins',
152159
],
153160
],
161+
self::E2E_TESTING => [
162+
'GLPI_CONFIG_DIR' => $root_dir . '/tests/playwright/glpi_config',
163+
'GLPI_VAR_DIR' => $root_dir . '/tests/playwright/glpi_files',
164+
'GLPI_LOG_LVL' => LogLevel::DEBUG,
165+
'GLPI_STRICT_ENV' => true,
166+
'GLPI_PLUGINS_DIRECTORIES' => [
167+
$root_dir . '/tests/fixtures/plugins',
168+
],
169+
170+
],
154171
self::DEVELOPMENT => [
155172
'GLPI_LOG_LVL' => LogLevel::DEBUG,
156173
'GLPI_STRICT_ENV' => true,
@@ -169,7 +186,11 @@ public function shouldExpectResourcesToChange(string $root_dir = GLPI_ROOT): boo
169186
// Only production/staging environment are considered as environments
170187
// where resources are not supposed to change.
171188
// In others environments, we must match for changes.
172-
if ($this === self::TESTING || $this === self::DEVELOPMENT) {
189+
if (
190+
$this === self::TESTING
191+
|| $this === self::DEVELOPMENT
192+
|| $this === self::E2E_TESTING
193+
) {
173194
return true;
174195
}
175196

@@ -212,7 +233,7 @@ public function shouldEnableExtraDevAndDebugTools(): bool
212233
};
213234
}
214235

215-
public function shouldAddExtraE2EDataDuringInstallation(): bool
236+
public function shouldAddExtraCypressDataDuringInstallation(): bool
216237
{
217238
// Note: this will be removed when we switch to playwright.
218239
return match ($this) {

tests/playwright/.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Copy this file as .env.local and set your own values if needed.
22

33
# GLPI base URL
4-
GLPI_BASE_URL="http://localhost:80"
4+
GLPI_BASE_URL="http://localhost:8090" # Should be an url leading to a GLPI server running in the "e2e_testing" environment
55

66
# PHP executable
7-
PHP="php"
8-
# PHP="docker compose exec app php" # Use this instead if you use docker
7+
PHP="docker compose exec app php"
8+
# PHP="php" # If you don't use the official docker image, you may use this instead docker
99

1010
# Disable web report being automatically opened on failure
1111
# PW_TEST_HTML_REPORT_OPEN='never'

0 commit comments

Comments
 (0)