[MOSS] CIV-01-001 - Display sensible error if someone tries to use "qunit" when it...
authorTim Otten <totten@civicrm.org>
Fri, 3 Apr 2020 02:34:00 +0000 (19:34 -0700)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 16 Apr 2020 01:05:50 +0000 (11:05 +1000)
CRM/Core/Page/QUnit.php

index ae1c90c3441adc8fb5ed1cd8a40a70b91efe373c..5fb8bc8b63da744e936a3f35b0fe08369eb96438 100644 (file)
@@ -15,6 +15,13 @@ class CRM_Core_Page_QUnit extends CRM_Core_Page {
    * @throws \CRM_Core_Exception
    */
   public function run() {
+    $qunitJsFile = Civi::paths()->getPath('[civicrm.bower]/qunit/qunit/qunit.js');
+    $qunitJsUrl = Civi::paths()->getUrl('[civicrm.bower]/qunit/qunit/qunit.js');
+    $qunitCssUrl = Civi::paths()->getUrl('[civicrm.bower]/qunit/qunit/qunit.css');
+    if (!file_exists($qunitJsFile)) {
+      throw new \CRM_Core_Exception("QUnit is not available. Please install it in [civicrm.bower]/qunit.");
+    }
+
     list ($ext, $suite) = $this->getRequestExtAndSuite();
     if (empty($ext) || empty($suite)) {
       throw new CRM_Core_Exception("FIXME: Not implemented: QUnit browser");
@@ -45,8 +52,8 @@ class CRM_Core_Page_QUnit extends CRM_Core_Page {
 
     CRM_Utils_System::setTitle(ts('QUnit: %2 (%1)', [1 => $ext, 2 => $suite]));
     CRM_Core_Resources::singleton()
-      ->addScriptFile('civicrm', 'bower_components/qunit/qunit/qunit.js', 1, 'html-header')
-      ->addStyleFile('civicrm', 'bower_components/qunit/qunit/qunit.css', 1, 'html-header');
+      ->addScriptUrl($qunitJsUrl, 1, 'html-header')
+      ->addStyleUrl($qunitCssUrl, 1, 'html-header');
     parent::run();
   }