Skip to content

Commit 3c6cf40

Browse files
committed
base structure, behat test and gha workflow script
1 parent 1077b0d commit 3c6cf40

15 files changed

+363
-1
lines changed

Diff for: .github/workflows/web-install.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Moodle web installation testing
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
env:
13+
php: 8.2
14+
15+
jobs:
16+
behat:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Setting up DB PostgreSQL
21+
uses: m4nu56/postgresql-action@v1
22+
with:
23+
postgresql version: 13
24+
postgresql db: test
25+
postgresql user: test
26+
postgresql password: test
27+
28+
- name: Wait for PostgreSQL to be ready
29+
run: |
30+
for i in {1..30}; do
31+
if pg_isready -h localhost -p 5432 -U test; then
32+
echo "PostgreSQL is ready"
33+
break
34+
else
35+
echo "Waiting for PostgreSQL to be ready..."
36+
sleep 2
37+
fi
38+
done
39+
40+
- name: Setting up PHP
41+
uses: shivammathur/setup-php@v2
42+
with:
43+
php-version: 8.3
44+
ini-values: max_input_vars=5000
45+
coverage: none
46+
47+
- name: Clone Moodle repository
48+
uses: actions/checkout@v2
49+
with:
50+
repository: moodle/moodle
51+
ref: main
52+
path: moodle
53+
54+
- name: Clone Plugin repository
55+
uses: actions/checkout@v2
56+
with:
57+
repository: lameze/moodle-webinstall
58+
ref: main
59+
path: webinstall
60+
61+
- name: Install Plugin Composer Dependencies
62+
run: composer install
63+
working-directory: webinstall
64+
65+
- name: Start PHP built-in server
66+
run: |
67+
nohup php -S localhost:8080 -t . > server.log 2>&1 &
68+
echo "Waiting for PHP built-in server to be ready..."
69+
for i in {1..5}; do
70+
if nc -z localhost 8080; then
71+
echo "PHP built-in server is ready"
72+
break
73+
else
74+
echo "Waiting for PHP built-in server to be ready..."
75+
sleep 2
76+
fi
77+
done
78+
working-directory: moodle
79+
80+
- name: Install Puppeteer
81+
run: npm install puppeteer
82+
working-directory: webinstall
83+
84+
- name: Take screenshot of Moodle installation page
85+
run: node screenshot.js
86+
working-directory: webinstall
87+
88+
- name: Run Behat tests
89+
run: vendor/bin/behat tests/behat/install.feature
90+
working-directory: webinstall
91+
92+
- name: Print PHP built-in server logs
93+
if: always()
94+
run: cat server.log
95+
working-directory: moodle
96+
97+
- name: Upload screenshot
98+
if: always()
99+
uses: actions/upload-artifact@v2
100+
with:
101+
name: screenshot
102+
path: webinstall/moodle.png

Diff for: .idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/GitLink.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/moodle-webinstall.iml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/php.xml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/vcs.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Context/FeatureContext.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
namespace Context;
3+
4+
use Behat\Behat\Hook\Scope\AfterStepScope;
5+
use Behat\Mink\Exception\UnsupportedDriverActionException;
6+
use Behat\MinkExtension\Context\MinkContext;
7+
use Behat\Behat\Context\Context;
8+
9+
class FeatureContext extends MinkContext implements Context {
10+
/**
11+
* @AfterStep
12+
*/
13+
public function takeScreenshotAfterFailedStep(AfterStepScope $scope)
14+
{
15+
if (99 === $scope->getTestResult()->getResultCode()) {
16+
$this->saveScreenshot(null, __DIR__ . '/../../build/behat/');
17+
}
18+
}
19+
20+
public function saveScreenshot($filename = null, $filepath = null)
21+
{
22+
if (!$this->getSession()->getDriver() instanceof \Behat\Mink\Driver\Selenium2Driver) {
23+
throw new UnsupportedDriverActionException('Taking screenshots is not supported by %s, use Selenium2Driver instead.', $this->getSession()->getDriver());
24+
}
25+
26+
if (null === $filename) {
27+
$filename = 'behat_screenshot_' . date('YmdHis') . '.png';
28+
}
29+
30+
$this->getSession()->getDriver()->getScreenshot($filepath . $filename);
31+
}
32+
}

Diff for: README.md

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# moodle-local_webinstall
1+
# moodle-webinstall

Diff for: behat.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
default:
2+
suites:
3+
default:
4+
paths:
5+
- "%paths.base%/tests/behat"
6+
contexts:
7+
- Context\FeatureContext
8+
extensions:
9+
Behat\MinkExtension:
10+
base_url: http://localhost
11+
goutte: ~
12+
selenium2: ~

