diff --git a/build.xml b/build.xml index 0dc33074cf257d7f11be9ec436ed10a40f43d03f..de28a49d5ab9e4e96490937cac0057fbe2e2fdaa 100644 --- a/build.xml +++ b/build.xml @@ -306,12 +306,13 @@ </else> </if> - <!-- Update config.ini to activate DB connection and exception logging --> + <!-- Update config.ini to activate DB connection, exception logging and test mode --> <copy file="${srcdir}/config/vufind/config.ini" tofile="${srcdir}/local/config/vufind/config.ini"> <filterchain> <replaceregexp> <regexp pattern="mysql://root@localhost/vufind" replace="${db_connection_string}" /> <regexp pattern=";file\s+= /var/log/vufind.log:alert,error,notice,debug" replace="file = ${srcdir}/vufind-exception.log:alert-5,error-5" /> + <regexp pattern="(\[System\]\s+)" replace="\1runningTestSuite=1" /> </replaceregexp> </filterchain> </copy> diff --git a/module/VuFind/src/VuFind/Bootstrapper.php b/module/VuFind/src/VuFind/Bootstrapper.php index 440d9ae610f14373bd07ea21798e03ba5415c897..ff13b3e683e5937d4e5d94fa7df3a5190fda5ea0 100644 --- a/module/VuFind/src/VuFind/Bootstrapper.php +++ b/module/VuFind/src/VuFind/Bootstrapper.php @@ -103,6 +103,25 @@ class Bootstrapper $this->config = $sm->get(\VuFind\Config\PluginManager::class)->get('config'); } + /** + * Set up cookie to flag test mode. + * + * @return void + */ + protected function initTestMode() + { + // If we're in test mode (as determined by the config.ini property installed + // by the build.xml startup process), set a cookie so the front-end code can + // act accordingly. (This is needed to work around a problem where opening + // print dialogs during testing stalls the automated test process). + if ($this->config->System->runningTestSuite ?? false) { + $app = $this->event->getApplication(); + $sm = $app->getServiceManager(); + $cm = $sm->get(\VuFind\Cookie\CookieManager::class); + $cm->set('VuFindTestSuiteRunning', '1', 0, false); + } + } + /** * Initialize dynamic debug mode (debug initiated by a ?debug=true parameter). * diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js index 7af5a6f659cc28ea74b2222bcc142e5fcfeba98b..40e107357412e6b95a2451b2752898c3c02f4c96 100644 --- a/themes/bootstrap3/js/common.js +++ b/themes/bootstrap3/js/common.js @@ -428,7 +428,14 @@ $(document).ready(function commonDocReady() { if (url.indexOf('?' + 'print' + '=') !== -1 || url.indexOf('&' + 'print' + '=') !== -1) { $("link[media='print']").attr("media", "all"); $(document).ajaxStop(function triggerPrint() { - window.print(); + // Print dialogs cause problems during testing, so disable them + // when the "test mode" cookie is set. This should never happen + // under normal usage outside of the Phing startup process. + if (document.cookie.indexOf('VuFindTestSuiteRunning=') === -1) { + window.print(); + } else { + console.log("Printing disabled due to test mode."); + } }); // Make an ajax call to ensure that ajaxStop is triggered $.getJSON(VuFind.path + '/AJAX/JSON', {method: 'keepAlive'});