From 5c1cf60ae491cedbe4df9668c9fe47feca03f6db Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 20 Apr 2021 17:26:27 +0200 Subject: [PATCH] MDL-71386 behat: Support for 3.9.5+ mobile app --- lib/behat/classes/behat_config_util.php | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/behat/classes/behat_config_util.php b/lib/behat/classes/behat_config_util.php index 886a74caf89..86f263bd709 100644 --- a/lib/behat/classes/behat_config_util.php +++ b/lib/behat/classes/behat_config_util.php @@ -731,17 +731,28 @@ class behat_config_util { } $installedversion = $package->version; } else if (!empty($CFG->behat_ionic_wwwroot)) { - // Get app version from config.json inside wwwroot. - $jsonurl = $CFG->behat_ionic_wwwroot . '/config.json'; - $json = @download_file_content($jsonurl); + // Get app version from env.json inside wwwroot. + $jsonurl = $CFG->behat_ionic_wwwroot . '/assets/env.json'; + $json = @file_get_contents($jsonurl); if (!$json) { - throw new coding_exception('Unable to load app version from ' . $jsonurl); + // Fall back to ionic 3 config file. + $jsonurl = $CFG->behat_ionic_wwwroot . '/config.json'; + $json = @file_get_contents($jsonurl); + if (!$json) { + throw new coding_exception('Unable to load app version from ' . $jsonurl); + } + $config = json_decode($json); + if ($config === null || empty($config->versionname)) { + throw new coding_exception('Invalid app config data in ' . $jsonurl); + } + $installedversion = str_replace('-dev', '', $config->versionname); + } else { + $env = json_decode($json); + if (empty($env->build->version ?? null)) { + throw new coding_exception('Invalid app config data in ' . $jsonurl); + } + $installedversion = $env->build->version; } - $config = json_decode($json); - if ($config === null || empty($config->versionname)) { - throw new coding_exception('Invalid app config data in ' . $jsonurl); - } - $installedversion = str_replace('-dev', '', $config->versionname); } else { return ''; }