Diff for: composer.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "lameze/local_webinstall",
3+
"description": "A project to automate test Moodle's web install",
4+
"require": {
5+
"php": "^7.4 || ^8.0",
6+
"behat/behat": "3.13.*",
7+
"behat/mink": "^1.10.0",
8+
"behat/mink-extension": "^2.6",
9+
"behat/mink-goutte-driver": "^2.0",
10+
"behat/mink-selenium2-driver": "^1.4",
11+
"behat/mink-browserkit-driver": "^2.1.0",
12+
"friends-of-behat/mink-extension": "^2.7.4",
13+
"symfony/process": "^4.4 || ^5.0 || ^6.0",
14+
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
15+
"symfony/mime": "^4.4 || ^5.0 || ^6.0",
16+
"oleg-andreyev/mink-phpwebdriver": "1.3.*"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"Context\\": "tests/behat/Context/"
21+
}
22+
},
23+
"scripts": {
24+
"test": "vendor/bin/behat"
25+
}
26+
}

Diff for: install.feature

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Feature: Moodle Web Installation
2+
3+
Scenario: Verify successful installation of Moodle
4+
Given I am on "http://localhost:8080/moodle"
5+
6+
# First page: Choose a language
7+
And I should see "Installation"
8+
And I should see "Choose a language"
9+
And I should see "Please choose a language for the installation. This language will also be used as the default language for the site, though it may be changed later."
10+
And I press "Next"
11+
12+
# Second page: paths
13+
And I should see "Confirm paths"
14+
And I press "Next"
15+
16+
# Choose database driver
17+
And I fill in "dbtype" with "pgsql"
18+
And I press "Next"
19+
20+
# Database settings
21+
When I fill in "dbhost" with "localhost"
22+
When I fill in "dbname" with "test"
23+
When I fill in "dbuser" with "test"
24+
When I fill in "dbpass" with "test"
25+
And I press "Next"
26+
27+
# Configuration completed: --> only if moodle can't save config.php
28+
# And I should see "Configuration completed"
29+
# And I press "Next"
30+
31+
# Installation
32+
# And I should see "Moodle - Modular Object-Oriented Dynamic Learning Environment"
33+
And I should see "Have you read these conditions and understood them?"
34+
And I press "Continue"
35+
36+
# Server checks
37+
And I should see "Server checks"
38+
And I press "Continue"
39+
40+
# All modules installation.
41+
And I press "Continue"
42+
43+
# Admin user account.
44+
And I should see "On this page you should configure your main administrator account"
45+
And I fill in "email" with "[email protected]"
46+
And I fill in "newpassword" with "aaa123!"
47+
And I press "Update profile"
48+
49+
# Site home settings
50+
And I fill in "s__fullname" with "site test"
51+
And I fill in "s__shortname" with "sitetest"
52+
And I fill in "s__supportemail" with "[email protected]"
53+
And I fill in "s__noreplyaddress" with "[email protected]"
54+
And I press "Save changes"
55+
56+
# Finish.
57+
And I should see "Welcome, admin!"

Diff for: screenshot.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const puppeteer = require('puppeteer');
2+
3+
(async () => {
4+
const browser = await puppeteer.launch();
5+
const page = await browser.newPage();
6+
await page.goto('http://localhost:8080/moodle');
7+
await page.screenshot({path: 'moodle.png'});
8+
await browser.close();
9+
})();

Diff for: tests/behat/Context/FeatureContext.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace Context;
3+
4+
use Behat\MinkExtension\Context\MinkContext;
5+
use Behat\Behat\Context\Context;
6+
7+
class FeatureContext extends MinkContext implements Context {
8+
9+
}

Diff for: tests/behat/install.feature

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Feature: Moodle Web Installation
2+
3+
Scenario: Verify successful installation of Moodle
4+
Given I am on "http://localhost:8080/moodle"
5+
6+
# First page: Choose a language
7+
And I should see "Installation"
8+
And I should see "Choose a language"
9+
And I should see "Please choose a language for the installation. This language will also be used as the default language for the site, though it may be changed later."
10+
And I press "Next"
11+
12+
# Second page: Confirm paths
13+
And I should see "Confirm paths"
14+
And I press "Next"
15+
16+
# Choose database driver
17+
And I fill in "dbtype" with "pgsql"
18+
And I press "Next"
19+
20+
# Database settings
21+
When I fill in "dbhost" with "localhost"
22+
When I fill in "dbname" with "test"
23+
When I fill in "dbuser" with "test"
24+
When I fill in "dbpass" with "test"
25+
And I press "Next"
26+
27+
# Configuration completed: --> We only see this part if Moodle could not save the config.php
28+
# And I should see "Configuration completed"
29+
# And I press "Next"
30+
31+
# Installation
32+
And I should see "Have you read these conditions and understood them?"
33+
And I press "Continue"
34+
35+
# Server checks
36+
And I should see "Server checks"
37+
And I press "Continue"
38+
39+
# All modules installation.
40+
And I press "Continue"
41+
42+
# Admin user account.
43+
And I should see "On this page you should configure your main administrator account"
44+
And I fill in "email" with "[email protected]"
45+
And I fill in "newpassword" with "Web1nstall123!"
46+
And I press "Update profile"
47+
48+
# Site home settings.
49+
And I fill in "s__fullname" with "site test"
50+
And I fill in "s__shortname" with "sitetest"
51+
And I fill in "s__supportemail" with "[email protected]"
52+
And I fill in "s__noreplyaddress" with "[email protected]"
53+
And I press "Save changes"
54+
55+
# Installation finished.
56+
And I should see "Welcome, admin!"

0 commit comments

Comments
 (0)