Skip to content

Commit b2e6c7f

Browse files
authored
Merge pull request #126 from NoelDeMartin/moodle-app-development
Moodle app development
2 parents 9655ec9 + a4ada7d commit b2e6c7f

8 files changed

+93
-11
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ env:
5656
- "PHP=7.1 DB=mariadb GIT=v3.7.2 SUITE=behat BROWSER=chrome"
5757
- "PHP=7.0 DB=mariadb GIT=v3.5.8 SUITE=behat BROWSER=firefox"
5858
# Mobile app
59-
- "PHP=7.3 DB=pgsql GIT=master SUITE=app BROWSER=chrome MOBILE=next"
60-
- "PHP=7.3 DB=pgsql GIT=master SUITE=app BROWSER=chrome MOBILE=latest"
59+
- "PHP=7.3 DB=pgsql GIT=master SUITE=behat-app-development BROWSER=chrome APP_VERSION=3.9.0 APP_PATH=$HOME/app"
60+
- "PHP=7.3 DB=pgsql GIT=master SUITE=behat-app BROWSER=chrome APP_VERSION=3.9.0"
6161
install:
6262
- git clone --branch $GIT --depth 1 git://github.com/moodle/moodle $HOME/moodle
6363
- cp config.docker-template.php $HOME/moodle/config.php
6464
- export MOODLE_DOCKER_DB=$DB
6565
- export MOODLE_DOCKER_BROWSER=$BROWSER
6666
- export MOODLE_DOCKER_WWWROOT="$HOME/moodle"
6767
- export MOODLE_DOCKER_PHP_VERSION=$PHP
68-
- export MOODLE_APP_VERSION=$MOBILE
68+
- export MOODLE_DOCKER_APP_PATH=$APP_PATH
69+
- export MOODLE_APP_VERSION=$APP_VERSION
6970
before_script:
7071
- tests/setup.sh
7172
script:

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,50 @@ Notes:
9999
* Mailhog is listening on `http://localhost:8000/_/mail` to view emails which Moodle has sent out.
100100
* The admin `username` you need to use for logging in is `admin` by default. You can customize it by passing `--adminuser='myusername'`
101101

