/javascript/tests
 * and includes them as iFrames.
 * 
 * To create your own tests, please use this template:
 * 
 * 
 * 
 * 	
 * 		jQuery - Validation Test Suite 
 * 		
 * 		
 * 
 * @package framework
 * @subpackage testing
 */
class JSTestRunner extends Controller {
	/** @ignore */
	private static $default_reporter;
	
	private static $url_handlers = array(
		'' => 'browse',
		'$TestCase' => 'only',
	);
	
	private static $allowed_actions = array(
		'index',
		'all',
		'browse',
		'only'
	);
	
	/**
	 * Override the default reporter with a custom configured subclass.
	 *
	 * @param string $reporter
	 */
	public static function set_reporter($reporter) {
		if (is_string($reporter)) $reporter = new $reporter;
		self::$default_reporter = $reporter;
	}
	
	public function init() {
		parent::init();
		
		if(Director::is_cli()) {
			echo "Error: JSTestRunner cannot be run in CLI mode\n";
			die();
		}
		
		if (!self::$default_reporter) self::set_reporter('DebugView');
	}
	
	public function Link() {
		return Controller::join_links(Director::absoluteBaseURL(), 'dev/jstests/');
	}
	
	/**
	 * Run all test classes
	 */
	public function all() {
		$this->runTests(array_keys($this->getAllTestFiles()));
	}
	
	/**
	 * Browse all enabled test cases in the environment
	 */
	public function browse() {
		self::$default_reporter->writeHeader();
		echo '
';
		echo '
Available Tests ';
		echo '';
		echo '';
		$tests = $this->getAllTestFiles();
		echo "
";
		echo "
";
		foreach ($tests as $testName => $testFilePath) {
			echo "
";
		}
		echo '