@@ -146,30 +146,48 @@ function bind($splint, &$bind=null) {
146
146
* @return [type] [description]
147
147
*/
148
148
function test ($ splint , $ strict =true ) {
149
+ // Form hidden field to determine if form parameters have been loaded.
149
150
defined ("TEST_STATUS " ) OR define ("TEST_STATUS " , "test_status " );
150
151
if (!is_dir (APPPATH . "splints/ $ splint/ " )) {
151
152
show_error ("Cannot find splint ' $ splint' " );
152
153
return false ;
153
154
}
154
155
$ this ->helper ("file " );
155
156
$ 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 ;
160
166
}
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 ;
161
171
$ ci =& get_instance ();
172
+ $ platform = $ this ->splint ("splint/platform " );
162
173
if (file_exists (APPPATH . "splints/ $ splint/tests/post_data.json " ) &&
163
174
$ ci ->security ->xss_clean ($ ci ->input ->post (TEST_STATUS )) == "" ) {
164
- $ platform = $ this ->splint ("splint/platform " );
165
175
$ post_data = json_decode (file_get_contents (APPPATH . "splints/ $ splint/tests/post_data.json " ), true );
166
176
$ post_data [TEST_STATUS ] = "ready " ;
167
177
$ platform ->load ->view ("form " , array ("fields " => $ post_data ));
168
178
return true ;
169
179
}
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
+ }
170
188
$ this ->library ("unit_test " );
171
189
$ ci ->unit ->use_strict ($ strict );
172
- if ($ test_classes == null || count ($ test_classes ) == 0 ) { return false ;}
190
+ if (count ($ test_classes ) == 0 ) return false ;
173
191
$ total_tests = 0 ;
174
192
$ test_metrics = array ();
175
193
for ($ x = 0 ; $ x < count ($ test_classes ); $ x ++) {
@@ -195,7 +213,7 @@ function test($splint, $strict=true) {
195
213
* @param [type] $needle [description]
196
214
* @return [type] [description]
197
215
*/
198
- function endsWith ($ haystack , $ needle ) {
216
+ private function endsWith ($ haystack , $ needle ) {
199
217
$ length = strlen ($ needle );
200
218
if ($ length == 0 ) return true ;
201
219
return substr ($ haystack , -$ length ) === $ needle ;
0 commit comments