| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 require_once(dirname(__FILE__) . '/lmbTestTreePath.class.php'); 10 require_once(dirname(__FILE__) . '/lmbTestRunner.class.php'); 11 require_once(dirname(__FILE__) . '/lmbTestHTMLReporter.class.php'); 12 13 /** 14 * class lmbTestWebUI. 15 * 16 * @package tests_runner 17 * @version $Id: lmbTestWebUI.class.php 6022 2007-06-28 13:35:51Z pachanga $ 18 */ 19 class lmbTestWebUI 20 { 21 protected $tree; 22 protected $encoding = 'UTF-8'; 23 24 function __construct($root_node) 25 { 26 $this->root_node = $root_node; 27 } 28 29 function setEncoding($encoding) 30 { 31 $this->encoding = $encoding; 32 } 33 34 protected function _getReporter() 35 { 36 return new lmbTestHTMLReporter($this->encoding); 37 } 38 39 protected function _getBaseUrl() 40 { 41 return $_SERVER['PHP_SELF']; 42 } 43 44 function run() 45 { 46 if(isset($_GET['perform'])) 47 { 48 if(is_array($_GET['perform'])) 49 { 50 foreach(array_keys($_GET['perform']) as $path) 51 $this->perform(lmbTestTreePath :: normalize($path)); 52 } 53 else 54 $this->perform(lmbTestTreePath :: normalize($_GET['perform'])); 55 } 56 elseif(isset($_GET['browse'])) 57 $this->browse(lmbTestTreePath :: normalize($_GET['browse'])); 58 else 59 $this->browse(); 60 } 61 62 function perform($path) 63 { 64 $runner = new lmbTestRunner(); 65 $runner->setReporter($this->_getReporter()); 66 $runner->run($this->root_node, $path); 67 68 if(isset($_GET['back'])) 69 $postfix = ''; 70 else 71 $postfix = '/..'; 72 73 echo '<small>' . $runner->getRunTime() . '</small>'; 74 echo '<p>' . $this->_createBrowseLink($path . $postfix, 'Back') . '</p>'; 75 } 76 77 function browse($path='/') 78 { 79 $node = $this->root_node->findChildByPath($path); 80 81 echo '<html><body><style>@import url("style.css");</style>'; 82 83 if($this->root_node !== $node) 84 echo '<p>' . $this->_createBrowseLink($path . '/..', 'Back'); 85 86 $sub_nodes = $node->getChildren(); 87 88 $buffer = ''; 89 90 $buffer .= "<p>Available test groups in '" . $node->getTestLabel() . "':\n"; 91 $buffer .= '<p>' . $this->_createPerformLink($path, 'Run all tests from this group', true); 92 93 if(sizeof($sub_nodes)) 94 { 95 $buffer .= "<p><form action='" . $this->_getBaseURL(). "' name='tests' method='GET'>\n"; 96 $buffer .= $this->_createAntiEmptySelectionHiddenInput(); 97 $buffer .= $this->_getToggleJS(); 98 $buffer .= $this->_createRunSelectedButton(); 99 $buffer .= "<p><a href='#' onclick='toggle_checkbox()'>toggle all</a></p>"; 100 $buffer .= "<table>"; 101 102 foreach($sub_nodes as $index => $sub_node) 103 { 104 if($index % 2) 105 $class_name = 'odd'; 106 else 107 $class_name = 'even'; 108 $buffer .= "<tr class='{$class_name}'>"; 109 $buffer .= "<td>" . $this->_createPerformCheckBox("{$path}/{$index}") . "</td>"; 110 111 if($sub_node->isTerminal()) 112 { 113 $buffer .= "<td>" . $this->_createPerformLink("{$path}/{$index}", 'P') . "</td>"; 114 } 115 else 116 { 117 $buffer .= "<td>" . $this->_createPerformLink("{$path}/{$index}", 'P') . 118 $this->_createBrowseLink("{$path}/{$index}", 'B') ."</td>"; 119 } 120 121 $buffer .= "<td>" . $sub_node->getTestLabel() . "</td></tr>\n"; 122 } 123 $buffer .= "</table>\n"; 124 $buffer .= $this->_createRunSelectedButton(); 125 $buffer .= "</form>\n"; 126 } 127 else 128 $buffer .= "<p>No groups available.</p> \n"; 129 130 echo $buffer; 131 132 echo '</body></html>'; 133 } 134 135 protected function _createPerformHref($path) 136 { 137 return $this->_getBaseURL() . "?perform=$path"; 138 } 139 140 protected function _createPerformLink($path, $title, $need_back = false) 141 { 142 $back = $need_back ? '&back=1' : ''; 143 return "<a href='" . $this->_createPerformHref($path) . "$back'>$title</a> "; 144 } 145 146 protected function _createBrowseHref($path) 147 { 148 return $this->_getBaseURL() . "?browse=$path"; 149 } 150 151 protected function _createBrowseLink($path, $title) 152 { 153 return "<a href='" . $this->_createBrowseHref($path) . "'>$title</a> "; 154 } 155 156 protected function _createPerformCheckBox($path) 157 { 158 return "<input type='checkbox' name='perform[$path]'>"; 159 } 160 161 protected function _createRunSelectedButton() 162 { 163 return "<input type='submit' value='Run selected tests'>\n"; 164 } 165 166 protected function _createAntiEmptySelectionHiddenInput() 167 { 168 if(isset($_GET['perform'])) 169 return ''; 170 return "<input type='hidden' name='browse' value='" . 171 (isset($_GET['browse']) ? $_GET['browse'] : '/') . "'>"; 172 } 173 174 protected function _getToggleJS() 175 { 176 return <<<EOD 177 <script> 178 var toggle_mark = 0; 179 function toggle_checkbox() { 180 toggle_mark = toggle_mark ? 0 : 1; 181 inputs = document.getElementsByTagName('input'); 182 for(i=0;i<inputs.length;i++) { 183 var item = inputs[i]; 184 item.checked = toggle_mark; 185 } 186 } 187 </script> 188 EOD; 189 } 190 } 191 192 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Dec 2 03:54:09 2008 | Cross-referenced by PHPXref 0.7 |