From 0c03540f4b09d41c5effc146d10aeee8c71d6f9e Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 20 Nov 2023 16:18:08 +0100 Subject: [PATCH 1/2] Remove unused import --- src/Installer/TestSuiteInstaller.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Installer/TestSuiteInstaller.php b/src/Installer/TestSuiteInstaller.php index a8b2b96b..7007aeed 100644 --- a/src/Installer/TestSuiteInstaller.php +++ b/src/Installer/TestSuiteInstaller.php @@ -18,7 +18,6 @@ use MoodlePluginCI\Process\MoodleProcess; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; -use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\Process\Process; /** From 2130c06cf3a23fdb7aee267c1346bc99ea63bd18 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 20 Nov 2023 16:18:15 +0100 Subject: [PATCH 2/2] Support and document usage with the Moodle App --- .github/workflows/test.yml | 8 +- .travis.dist.yml | 2 + .travis.yml | 7 +- docs/CHANGELOG.md | 7 +- docs/GHAFileExplained.md | 4 + docs/Help.md | 6 +- docs/MoodleApp.md | 20 +++++ docs/TravisFileExplained.md | 3 + docs/index.md | 1 + gha.dist.yml | 5 +- res/template/config.php.txt | 9 ++- src/Bridge/MoodleConfig.php | 32 ++++---- src/Command/BehatCommand.php | 8 +- src/Installer/InstallerFactory.php | 7 ++ src/Installer/MoodleAppInstaller.php | 81 +++++++++++++++++++ tests/Bridge/MoodlePluginTest.php | 4 + tests/Command/CodeCheckerCommandTest.php | 4 +- tests/Command/CodeFixerCommandTest.php | 2 +- tests/Fake/Process/DummyExecute.php | 3 + tests/Fixture/example-config.php | 7 ++ .../moodle-local_ci/classes/output/mobile.php | 52 ++++++++++++ tests/Fixture/moodle-local_ci/db/mobile.php | 43 ++++++++++ .../moodle-local_ci/tests/behat/login.feature | 12 +++ tests/Fixture/phpunit/phpunit-expected.xml | 1 + tests/Installer/MoodleAppInstallerTest.php | 39 +++++++++ 25 files changed, 335 insertions(+), 32 deletions(-) create mode 100644 docs/MoodleApp.md create mode 100644 src/Installer/MoodleAppInstaller.php create mode 100644 tests/Fixture/moodle-local_ci/classes/output/mobile.php create mode 100644 tests/Fixture/moodle-local_ci/db/mobile.php create mode 100644 tests/Installer/MoodleAppInstallerTest.php diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3327ef50..f97a7450 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -86,12 +86,8 @@ jobs: moodle-branch: 'MOODLE_400_STABLE' - php: '8.0' moodle-branch: 'MOODLE_311_STABLE' - - php: '7.4' - moodle-branch: 'MOODLE_310_STABLE' - php: '7.4' moodle-branch: 'MOODLE_39_STABLE' - - php: '7.4' - moodle-branch: 'MOODLE_38_STABLE' steps: - name: Check out repository code @@ -127,6 +123,7 @@ jobs: IGNORE_PATHS: 'ignore' IGNORE_NAMES: 'ignore_name.php' MUSTACHE_IGNORE_NAMES: 'broken.mustache' + MOODLE_APP: 'true' - name: Run Integration tests env: @@ -145,6 +142,7 @@ jobs: moodle-plugin-ci phpunit --verbose --coverage-text --fail-on-warning moodle-plugin-ci behat --profile default moodle-plugin-ci behat --profile chrome + moodle-plugin-ci behat --profile firefox --tags="@local_ci&&~@app" buildphar: name: Build moodle-plugin-ci.phar @@ -240,6 +238,7 @@ jobs: IGNORE_PATHS: 'ignore' IGNORE_NAMES: 'ignore_name.php' MUSTACHE_IGNORE_NAMES: 'broken.mustache' + MOODLE_APP: 'true' - name: Run Integration tests (PHAR) env: @@ -258,3 +257,4 @@ jobs: php build/moodle-plugin-ci.phar phpunit --verbose --coverage-text --fail-on-warning php build/moodle-plugin-ci.phar behat --profile default php build/moodle-plugin-ci.phar behat --profile chrome + php build/moodle-plugin-ci.phar behat --profile firefox --tags="@local_ci&&~@app" diff --git a/.travis.dist.yml b/.travis.dist.yml index ce11403e..20ab597d 100644 --- a/.travis.dist.yml +++ b/.travis.dist.yml @@ -28,6 +28,8 @@ env: global: - PGVER=13 - MOODLE_BRANCH=MOODLE_402_STABLE + # Uncomment this to run Behat tests using the Moodle App. + # - MOODLE_APP=true matrix: - DB=pgsql - DB=mysqli diff --git a/.travis.yml b/.travis.yml index 12d723ef..3d0c0668 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,7 +46,7 @@ before_install: fi install: - - moodle-plugin-ci install -vvv + - MOODLE_APP=true moodle-plugin-ci install -vvv script: # This is basically "integration" testing. @@ -63,6 +63,7 @@ script: - moodle-plugin-ci phpunit --verbose --coverage-text --fail-on-warning - moodle-plugin-ci behat --profile default - moodle-plugin-ci behat --profile chrome + - moodle-plugin-ci behat --profile firefox --tags="@local_ci&&~@app" jobs: include: @@ -94,6 +95,6 @@ jobs: # Last stable with highest supported PHP version. - php: 8.2 env: MOODLE_BRANCH=MOODLE_402_STABLE - # And oldest stable supported (with lowest supported PHP version). + # And older stable supported (with lowest supported PHP version). - php: 7.4 - env: MOODLE_BRANCH=MOODLE_38_STABLE + env: MOODLE_BRANCH=MOODLE_39_STABLE diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4057aec2..0b2fb7ea 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -23,6 +23,9 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt To avoid that problem it's recommended to to add the `libonig5` package to the `travis.yml` file. For a working example, please reference the updated `.travis.dist.yml`file. +### Added +- Support and document usage with the [Moodle App](MoodleApp.md). + ## [4.1.8] - 2023-10-20 ### Changed - Updated project dependencies to current [moodle-cs](https://github.com/moodlehq/moodle-cs) version. @@ -426,7 +429,7 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt ### Fixed - `moodle-plugin-ci validate` now only regards required language strings as present if they are assigned to the - `$string` array. Before, other array variables were accepted although Moodle would not recognise them. + `$string` array. Before, other array variables were accepted although Moodle would not recognise them. ### Added - `moodle-plugin-ci install` now provides an option `--no-init` to skip initialization of the Behat and PHPUnit @@ -465,7 +468,7 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt PHP compatibility issues for the **currently** running PHP version. This makes it important to run this command on your lowest and highest supported PHP version. EG: on PHP 5.6 and 7.1. - `moodle-plugin-ci validate` command now validates tags in Behat feature files. EG: mod_forum should have @mod - and @mod_forum tags in each feature file. + and @mod_forum tags in each feature file. - The `.travis.dist.yml` now installs Version 2 of this tool. - Updated Moodle coding standard to v2.7.0. diff --git a/docs/GHAFileExplained.md b/docs/GHAFileExplained.md index fbc65e2c..99feb24a 100644 --- a/docs/GHAFileExplained.md +++ b/docs/GHAFileExplained.md @@ -124,12 +124,16 @@ jobs: # Other env vars are available for install, namely: # - DB_USER / DB_PASS / DB_NAME / DB_HOST / DB_PORT: used # by install to feed the corresponding --db-xxxx options. + # - MOODLE_APP: used to install dependencies to run Behat tests + # using the Moodle App. - name: Install moodle-plugin-ci run: | moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 env: DB: ${{ matrix.database }} MOODLE_BRANCH: ${{ matrix.moodle-branch }} + # Uncomment this to run Behat tests using the Moodle App. + # MOODLE_APP: 'true' # Steps that are run for the purpose of testing. Any of these steps # can be re-ordered or removed to your liking. And of course, you can diff --git a/docs/Help.md b/docs/Help.md index 33c5db52..4b248ac3 100644 --- a/docs/Help.md +++ b/docs/Help.md @@ -16,6 +16,7 @@ Always a good idea to check the [change log](CHANGELOG.md) if something suddenly * [Ignoring files](IgnoringFiles.md): how to ignore files that might be causing failures. * [Generating code coverage](CodeCoverage.md): how to generate code coverage of your plugin. * [CLI commands and options](CLI.md): the available `moodle-plugin-ci` commands and their options. +* [Moodle App](MoodleApp.md): how to configure `moodle-plugin-ci` to test plugins with mobile support. ## Test steps quick start @@ -84,7 +85,10 @@ There are few important options that you may want to use: - The suite option allows you to set the theme to use for behat test. If not specified, the default theme is used, e.g. usage: `--suite boost` - The profile option allows you to set the browser driver to use, - default is Firefox. If you need Chrome, set `--profile chrome`. + default is Firefox (or Chrome when `MOODLE_APP` is set). If you need a specific browser, + use `--profile chrome` or `--profile firefox`. +- The tags option allows you to specify which scenarios to run filtered by tags, + default is the tag with the plugin's component name, e.g. usage: `--tags="@local_myplugin~@ciskip"` ## Upgrade guides diff --git a/docs/MoodleApp.md b/docs/MoodleApp.md new file mode 100644 index 00000000..44b05872 --- /dev/null +++ b/docs/MoodleApp.md @@ -0,0 +1,20 @@ +--- +layout: page +title: Moodle App +--- + +In order to test plugins with mobile support, the only command that needs a special configuration is `behat`. + +In practice, you only need to set the `MOODLE_APP` env variable to `true`, and all the dependencies will be configured during the `install` command. You can also configure the behaviour of [Acceptance testing for the Moodle App](https://moodledev.io/general/app/development/testing/acceptance-testing) using the following env variables: + +- `MOODLE_APP_DOCKER_IMAGE`: Tag of [the Moodle App Docker image](https://moodledev.io/general/app/development/setup/docker-images) to use for running the app. The default value is `moodlehq/moodleapp:latest-test`. +- `MOODLE_APP_BEHAT_PLUGIN_PROJECT`: Project in github to use for installing the plugin with Behat steps specific to the Moodle App. The default value is `moodlehq/moodle-local_moodleappbehat`. This variable will be ignored if `MOODLE_APP_BEHAT_PLUGIN_REPOSITORY` is set. +- `MOODLE_APP_BEHAT_PLUGIN_REPOSITORY`: Repository url to use for installing the plugin with Behat steps specific to the Moodle App. By default, the github repository defined in `MOODLE_APP_BEHAT_PLUGIN_PROJECT` will be used. +- `MOODLE_APP_BEHAT_PLUGIN_BRANCH`: Branch of the repository to use for installing the plugin with Behat steps specific to the Moodle App. The default value is `latest`. +- `MOODLE_BEHAT_IONIC_WWWROOT`: Value to use in `$CFG->behat_ionic_wwwroot`. The default value is `http://localhost:8100`. This value should only be used if `MOODLE_APP` is not set, and the Moodle App dependencies are configured manually. + +Finally, keep in mind that mobile tests only run on Chrome, so make sure that you're using the correct browser. If you're setting the `MOODLE_APP` variable, the default browser should already be Chrome; but you can set it explicitly using the `--profile` flag otherwise. + +For specific examples, look at the [gha.dist.yml](GHAFileExplained.md) or [.travis.dist.yml](TravisFileExplained.md) files, and uncomment the lines mentioning the app. + +**Important:** Please notice that `MOODLE_APP` only works starting with version 4.1 of the app. If you want to use this setup against older versions, you'll have to use `MOODLE_BEHAT_IONIC_WWWROOT` and configure the dependencies manually (installing the plugin, launching the docker image, etc.). diff --git a/docs/TravisFileExplained.md b/docs/TravisFileExplained.md index 843e4e1f..6469fc8a 100644 --- a/docs/TravisFileExplained.md +++ b/docs/TravisFileExplained.md @@ -52,6 +52,9 @@ env: - PGVER=13 # This line determines which version branch of Moodle to test against. - MOODLE_BRANCH=MOODLE_402_STABLE +# Uncomment this to run Behat tests using the Moodle App. +# - MOODLE_APP=true + # This matrix is used for testing against multiple databases. So for # each version of PHP being tested, one build will be created for each # database listed here. EG: for PHP 7.4, one build will be created diff --git a/docs/index.md b/docs/index.md index 6456d127..f668fdf4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -167,6 +167,7 @@ Next steps on your continuous build journey may include: * Reviewing the [help documentation](Help.md) to further improve and customize your build. * Resolve any build errors you may currently have. Get to that ever rewarding Green Build status. * Show off your build status by adding the build status badge to your plugin's README file. +* Learn how to [configure CI for your mobile plugins in the Moodle App](MoodleApp.md). * Write new tests to increase your code coverage. * Contribute to this repo if you have improvement idea or found an issue. * Enjoy your favorite beverage because you no longer have to waste time manually testing your plugin! diff --git a/gha.dist.yml b/gha.dist.yml index e851848c..e9145af8 100644 --- a/gha.dist.yml +++ b/gha.dist.yml @@ -59,11 +59,12 @@ jobs: echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV - name: Install moodle-plugin-ci - run: | - moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 + run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 env: DB: ${{ matrix.database }} MOODLE_BRANCH: ${{ matrix.moodle-branch }} + # Uncomment this to run Behat tests using the Moodle App. + # MOODLE_APP: 'true' - name: PHP Lint if: ${{ !cancelled() }} diff --git a/res/template/config.php.txt b/res/template/config.php.txt index 8729926a..05b14d81 100644 --- a/res/template/config.php.txt +++ b/res/template/config.php.txt @@ -29,6 +29,9 @@ $CFG->debugdisplay = 1; $CFG->noemailever = true; $CFG->noreplyaddress = 'noreply@localhost.local'; +// App settings. +$CFG->behat_ionic_wwwroot = '{{BEHATIONICWWWROOT}}'; + // PHPUnit settings. $CFG->phpunit_prefix = 'phpu_'; $CFG->phpunit_dataroot = '{{PHPUNITDATAROOT}}'; @@ -40,13 +43,17 @@ $CFG->behat_wwwroot = '{{BEHATWWWROOT}}'; $CFG->behat_faildump_path = '{{BEHATDUMP}}'; $CFG->behat_profiles = [ 'default' => [ - 'browser' => 'firefox', + 'browser' => '{{BEHATDEFAULTBROWSER}}', 'wd_host' => '{{BEHATWDHOST}}', ], 'chrome' => [ 'browser' => 'chrome', 'wd_host' => '{{BEHATWDHOST}}', ], + 'firefox' => [ + 'browser' => 'firefox', + 'wd_host' => '{{BEHATWDHOST}}', + ], ]; {{EXTRACONFIG}} diff --git a/src/Bridge/MoodleConfig.php b/src/Bridge/MoodleConfig.php index eb8fde16..1ffb84eb 100644 --- a/src/Bridge/MoodleConfig.php +++ b/src/Bridge/MoodleConfig.php @@ -34,21 +34,23 @@ public function createContents(AbstractDatabase $database, string $dataDir): str { $template = file_get_contents(__DIR__ . '/../../res/template/config.php.txt'); $variables = [ - '{{DBTYPE}}' => $database->type, - '{{DBLIBRARY}}' => $database->library, - '{{DBHOST}}' => $database->host, - '{{DBPORT}}' => $database->port, - '{{DBNAME}}' => $database->name, - '{{DBUSER}}' => $database->user, - '{{DBPASS}}' => $database->pass, - '{{WWWROOT}}' => 'http://localhost/moodle', - '{{DATAROOT}}' => $dataDir, - '{{PHPUNITDATAROOT}}' => $dataDir . '/phpu_moodledata', - '{{BEHATDATAROOT}}' => $dataDir . '/behat_moodledata', - '{{BEHATDUMP}}' => $dataDir . '/behat_dump', - '{{BEHATWWWROOT}}' => getenv('MOODLE_BEHAT_WWWROOT') ?: 'http://localhost:8000', - '{{BEHATWDHOST}}' => getenv('MOODLE_BEHAT_WDHOST') ?: 'http://localhost:4444/wd/hub', - '{{EXTRACONFIG}}' => self::PLACEHOLDER, + '{{DBTYPE}}' => $database->type, + '{{DBLIBRARY}}' => $database->library, + '{{DBHOST}}' => $database->host, + '{{DBPORT}}' => $database->port, + '{{DBNAME}}' => $database->name, + '{{DBUSER}}' => $database->user, + '{{DBPASS}}' => $database->pass, + '{{WWWROOT}}' => 'http://localhost/moodle', + '{{DATAROOT}}' => $dataDir, + '{{PHPUNITDATAROOT}}' => $dataDir . '/phpu_moodledata', + '{{BEHATDATAROOT}}' => $dataDir . '/behat_moodledata', + '{{BEHATDUMP}}' => $dataDir . '/behat_dump', + '{{BEHATWWWROOT}}' => getenv('MOODLE_BEHAT_WWWROOT') ?: 'http://localhost:8000', + '{{BEHATWDHOST}}' => getenv('MOODLE_BEHAT_WDHOST') ?: 'http://localhost:4444/wd/hub', + '{{BEHATDEFAULTBROWSER}}' => getenv('MOODLE_BEHAT_DEFAULT_BROWSER') ?: (getenv('MOODLE_APP') ? 'chrome' : 'firefox'), + '{{BEHATIONICWWWROOT}}' => getenv('MOODLE_APP') ? 'http://localhost:8100' : (getenv('MOODLE_BEHAT_IONIC_WWWROOT') ?: ''), + '{{EXTRACONFIG}}' => self::PLACEHOLDER, ]; return str_replace(array_keys($variables), array_values($variables), $template); diff --git a/src/Command/BehatCommand.php b/src/Command/BehatCommand.php index aeeecd99..3da0074f 100644 --- a/src/Command/BehatCommand.php +++ b/src/Command/BehatCommand.php @@ -144,7 +144,13 @@ private function startServerProcesses(InputInterface $input): void } // Start docker container using desired image. - if ($input->getOption('profile') === 'chrome') { + $profile = $input->getOption('profile'); + + if ($profile === 'default') { + $profile = getenv('MOODLE_BEHAT_DEFAULT_BROWSER') ?: (getenv('MOODLE_APP') ? 'chrome' : 'firefox'); + } + + if ($profile === 'chrome') { $image = $this->seleniumChromeImage; } elseif ($this->usesLegacyPhpWebdriver()) { $image = $this->seleniumLegacyFirefoxImage; diff --git a/src/Installer/InstallerFactory.php b/src/Installer/InstallerFactory.php index ea92f79d..cdb77ad7 100644 --- a/src/Installer/InstallerFactory.php +++ b/src/Installer/InstallerFactory.php @@ -43,6 +43,13 @@ class InstallerFactory public function addInstallers(InstallerCollection $installers): void { $installers->add(new MoodleInstaller($this->execute, $this->database, $this->moodle, new MoodleConfig(), $this->repo, $this->branch, $this->dataDir)); + + if (getenv('MOODLE_APP')) { + $this->pluginsDir = $this->pluginsDir ?? 'moodle-plugin-ci-plugins'; + + $installers->add(new MoodleAppInstaller($this->execute, $this->pluginsDir)); + } + $installers->add(new PluginInstaller($this->moodle, $this->plugin, $this->pluginsDir, $this->dumper)); $installers->add(new VendorInstaller($this->moodle, $this->plugin, $this->execute, $this->nodeVer)); diff --git a/src/Installer/MoodleAppInstaller.php b/src/Installer/MoodleAppInstaller.php new file mode 100644 index 00000000..432163a5 --- /dev/null +++ b/src/Installer/MoodleAppInstaller.php @@ -0,0 +1,81 @@ +execute = $execute; + $this->pluginsDir = $pluginsDir; + } + + public function install(): void + { + $this->addEnv('MOODLE_APP', 'true'); + + // Launch docker image. + $this->getOutput()->step('Launch Moodle App docker image'); + + $image = getenv('MOODLE_APP_DOCKER_IMAGE') ?: 'moodlehq/moodleapp:latest-test'; + + $this->execute->mustRun([ + 'docker', + 'run', + '-d', + '--rm', + '--name=moodleapp', + '-p', + '8100:80', + $image, + ]); + + // Clone plugin. + $this->getOutput()->step('Clone Moodle App Behat plugin'); + + $pluginProject = getenv('MOODLE_APP_BEHAT_PLUGIN_PROJECT') ?: 'moodlehq/moodle-local_moodleappbehat'; + $pluginRepository = getenv('MOODLE_APP_BEHAT_PLUGIN_REPOSITORY') ?: sprintf('https://github.com/%s.git', $pluginProject); + $pluginBranch = getenv('MOODLE_APP_BEHAT_PLUGIN_BRANCH') ?: 'latest'; + $filesystem = new Filesystem(); + $validate = new Validate(); + $command = [ + 'git', + 'clone', + '--depth', + '1', + '--branch', + $pluginBranch, + $pluginRepository, + ]; + + $filesystem->mkdir($this->pluginsDir); + $storageDir = realpath($validate->directory($this->pluginsDir)); + $this->execute->mustRun(new Process($command, $storageDir, null, null, null)); + } + + public function stepCount(): int + { + return 2; + } +} diff --git a/tests/Bridge/MoodlePluginTest.php b/tests/Bridge/MoodlePluginTest.php index 6d493a7f..1df95de7 100644 --- a/tests/Bridge/MoodlePluginTest.php +++ b/tests/Bridge/MoodlePluginTest.php @@ -125,7 +125,9 @@ public function testGetFiles() $files = $plugin->getFiles($finder); $expected = [ $this->pluginDir . '/classes/math.php', + $this->pluginDir . '/classes/output/mobile.php', $this->pluginDir . '/db/access.php', + $this->pluginDir . '/db/mobile.php', $this->pluginDir . '/db/upgrade.php', $this->pluginDir . '/lang/en/local_ci.php', $this->pluginDir . '/lib.php', @@ -151,7 +153,9 @@ public function testGetRelativeFiles() $plugin = new MoodlePlugin($this->pluginDir); $expected = [ 'classes/math.php', + 'classes/output/mobile.php', 'db/access.php', + 'db/mobile.php', 'db/upgrade.php', 'lang/en/local_ci.php', 'lib.php', diff --git a/tests/Command/CodeCheckerCommandTest.php b/tests/Command/CodeCheckerCommandTest.php index b92883d5..e11019dd 100644 --- a/tests/Command/CodeCheckerCommandTest.php +++ b/tests/Command/CodeCheckerCommandTest.php @@ -69,7 +69,7 @@ public function testExecute() // Verify various parts of the output. $output = $commandTester->getDisplay(); // Verify that the progress information is always printed, no matter there aren't warnings/errors. - $this->assertMatchesRegularExpression('/\.{7} 7 \/ 7 \(100%\)/', $output); + $this->assertMatchesRegularExpression('/\.{9} 9 \/ 9 \(100%\)/', $output); // Also verify display info is correct. $this->assertMatchesRegularExpression('/RUN Moodle CodeSniffer standard on local_ci/', $output); @@ -101,7 +101,7 @@ abstract private function somefunc() { // To verify PHPCompatibility sniff. // Verify various parts of the output. $output = $commandTester->getDisplay(); - $this->assertMatchesRegularExpression('/E\.* 8\.* \/ 8 \(100%\)/', $output); // Progress. + $this->assertMatchesRegularExpression('/E\.* 10\.* \/ 10 \(100%\)/', $output); // Progress. $this->assertMatchesRegularExpression('/\/fixable.php/', $output); // File. $this->assertMatchesRegularExpression('/ 7 ERRORS AND 1 WARNING AFFECTING 7 /', $output); // Summary. $this->assertMatchesRegularExpression('/moodle\.Files\.BoilerplateComment\.Wrong/', $output); // Moodle sniff. diff --git a/tests/Command/CodeFixerCommandTest.php b/tests/Command/CodeFixerCommandTest.php index ef13d480..33231096 100644 --- a/tests/Command/CodeFixerCommandTest.php +++ b/tests/Command/CodeFixerCommandTest.php @@ -76,7 +76,7 @@ public function testExecute() // Verify various parts of the output. $output = $commandTester->getDisplay(); - $this->assertMatchesRegularExpression('/F\.* 8\.* \/ 8 \(100%\)/', $output); // Progress. + $this->assertMatchesRegularExpression('/F\.* 10\.* \/ 10 \(100%\)/', $output); // Progress. $this->assertMatchesRegularExpression('/\/fixable.php/', $output); // File. $this->assertMatchesRegularExpression('/A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE/', $output); // Summary. $this->assertMatchesRegularExpression('/Time:.*Memory:/', $output); // Time. diff --git a/tests/Fake/Process/DummyExecute.php b/tests/Fake/Process/DummyExecute.php index 1f9a3501..b11ccc2f 100644 --- a/tests/Fake/Process/DummyExecute.php +++ b/tests/Fake/Process/DummyExecute.php @@ -18,6 +18,7 @@ class DummyExecute extends Execute { public string $returnOutput = ''; + public array $allCmds = []; public string $lastCmd = ''; // We need this for assertions against the command run. private function getMockProcess(string $cmd) @@ -87,6 +88,8 @@ private function getCommandLine($cmd): string $this->lastCmd = $cmd->getCommandLine(); } + $this->allCmds[] = $this->lastCmd; + return $this->lastCmd; } } diff --git a/tests/Fixture/example-config.php b/tests/Fixture/example-config.php index 950df2a1..034b4022 100644 --- a/tests/Fixture/example-config.php +++ b/tests/Fixture/example-config.php @@ -29,6 +29,9 @@ $CFG->noemailever = true; $CFG->noreplyaddress = 'noreply@localhost.local'; +// App settings. +$CFG->behat_ionic_wwwroot = ''; + // PHPUnit settings. $CFG->phpunit_prefix = 'phpu_'; $CFG->phpunit_dataroot = '/path/to/moodledata/phpu_moodledata'; @@ -47,6 +50,10 @@ 'browser' => 'chrome', 'wd_host' => 'http://localhost:4444/wd/hub', ], + 'firefox' => [ + 'browser' => 'firefox', + 'wd_host' => 'http://localhost:4444/wd/hub', + ], ]; // Extra config. diff --git a/tests/Fixture/moodle-local_ci/classes/output/mobile.php b/tests/Fixture/moodle-local_ci/classes/output/mobile.php new file mode 100644 index 00000000..69ccf915 --- /dev/null +++ b/tests/Fixture/moodle-local_ci/classes/output/mobile.php @@ -0,0 +1,52 @@ +. + +/** + * Mobile class. + * + * @package local_ci + * @copyright 2022 Moodle Pty Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_ci\output; + +/** + * Mobile class. + * + * @package local_ci + * @copyright 2022 Moodle Pty Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mobile { + + /** + * Render index page. + * + * @return array View data. + */ + public static function view_index() { + return [ + 'templates' => [ + [ + 'id' => 'main', + 'html' => '

Hello CI!

', + ], + ], + ]; + } + +} diff --git a/tests/Fixture/moodle-local_ci/db/mobile.php b/tests/Fixture/moodle-local_ci/db/mobile.php new file mode 100644 index 00000000..43dde9fc --- /dev/null +++ b/tests/Fixture/moodle-local_ci/db/mobile.php @@ -0,0 +1,43 @@ +. + +/** + * Plugin mobile file + * + * @package local_ci + * @copyright 2022 Moodle Pty Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$addons = [ + 'local_ci' => [ + 'handlers' => [ + 'index' => [ + 'delegate' => 'CoreMainMenuDelegate', + 'method' => 'view_index', + 'displaydata' => [ + 'title' => 'pluginname', + 'icon' => 'language', + ], + ], + ], + 'lang' => [ + ['pluginname', 'local_ci'], + ], + ], +]; diff --git a/tests/Fixture/moodle-local_ci/tests/behat/login.feature b/tests/Fixture/moodle-local_ci/tests/behat/login.feature index fa3e3256..6d599820 100644 --- a/tests/Fixture/moodle-local_ci/tests/behat/login.feature +++ b/tests/Fixture/moodle-local_ci/tests/behat/login.feature @@ -9,3 +9,15 @@ Feature: Testing feature from auth login Scenario: Log in with the predefined admin user with Javascript enabled Given I log in as "admin" Then I should see "You are logged in as Admin User" in the "page-footer" "region" + + @javascript @app + Scenario: Log in with the predefined admin user in the app + Given I entered the app as "admin" + Then I should find "Your users are not receiving any notification" in the app + + When I press "OK" in the app + And I press the more menu button in the app + Then I should find "Travis Tester" in the app + + When I press "Travis Tester" in the app + Then I should find "Hello CI!" in the app diff --git a/tests/Fixture/phpunit/phpunit-expected.xml b/tests/Fixture/phpunit/phpunit-expected.xml index c4638b5b..82264b61 100644 --- a/tests/Fixture/phpunit/phpunit-expected.xml +++ b/tests/Fixture/phpunit/phpunit-expected.xml @@ -35,6 +35,7 @@ classes/math.php + classes/output/mobile.php lib.php diff --git a/tests/Installer/MoodleAppInstallerTest.php b/tests/Installer/MoodleAppInstallerTest.php new file mode 100644 index 00000000..7d937ff3 --- /dev/null +++ b/tests/Installer/MoodleAppInstallerTest.php @@ -0,0 +1,39 @@ +tempDir); + $installer->install(); + + $this->assertSame($installer->stepCount(), $installer->getOutput()->getStepCount()); + + $this->assertSame(['MOODLE_APP' => 'true'], $installer->getEnv()); + + $this->assertMatchesRegularExpression('/docker/', $execute->allCmds[0]); + $this->assertMatchesRegularExpression('/run/', $execute->allCmds[0]); + $this->assertMatchesRegularExpression('/moodlehq\/moodleapp:latest-test/', $execute->allCmds[0]); + + $this->assertMatchesRegularExpression('/git/', $execute->allCmds[1]); + $this->assertMatchesRegularExpression('/clone/', $execute->allCmds[1]); + $this->assertMatchesRegularExpression('/https:\/\/github\.com\/moodlehq\/moodle-local_moodleappbehat\.git/', $execute->allCmds[1]); + } +}