From 1c435dfaee7a3aaf8384a31225948e18725cf88e Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 29 Oct 2008 13:19:01 +0000 Subject: [PATCH] FEATURE Added JavaScript unit tests with jQuery QUnit. Can be viewed similiarly to PHPUnit tests through dev/jstests URL. Uses an '; + } + + $this->tearDown(); + } + + function setUp() { + } + + function tearDown() { + } + + protected function getAllTestFiles() { + $testFiles = array(); + + $baseDir = Director::baseFolder(); + $modules = scandir($baseDir); + foreach($modules as $moduleFileOrFolder) { + if( + $moduleFileOrFolder[0] == '.' + || !@is_dir("$baseDir/$moduleFileOrFolder") + || !file_exists("$baseDir/$moduleFileOrFolder/_config.php") + ) { + continue; + } + + $testDir = "$baseDir/$moduleFileOrFolder/javascript/tests"; + if(@is_dir($testDir)) { + $tests = scandir($testDir); + foreach($tests as $testFile) { + $testFileExt = pathinfo("$testDir/$testFile", PATHINFO_EXTENSION); + if(!in_array(strtolower($testFileExt),array('htm','html'))) continue; + $testFileNameWithoutExt = substr($testFile, 0,-strlen($testFileExt)-1); + $testUrl = Director::makeRelative("$testDir/$testFile"); + $testUrl = substr($testUrl, 1); + // @todo Limit to html extension with "Test" suffix + $testFiles[$testFileNameWithoutExt] = $testUrl; + } + } + } + + return $testFiles; + } + + /** + * Returns the URL for a test case file. + * + * @return string + */ + protected function urlForTestCase($testName) { + $allTests = $this->getAllTestFiles(); + return (array_key_exists($testName, $allTests)) ? $allTests[$testName] : false; + } +}