3 require_once 'CRM/Core/Page.php';
6 * Accept requests for "civicrm/dev/qunit/$ext/$suite"; locate the qunit
7 * test-suite ($suite) in an extension ($ext) and render it.
9 class CRM_Core_Page_QUnit
extends CRM_Core_Page
{
10 protected $tplFile = NULL;
13 list ($ext, $suite) = $this->getRequestExtAndSuite();
14 if (empty($ext) ||
empty($suite)) {
15 throw new CRM_Core_Exception("FIXME: Not implemented: QUnit browser");
18 if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $suite) ||
strpos($suite, '..') !== FALSE) {
19 throw new CRM_Core_Exception("Malformed suite name");
22 $path = CRM_Extension_System
::singleton()->getMapper()->keyToBasePath($ext);
23 if (!is_dir("$path/tests/qunit/$suite")) {
24 throw new CRM_Core_Exception("Failed to locate test suite");
27 // Load the test suite -- including any PHP, TPL, or JS content
28 if (file_exists("$path/tests/qunit/$suite/test.php")) {
29 // e.g. load resources
30 require_once "$path/tests/qunit/$suite/test.php";
32 if (file_exists("$path/tests/qunit/$suite/test.tpl")) {
33 // e.g. setup markup and/or load resources
34 CRM_Core_Smarty
::singleton()->addTemplateDir("$path/tests");
35 $this->assign('qunitTpl', "qunit/$suite/test.tpl");
37 if (file_exists("$path/tests/qunit/$suite/test.js")) {
38 CRM_Core_Resources
::singleton()->addScriptFile($ext, "tests/qunit/$suite/test.js", 1000);
41 CRM_Utils_System
::setTitle(ts('QUnit: %2 (%1)', array(1 => $ext, 2 => $suite)));
42 CRM_Core_Resources
::singleton()
43 ->addScriptFile('civicrm', 'packages/qunit/qunit.js')
44 ->addStyleFile('civicrm', 'packages/qunit/qunit.css');
49 * Extrac the extension and suite from the request path
53 function getRequestExtAndSuite() {
54 $config = CRM_Core_Config
::singleton();
55 $arg = explode('/', $_GET[$config->userFrameworkURLVar
]);
58 && CRM_Utils_Array
::value(2, $arg) == 'qunit'
63 trim(CRM_Utils_Type
::escape($arg[3], 'String'), '/'),
64 trim(CRM_Utils_Type
::escape($arg[4], 'String'), '/'),
68 return array(NULL, NULL);