From 6515d03f7d7852c3207606fc698df0d1f24fb58d Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 17 Jan 2023 18:08:02 +0100 Subject: [PATCH] MOBILE-4239 core: Enable DB logging when needed --- .../tests/behat/behat_app.php | 22 +++++++++++++++++++ src/core/services/db.ts | 3 +-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/local_moodleappbehat/tests/behat/behat_app.php b/local_moodleappbehat/tests/behat/behat_app.php index 168bfa9d5..7a815ec17 100644 --- a/local_moodleappbehat/tests/behat/behat_app.php +++ b/local_moodleappbehat/tests/behat/behat_app.php @@ -19,6 +19,7 @@ require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/behat_app_helper.php'); +use Behat\Behat\Hook\Scope\ScenarioScope; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Exception\DriverException; use Behat\Mink\Exception\ExpectationException; @@ -45,6 +46,27 @@ class behat_app extends behat_app_helper { protected $windowsize = '360x720'; + /** + * @BeforeScenario + */ + public function before_scenario(ScenarioScope $scope) { + if (!$scope->getFeature()->hasTag('app')) { + return; + } + + global $CFG; + + $performanceLogs = $CFG->behat_profiles['default']['capabilities']['extra_capabilities']['goog:loggingPrefs']['performance'] ?? null; + + if ($performanceLogs !== 'ALL') { + return; + } + + // Enable DB Logging only for app tests with performance logs activated. + $this->getSession()->visit($this->get_app_url() . '/assets/env.json'); + $this->execute_script("document.cookie = 'MoodleAppDBLoggingEnabled=true;path=/';"); + } + /** * Opens the Moodle App in the browser and optionally logs in. * diff --git a/src/core/services/db.ts b/src/core/services/db.ts index 036c8718c..87eefd519 100644 --- a/src/core/services/db.ts +++ b/src/core/services/db.ts @@ -18,7 +18,6 @@ import { SQLiteDB } from '@classes/sqlitedb'; import { SQLiteDBMock } from '@features/emulator/classes/sqlitedb'; import { CoreBrowser } from '@singletons/browser'; import { makeSingleton, SQLite } from '@singletons'; -import { CoreAppProvider } from './app'; import { CorePlatform } from '@services/platform'; const tableNameRegex = new RegExp([ @@ -47,7 +46,7 @@ export class CoreDbProvider { * @returns Whether queries should be logged. */ loggingEnabled(): boolean { - return CoreBrowser.hasDevelopmentSetting('DBLoggingEnabled') || CoreAppProvider.isAutomated(); + return CoreBrowser.hasDevelopmentSetting('DBLoggingEnabled'); } /**