From e2019fbea258b1cf4521600487dc9f4deae4c968 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 13 May 2024 08:16:18 +0000 Subject: [PATCH] [auto-generated] Update plugin files Check out the commits that caused these changes: https://github.com/moodlehq/moodleapp/compare/6553d20c30a2ed655137e2eae74d46913a2fab60...6ac81d148614f743af92480e53215db92f34a740 --- tests/behat/behat_app.php | 34 +++++++++++++++++++++++++++++++- tests/behat/behat_app_helper.php | 19 +++++++++++++++++- version.php | 2 +- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/tests/behat/behat_app.php b/tests/behat/behat_app.php index c5b4ccf..ca9a155 100644 --- a/tests/behat/behat_app.php +++ b/tests/behat/behat_app.php @@ -20,6 +20,7 @@ require_once(__DIR__ . '/behat_app_helper.php'); use Behat\Behat\Hook\Scope\ScenarioScope; +use Behat\Behat\Hook\Scope\AfterStepScope; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Exception\DriverException; use Behat\Mink\Exception\ExpectationException; @@ -44,7 +45,10 @@ class behat_app extends behat_app_helper { ], ]; - protected $featurepath = ''; + protected $featurepath; + protected $coveragepath; + protected $scenarioslug; + protected $scenariolaststep; /** * @BeforeScenario @@ -56,7 +60,35 @@ public function before_scenario(ScenarioScope $scope) { return; } + $steps = $scope->getScenario()->getSteps(); + + $this->scenarioslug = $this->get_scenario_slug($scope); + $this->scenariolaststep = $steps[count($steps) - 1]; $this->featurepath = dirname($feature->getFile()); + $this->coveragepath = get_config('local_moodleappbehat', 'coverage_path') ?: ($this->featurepath . DIRECTORY_SEPARATOR . 'coverage' . DIRECTORY_SEPARATOR); + } + + /** + * @AfterStep + */ + public function after_step(AfterStepScope $scope) { + $step = $scope->getStep(); + + if ($step !== $this->scenariolaststep || empty($this->coveragepath)) { + return; + } + + if (!is_dir($this->coveragepath)) { + if (!@mkdir($this->coveragepath, 0777, true)) { + throw new Exception("Cannot create {$this->coveragepath} directory."); + } + } + + $coverage = $this->runtime_js('getCoverage()'); + + if (!is_null($coverage)) { + file_put_contents($this->coveragepath . $this->scenarioslug . '.json', $coverage); + } } /** diff --git a/tests/behat/behat_app_helper.php b/tests/behat/behat_app_helper.php index 50a9056..6cf42e8 100644 --- a/tests/behat/behat_app_helper.php +++ b/tests/behat/behat_app_helper.php @@ -18,6 +18,7 @@ require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); +use Behat\Behat\Hook\Scope\ScenarioScope; use Behat\Mink\Exception\DriverException; use Behat\Mink\Exception\ExpectationException; use Moodle\BehatExtension\Exception\SkippedException; @@ -357,7 +358,7 @@ protected function notify_unload(): void { * @return mixed Result. */ protected function runtime_js(string $script) { - return $this->evaluate_script("window.behat.$script"); + return $this->evaluate_script("window.behat?.$script"); } /** @@ -472,6 +473,22 @@ function($context) use ($successXPath) { $this->i_wait_the_app_to_restart(); } + /** + * Get scenario slug. + * + * @param ScenarioScope $scope Scenario scope. + * @return string Slug. + */ + protected function get_scenario_slug(ScenarioScope $scope): string { + $text = $scope->getFeature()->getTitle() . ' ' . $scope->getScenario()->getTitle(); + $text = trim($text); + $text = strtolower($text); + $text = preg_replace('/\s+/', '-', $text); + $text = preg_replace('/[^a-z0-9-]/', '', $text); + + return $text; + } + /** * Returns the current mobile url scheme of the site. */ diff --git a/version.php b/version.php index e3d19d7..0224a77 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2024041700; +$plugin->version = 2024051300; $plugin->requires = 2016052300; $plugin->maturity = MATURITY_STABLE; $plugin->release = '4.4.0';