102+
## Use containers for running behat tests for the mobile app
103+
104+
In order to run Behat tests for the mobile app, you need to install the [local_moodlemobileapp](https://github.com/moodlehq/moodle-local_moodlemobileapp) plugin in your Moodle site. Everything else should be the same as running standard Behat tests for Moodle. Make sure to filter tests using the `@app` tag.
105+
106+
The Behat tests will be run against a container serving the mobile application, you have two options here:
107+
108+
1. Use a docker image that includes the application code. You need to specify the `MOODLE_APP_VERSION` env variable and the [moodlehq/moodleapp](https://hub.docker.com/r/moodlehq/moodleapp) image will be downloaded from docker hub.
109+
110+
2. Use a local copy of the application code and serve it through docker, similar to how the Moodle site is being served. Set the `MOODLE_DOCKER_APP_PATH` env variable to the codebase in you file system. This will assume that you've already initialized the app calling `npm install` and `npm run setup` locally.
111+
112+
For both options, you also need to set `MOODLE_DOCKER_BROWSER` to "chrome".
113+
114+
```bash
115+
# Install local_moodlemobileapp plugin
116+
git clone git://github.com/moodlehq/moodle-local_moodlemobileapp "$MOODLE_DOCKER_WWWROOT/local/moodlemobileapp"
117+
118+
# Initialize behat environment
119+
bin/moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php
120+
# [..]
121+
122+
# Run behat tests
123+
bin/moodle-docker-compose exec -u www-data webserver php admin/tool/behat/cli/run.php --tags="@app&&@mod_login"
124+
Running single behat site:
125+
Moodle 4.0dev (Build: 20200615), a2b286ce176fbe361f0889abc8f30f043cd664ae
126+
Php: 7.2.30, pgsql: 11.8 (Debian 11.8-1.pgdg90+1), OS: Linux 5.3.0-61-generic x86_64
127+
Server OS "Linux", Browser: "chrome"
128+
Browser specific fixes have been applied. See http://docs.moodle.org/dev/Acceptance_testing#Browser_specific_fixes
129+
Started at 13-07-2020, 18:34
130+
.....................................................................
131+
132+
4 scenarios (4 passed)
133+
69 steps (69 passed)
134+
3m3.17s (55.02Mb)
135+
```
136+
137+
If you are going with the second option, this *can* be used for local development of the mobile app, given that the `moodleapp` container serves the app on the local 8100 port. However, this is intended to run Behat tests that require interacting with a local Moodle environment. Normal development should be easier calling `npm start` in the host system.
138+
139+
By all means, if you don't want to have npm installed locally you can go full docker executing the following commands before starting the containers:
140+
141+
```
142+
docker run --volume $MOODLE_DOCKER_APP_PATH:/app --workdir /app node:11 npm install
143+
docker run --volume $MOODLE_DOCKER_APP_PATH:/app --workdir /app node:11 npm run setup
144+
```
145+
102146
## Using VNC to view behat tests
103147

104148
If `MOODLE_DOCKER_SELENIUM_VNC_PORT` is defined, selenium will expose a VNC session on the port specified so behat tests can be viewed in progress.
@@ -134,7 +178,8 @@ You can change the configuration of the docker images by setting various environ
134178
| `MOODLE_DOCKER_WEB_HOST` | no | any valid hostname | localhost | The hostname for web |
135179
| `MOODLE_DOCKER_WEB_PORT` | no | any integer value (or bind_ip:integer)| 127.0.0.1:8000| The port number for web. If set to 0, no port is used.<br/>If you want to bind to any host IP different from the default 127.0.0.1, you can specify it with the bind_ip:port format (0.0.0.0 means bind to all) |
136180
| `MOODLE_DOCKER_SELENIUM_VNC_PORT` | no | any integer value (or bind_ip:integer)| not set | If set, the selenium node will expose a vnc session on the port specified. Similar to MOODLE_DOCKER_WEB_PORT, you can optionally define the host IP to bind to. If you just set the port, VNC binds to 127.0.0.1 |
137-
| `MOODLE_APP_VERSION` | no | next, latest, or an app version number| not set | If set will start an instance of the Mmodle app if the chrome browser is selected |
181+
| `MOODLE_DOCKER_APP_PATH` | no | path on your file system | not set | If set and the chrome browser is selected, it will start an instance of the Moodle app from your local codebase |
182+
| `MOODLE_APP_VERSION` | no | next, latest, or an app version number| not set | If set will start an instance of the Moodle app if the chrome browser is selected |
138183

139184
## Using XDebug for live debugging
140185

bin/moodle-docker-compose

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ if [ -f $filename ]; then
4444
dockercompose="${dockercompose} -f ${filename}"
4545
fi
4646

47-
# Mobile app
48-
if [[ ! -z "$MOODLE_DOCKER_BROWSER" ]] && [[ "$MOODLE_DOCKER_BROWSER" == "chrome" ]] && [[ ! -z "$MOODLE_APP_VERSION" ]];
47+
# Mobile app for development
48+
if [[ ! -z "$MOODLE_DOCKER_BROWSER" ]] && [[ "$MOODLE_DOCKER_BROWSER" == "chrome" ]] && [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]];
49+
then
50+
dockercompose="${dockercompose} -f ${basedir}/moodle-app-dev.yml"
51+
# Mobile app using a docker image
52+
elif [[ ! -z "$MOODLE_DOCKER_BROWSER" ]] && [[ "$MOODLE_DOCKER_BROWSER" == "chrome" ]] && [[ ! -z "$MOODLE_APP_VERSION" ]];
4953
then
5054
dockercompose="${dockercompose} -f ${basedir}/moodle-app.yml"
5155
fi

bin/moodle-docker-compose.cmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ if exist %filename% (
3535
)
3636

3737
IF "%MOODLE_DOCKER_BROWSER%"=="chrome" (
38-
IF NOT "%MOODLE_APP_VERSION%"=="" (
38+
IF NOT "%MOODLE_DOCKER_APP_PATH%"=="" (
39+
SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app-dev.yml"
40+
) ELSE IF NOT "%MOODLE_APP_VERSION%"=="" (
3941
SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app.yml"
4042
)
4143
)

bin/moodle-docker-wait-for-app

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

44
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
55

6-
if [[ ! -z "$MOODLE_DOCKER_BROWSER" ]] && [[ "$MOODLE_DOCKER_BROWSER" == "chrome" ]] && [[ ! -z "$MOODLE_APP_VERSION" ]];
6+
if [[ ! -z "$MOODLE_DOCKER_BROWSER" ]] && [[ "$MOODLE_DOCKER_BROWSER" == "chrome" ]] && ([[ ! -z "$MOODLE_DOCKER_APP_PATH" ]] || [[ ! -z "$MOODLE_APP_VERSION" ]]);
77
then
88
until $basedir/bin/moodle-docker-compose logs moodleapp | grep -q 'dev server running: ';
99
do

moodle-app-dev.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: "2"
2+
services:
3+
webserver:
4+
environment:
5+
MOODLE_DOCKER_APP: "true"
6+
moodleapp:
7+
image: node:11
8+
working_dir: /app
9+
command: npm run ionic:serve
10+
volumes:
11+
- "${MOODLE_DOCKER_APP_PATH}:/app"
12+
expose:
13+
- 8100
14+
- 35729
15+
- 53703
16+
ports:
17+
- "8100:8100"
18+
- "35729:35729"
19+
- "53703:53703"

tests/setup.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ elif [ "$SUITE" = "phpunit-full" ];
1212
then
1313
export MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES=true
1414
initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/phpunit/cli/init.php"
15-
elif [ "$SUITE" = "app" ];
15+
elif [ "$SUITE" = "behat-app-development" ];
1616
then
17+
git clone --branch "v$APP_VERSION" --depth 1 git://github.com/moodlehq/moodleapp $HOME/app
18+
git clone --branch "v$APP_VERSION" --depth 1 git://github.com/moodlehq/moodle-local_moodlemobileapp $HOME/moodle/local/moodlemobileapp
19+
20+
docker run --volume $HOME/app:/app --workdir /app node:11 npm install
21+
docker run --volume $HOME/app:/app --workdir /app node:11 npm run setup
22+
23+
initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/init.php"
24+
elif [ "$SUITE" = "behat-app" ];
25+
then
26+
git clone --branch "v$APP_VERSION" --depth 1 git://github.com/moodlehq/moodle-local_moodlemobileapp $HOME/moodle/local/moodlemobileapp
27+
1728
initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/init.php"
1829
else
1930
echo "Error, unknown suite '$SUITE'"

tests/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ then
1212
elif [ "$SUITE" = "phpunit-full" ];
1313
then
1414
testcmd="bin/moodle-docker-compose exec -T webserver vendor/bin/phpunit --verbose"
15-
elif [ "$SUITE" = "app" ];
15+
elif [ "$SUITE" = "behat-app" ] || [ "$SUITE" = "behat-app-development" ];
1616
then
17-
testcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/run.php --tags=@app"
17+
testcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/run.php --tags=@app&&@mod_login"
1818
else
1919
echo "Error, unknown suite '$SUITE'"
2020
exit 1

0 commit comments

Comments
 (0)