Skip to content

Commit cadb44a

Browse files
committed
QUnit Support.
1 parent 01dba4a commit cadb44a

File tree

4 files changed

+7071
-7
lines changed

4 files changed

+7071
-7
lines changed

application/core/MY_Loader.php

+25-7
Original file line numberDiff line numberDiff line change
@@ -146,30 +146,48 @@ function bind($splint, &$bind=null) {
146146
* @return [type] [description]
147147
*/
148148
function test($splint, $strict=true) {
149+
// Form hidden field to determine if form parameters have been loaded.
149150
defined("TEST_STATUS") OR define("TEST_STATUS", "test_status");
150151
if (!is_dir(APPPATH . "splints/$splint/")) {
151152
show_error("Cannot find splint '$splint'");
152153
return false;
153154
}
154155
$this->helper("file");
155156
$test_classes = array();
156-
$files = get_filenames(APPPATH . "splints/$splint/tests");
157-
if (!$files) return true;
158-
foreach ($files as $file) {
159-
if ($this->endsWith($file, ".php")) $test_classes[] = $file;
157+
$testDir = APPPATH . "splints/$splint/tests/";
158+
if (!is_dir($testDir)) return true;
159+
$jsTestDir = $testDir . "js/";
160+
$scannedFiles = array_diff(scandir($testDir), array('.', '..'));
161+
$files = array();
162+
$scannedJsFiles = is_dir($jsTestDir) ? array_diff(scandir($jsTestDir), array('.', '..')) : array();
163+
$jsFiles = array();
164+
foreach ($scannedFiles as $file) {
165+
if (is_file($testDir . $file) && $this->endsWith($file, ".php")) $test_classes[] = $file;
160166
}
167+
foreach ($scannedJsFiles as $file) {
168+
if (is_file($jsTestDir . $file ) && $this->endsWith($file, ".php")) $jsTests[] = $file;
169+
}
170+
if (count($test_classes) == 0 && count($jsTests) == 0) return true;
161171
$ci =& get_instance();
172+
$platform = $this->splint("splint/platform");
162173
if (file_exists(APPPATH . "splints/$splint/tests/post_data.json") &&
163174
$ci->security->xss_clean($ci->input->post(TEST_STATUS)) == "") {
164-
$platform = $this->splint("splint/platform");
165175
$post_data = json_decode(file_get_contents(APPPATH . "splints/$splint/tests/post_data.json"), true);
166176
$post_data[TEST_STATUS] = "ready";
167177
$platform->load->view("form", array("fields" => $post_data));
168178
return true;
169179
}
180+
if (isset($jsTests) && count($jsTests) > 0) {
181+
$platform->load->view("js/qunit");
182+
$platform->load->view("css/qunit");
183+
$platform->load->view("qunit_container");
184+
foreach ($jsTests as $test) {
185+
$this->view("../splints/$splint/tests/js/$test");
186+
}
187+
}
170188
$this->library("unit_test");
171189
$ci->unit->use_strict($strict);
172-
if ($test_classes == null || count($test_classes) == 0) {return false;}
190+
if (count($test_classes) == 0) return false;
173191
$total_tests = 0;
174192
$test_metrics = array();
175193
for ($x = 0; $x < count($test_classes); $x++) {
@@ -195,7 +213,7 @@ function test($splint, $strict=true) {
195213
* @param [type] $needle [description]
196214
* @return [type] [description]
197215
*/
198-
function endsWith($haystack, $needle) {
216+
private function endsWith($haystack, $needle) {
199217
$length = strlen($needle);
200218
if ($length == 0) return true;
201219
return substr($haystack, -$length) === $needle;

0 commit comments

Comments
 (0)