PHPonTraxTest
[ class tree: PHPonTraxTest ] [ index: PHPonTraxTest ] [ all elements ]

Source for file HelpersTest.php

Documentation is available at HelpersTest.php

  1. <?php
  2. /**
  3. * File for the HelpersTest class
  4. *
  5. * (PHP 5)
  6. *
  7. * @package PHPonTraxTest
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @copyright (c) Walter O. Haas 2006
  10. * @version $Id: HelpersTest.php 196 2006-04-06 17:30:43Z haas $
  11. * @author Walt Haas <haas@xmission.com>
  12. */
  13.  
  14. echo "testing Helpers\n";
  15. require_once 'testenv.php';
  16.  
  17. // Call HelpersTest::main() if this source file is executed directly.
  18. if (!defined("PHPUnit2_MAIN_METHOD")) {
  19. define("PHPUnit2_MAIN_METHOD", "HelpersTest::main");
  20. }
  21.  
  22. require_once "PHPUnit2/Framework/TestCase.php";
  23. require_once "PHPUnit2/Framework/TestSuite.php";
  24.  
  25. // You may remove the following line when all tests have been implemented.
  26. require_once "PHPUnit2/Framework/IncompleteTestError.php";
  27.  
  28. // root Trax files in the test directory
  29. define("TRAX_ROOT", dirname(__FILE__) . "/");
  30. define("TRAX_VIEWS_EXTENTION", "phtml");
  31. $GLOBALS['TRAX_INCLUDES'] =
  32. array( "config" => "config",
  33. "controllers" => "controllers",
  34. "helpers" => "helpers",
  35. "layouts" => "layouts",
  36. "views" => "views");
  37.  
  38. require_once "action_view/helpers.php";
  39. require_once "action_controller.php";
  40. require_once "router.php";
  41. require_once "controllers/application.php";
  42.  
  43. /**
  44. * Extend Helpers class to test protected methods
  45. */
  46. class ExtHelpers extends Helpers
  47. {
  48. function __construct($object_name = null, $attribute_name = null) {
  49. parent::__construct($object_name, $attribute_name);
  50. }
  51.  
  52. function boolean_attribute(&$options, $attribute) {
  53. parent::boolean_attribute($options, $attribute);
  54. }
  55.  
  56. function convert_options($options = array()) {
  57. return parent::convert_options($options);
  58. }
  59.  
  60. function object($object_name = null) {
  61. return parent::object($object_name);
  62. }
  63. } // class ExtHelpers extends Helpers
  64.  
  65. /**
  66. * Dummy controller object
  67. */
  68. class DummyController extends ApplicationController
  69. {
  70. var $some_attr = 'attr value';
  71. } // class DummyController
  72.  
  73. /**
  74. * Test class for Helpers.
  75. * Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 13:23:35.
  76. */
  77. class HelpersTest extends PHPUnit2_Framework_TestCase {
  78. /**
  79. * Runs the test methods of this class.
  80. *
  81. * @access public
  82. * @static
  83. */
  84. public static function main() {
  85. require_once "PHPUnit2/TextUI/TestRunner.php";
  86.  
  87. $suite = new PHPUnit2_Framework_TestSuite("HelpersTest");
  88. $result = PHPUnit2_TextUI_TestRunner::run($suite);
  89. }
  90.  
  91. /**
  92. * Sets up the fixture, for example, open a network connection.
  93. * This method is called before a test is executed.
  94. *
  95. * @access protected
  96. */
  97. protected function setUp() {
  98. $GLOBALS['current_controller_name'] = 'foo_controller';
  99. $GLOBALS['current_controller_path'] = '/foo/bar/mumble';
  100. $GLOBALS['current_controller_object'] = 'nonobject';
  101. }
  102.  
  103. /**
  104. * Tears down the fixture, for example, close a network connection.
  105. * This method is called after a test is executed.
  106. *
  107. * @access protected
  108. */
  109. protected function tearDown() {
  110. }
  111.  
  112.  
  113. /**
  114. * Test constructor
  115. * @todo Figure out how to test first argument
  116. */
  117. public function test__construct() {
  118. // No arguments to constructor
  119. $h = new Helpers;
  120. $this->assertFalse($h->auto_index);
  121. $this->assertEquals('', $h->object_name);
  122. $this->assertNull($h->attribute_name);
  123. $this->assertEquals('foo_controller', $h->controller_name);
  124. $this->assertEquals('/foo/bar/mumble', $h->controller_path);
  125. $this->assertEquals('nonobject', $h->controller_object);
  126. // Only attribute argument to constructor
  127. $h = new Helpers(null,'someattr');
  128. $this->assertFalse($h->auto_index);
  129. $this->assertEquals('', $h->object_name);
  130. $this->assertEquals('someattr', $h->attribute_name);
  131. $this->assertEquals('foo_controller', $h->controller_name);
  132. $this->assertEquals('/foo/bar/mumble', $h->controller_path);
  133. $this->assertEquals('nonobject', $h->controller_object);
  134.  
  135. // Need to figure out how the first argument is used
  136. // and write a test for it.
  137. // Remove the following line when you implement this test.
  138. throw new PHPUnit2_Framework_IncompleteTestError;
  139. }
  140.  
  141. /**
  142. * Test cdata_section().
  143. */
  144. public function testCdata_section() {
  145. // Test the cdata_section() method of the object
  146. $h = new Helpers;
  147. $s = $h->cdata_section('foo');
  148. $this->assertEquals("<![CDATA[foo]]>", $s);
  149. // Test the file function that calls cdata_section()
  150. $s = cdata_section('foo');
  151. $this->assertEquals("<![CDATA[foo]]>", $s);
  152. }
  153.  
  154. /**
  155. * Test tag()
  156. */
  157. public function testTag() {
  158. // Test the tag() method of the object
  159. $h = new Helpers;
  160. $s = $h->tag('p');
  161. $this->assertEquals("<p />\n",$s);
  162. $h = new Helpers;
  163. $s = $h->tag('p', array('id'=>'a&b'));
  164. $this->assertEquals("<p id=\"a&amp;b\" />\n",$s);
  165. $h = new Helpers;
  166. $s = $h->tag('p', array('id'=>'a&b'),true);
  167. $this->assertEquals("<p id=\"a&amp;b\">\n",$s);
  168. // Test the file function that calls tag()
  169. $s = tag('p');
  170. $this->assertEquals("<p />\n",$s);
  171. $s = tag('p', array('id'=>'a&b'));
  172. $this->assertEquals("<p id=\"a&amp;b\" />\n",$s);
  173. $s = tag('p', array('id'=>'a&b'),true);
  174. $this->assertEquals("<p id=\"a&amp;b\">\n",$s);
  175. }
  176.  
  177. /**
  178. * Test content_tag()
  179. */
  180. public function testContent_tag() {
  181. // Test the content_tag() method of the object
  182. $h = new Helpers;
  183. $s = $h->content_tag('p','hello world');
  184. $this->assertEquals("<p >hello world</p>\n",$s);
  185. $h = new Helpers;
  186. $s = $h->content_tag('p','hello world',array('class'=>'content'));
  187. $this->assertEquals("<p class=\"content\">hello world</p>\n",$s);
  188. $h = new Helpers;
  189. $s = $h->content_tag('p','hello world',array('id'=>'a&b'));
  190. $this->assertEquals("<p id=\"a&amp;b\">hello world</p>\n",$s);
  191. // Test the file function that calls content_tag()
  192. $s = content_tag('p','hello world');
  193. $this->assertEquals("<p >hello world</p>\n",$s);
  194. $s = content_tag('p','hello world',array('class'=>'content'));
  195. $this->assertEquals("<p class=\"content\">hello world</p>\n",$s);
  196. }
  197.  
  198. /**
  199. * Test boolean_attribute().
  200. */
  201. public function testBoolean_attribute() {
  202. $e = new ExtHelpers;
  203. $k = array('foo'=>'bar', 'mumble'=>'grumble');
  204. $e->boolean_attribute($k,'foo');
  205. $this->assertEquals(array('foo'=>'foo', 'mumble'=>'grumble'), $k);
  206. }
  207.  
  208. /**
  209. * Test convert_options().
  210. */
  211. public function testConvert_options() {
  212. $e = new ExtHelpers;
  213. $k = array('disabled'=>'foo',
  214. 'readonly'=>'bar',
  215. 'multiple'=>'whocares',
  216. 'mumble'=>'grumble');
  217. $r = $e->convert_options($k);
  218. $this->assertEquals(array('disabled'=>'disabled',
  219. 'readonly'=>'readonly',
  220. 'multiple'=>'multiple',
  221. 'mumble'=>'grumble'),
  222. $r);
  223. }
  224.  
  225. /**
  226. * Test object()
  227. */
  228. public function testObject() {
  229. // Constructing with no object name and then
  230. // calling object with no argument should return null
  231. $e = new ExtHelpers;
  232. $this->assertNull($e->object());
  233. // Create a dummy controller object
  234. $d = new DummyController;
  235. $GLOBALS['current_controller_object'] = $d;
  236. // This should inherit value of current_controller_object
  237. $e = new ExtHelpers;
  238. $this->assertEquals('attr value', $e->object('some_attr'));
  239. // This should inherit object name from constructor
  240. $e = new ExtHelpers('some_attr');
  241. $this->assertEquals('attr value', $e->object());
  242. }
  243.  
  244. /**
  245. * @todo Implement testValue().
  246. */
  247. public function testValue() {
  248. // Remove the following line when you implement this test.
  249. throw new PHPUnit2_Framework_IncompleteTestError;
  250. }
  251.  
  252. /**
  253. * @todo Implement testTo_content_tag().
  254. */
  255. public function testTo_content_tag() {
  256. // Remove the following line when you implement this test.
  257. throw new PHPUnit2_Framework_IncompleteTestError;
  258. }
  259. }
  260.  
  261. // Call HelpersTest::main() if this source file is executed directly.
  262. if (PHPUnit2_MAIN_METHOD == "HelpersTest::main") {
  263. HelpersTest::main();
  264. }
  265.  
  266. // -- set Emacs parameters --
  267. // Local variables:
  268. // tab-width: 4
  269. // c-basic-offset: 4
  270. // c-hanging-comment-ender-p: nil
  271. // indent-tabs-mode: nil
  272. // End:
  273. ?>

Documentation generated on Thu, 04 May 2006 19:47:45 -0600 by phpDocumentor 1.3.0RC4