From dd4d110c9bdda8ab0817f7a05dde601d026ef843 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 3 May 2022 20:40:08 +0100 Subject: [PATCH] MDL-74636 behat: step to skip this scenario if a plugin isn't installed --- lib/tests/behat/behat_general.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 25a66988619..79a000b3c6d 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1922,6 +1922,21 @@ EOF; throw new \Moodle\BehatExtension\Exception\SkippedException(); } + /** + * Checks if given plugin is installed, and skips the current scenario if not. + * + * @Given the :plugin plugin is installed + * @param string $plugin frankenstyle plugin name, e.g. 'filter_embedquestion'. + * @throws \Moodle\BehatExtension\Exception\SkippedException + */ + public function plugin_is_installed(string $plugin): void { + $path = core_component::get_component_directory($plugin); + if (!is_readable($path . '/version.php')) { + throw new \Moodle\BehatExtension\Exception\SkippedException( + 'Skipping this scenario because the ' . $plugin . ' is not installed.'); + } + } + /** * Checks focus is with the given element. *