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

Source for file AssetTagHelperTest.php

Documentation is available at AssetTagHelperTest.php

  1. <?php
  2. /**
  3. * File for the AssetTagHelperTest 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: AssetTagHelperTest.php 192 2006-03-27 22:02:53Z haas $
  11. * @author Walt Haas <haas@xmission.com>
  12. */
  13.  
  14. echo "testing AssetTagHelper\n";
  15. require_once 'testenv.php';
  16.  
  17. // Call AssetTagHelperTest::main() if this source file is executed directly.
  18. if (!defined("PHPUnit2_MAIN_METHOD")) {
  19. define("PHPUnit2_MAIN_METHOD", "AssetTagHelperTest::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_PUBLIC", dirname(__FILE__) . "/public");
  31. define("TRAX_URL_PREFIX", "/testprefix");
  32. define("TRAX_VIEWS_EXTENTION", "phtml");
  33. $GLOBALS['TRAX_INCLUDES'] =
  34. array( "config" => "config",
  35. "controllers" => "controllers",
  36. "helpers" => "helpers",
  37. "layouts" => "layouts",
  38. "views" => "views");
  39.  
  40. require_once "action_view/helpers.php";
  41. require_once "inflector.php";
  42. require_once "action_view/helpers/url_helper.php";
  43. require_once "action_view/helpers/asset_tag_helper.php";
  44. require_once "trax_exceptions.php";
  45.  
  46. // parameters need by UrlHelper
  47. $_SERVER['HTTP_HOST'] = 'www.example.com';
  48. $_SERVER['SERVER_PORT'] = '80';
  49.  
  50. // referenced by the AssetTagHelper constructor
  51. $GLOBALS['JAVASCRIPT_DEFAULT_SOURCES'] = array('this', 'that');
  52.  
  53. /**
  54. * Test class for AssetTagHelper.
  55. * Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 13:17:32.
  56. */
  57. class AssetTagHelperTest extends PHPUnit2_Framework_TestCase {
  58. /**
  59. * Runs the test methods of this class.
  60. *
  61. * @access public
  62. * @static
  63. */
  64. public static function main() {
  65. require_once "PHPUnit2/TextUI/TestRunner.php";
  66.  
  67. $suite = new PHPUnit2_Framework_TestSuite("AssetTagHelperTest");
  68. $result = PHPUnit2_TextUI_TestRunner::run($suite);
  69. }
  70.  
  71. /**
  72. * Sets up the fixture, for example, open a network connection.
  73. * This method is called before a test is executed.
  74. *
  75. * @access protected
  76. */
  77. protected function setUp() {
  78. }
  79.  
  80. /**
  81. * Tears down the fixture, for example, close a network connection.
  82. * This method is called after a test is executed.
  83. *
  84. * @access protected
  85. */
  86. protected function tearDown() {
  87. }
  88.  
  89. /**
  90. * Test __construct() method
  91. *
  92. * Test the {@link AssetTagHelper::__construct()} method
  93. */
  94. public function test__construct() {
  95. $ath = new AssetTagHelper;
  96. $this->assertTrue(is_object($ath));
  97. $this->assertEquals('AssetTagHelper', get_class($ath));
  98. $this->assertEquals(array('this','that'),
  99. $ath->javascript_default_sources);
  100. }
  101.  
  102. /**
  103. * Test javascript_path() method
  104. *
  105. * Test the {@link AssetTagHelper::javascript_path()} method
  106. */
  107. public function testJavascript_path() {
  108. $ath = new AssetTagHelper;
  109. $this->assertEquals('/testprefix/javascripts/foo.js',
  110. $ath->javascript_path('foo'));
  111. $this->assertEquals('/testprefix/javascripts/foo.bar',
  112. $ath->javascript_path('foo.bar'));
  113. $this->assertEquals('/testprefix/foo.js',
  114. $ath->javascript_path('/foo'));
  115. $this->assertEquals('http://foo/bar',
  116. $ath->javascript_path('http://foo/bar'));
  117. }
  118.  
  119. /**
  120. * Test javascript_include_tag() method
  121. *
  122. * Test the {@link AssetTagHelper::javascript_include_tag()} method
  123. */
  124. public function testJavascript_include_tag_method() {
  125. $ath = new AssetTagHelper;
  126. $this->assertEquals("<script src=\"/testprefix/javascripts/foo.js\""
  127. . " type=\"text/javascript\"></script>\n",
  128. $ath->javascript_include_tag('foo'));
  129. $this->assertEquals("<script src=\"/testprefix/javascripts/foo.js\""
  130. . " type=\"text/javascript\"></script>\n"
  131. . "<script src=\"/testprefix/javascripts/bar.js\""
  132. . " type=\"text/javascript\"></script>\n",
  133. $ath->javascript_include_tag('foo','bar'));
  134. $this->assertEquals("<script src=\"/testprefix/javascripts/this.js\""
  135. . " type=\"text/javascript\"></script>\n"
  136. . "<script src=\"/testprefix/javascripts/that.js\""
  137. . " type=\"text/javascript\"></script>\n"
  138. . "<script src=\"/testprefix/javascripts/application.js\""
  139. . " type=\"text/javascript\"></script>\n",
  140. $ath->javascript_include_tag('defaults'));
  141. }
  142.  
  143. /**
  144. * Test the javascript_include_tag() function
  145. *
  146. * Test the {@link javascript_include_tag()} function in
  147. * procedural file {@link asset_tag_helper.php}
  148. */
  149. public function testJavascript_include_tag_function() {
  150. $this->assertEquals("<script src=\"/testprefix/javascripts/foo.js\""
  151. . " type=\"text/javascript\"></script>\n",
  152. javascript_include_tag('foo'));
  153. }
  154.  
  155. /**
  156. * Test stylesheet_path() method
  157. *
  158. * Test the {@link AssetTagHelper::stylesheet_path()} method
  159. */
  160. public function testStylesheet_path() {
  161. $ath = new AssetTagHelper;
  162. $this->assertEquals('/testprefix/stylesheets/foo.css',
  163. $ath->stylesheet_path('foo'));
  164. $this->assertEquals('/testprefix/stylesheets/foo.bar',
  165. $ath->stylesheet_path('foo.bar'));
  166. $this->assertEquals('/testprefix/foo.css',
  167. $ath->stylesheet_path('/foo'));
  168. $this->assertEquals('http://foo/bar',
  169. $ath->stylesheet_path('http://foo/bar'));
  170. }
  171.  
  172. /**
  173. * Test stylesheet_link_tag() method
  174. *
  175. * Test the {@link AssetTagHelper::stylesheet_link_tag()} method
  176. */
  177. public function testStylesheet_link_tag_method() {
  178. $ath = new AssetTagHelper;
  179. $this->assertEquals('<link href="/testprefix/stylesheets/foo.css"'
  180. . ' media="screen" rel="Stylesheet"'
  181. . ' type="text/css" />'."\n",
  182. $ath->stylesheet_link_tag("foo"));
  183. $this->assertEquals('<link href="/testprefix/stylesheets/foo.css"'
  184. . ' media="screen" rel="Stylesheet"'
  185. . ' type="text/css" />'."\n"
  186. . '<link href="/testprefix/stylesheets/bar.css"'
  187. . ' media="screen" rel="Stylesheet"'
  188. . ' type="text/css" />'."\n",
  189. $ath->stylesheet_link_tag("foo","bar"));
  190. $this->assertEquals('<link href="/testprefix/stylesheets/foo.css"'
  191. . ' media="screen" rel="Screenstyle"'
  192. . ' type="text/css" />'."\n",
  193. $ath->stylesheet_link_tag("foo",
  194. array("rel"=>"Screenstyle")));
  195. $this->assertEquals('<link href="/testprefix/stylesheets/foo.css"'
  196. . ' media="all" rel="Stylesheet"'
  197. . ' type="text/css" />'."\n",
  198. $ath->stylesheet_link_tag("foo",
  199. array("media"=>"all")));
  200. $this->assertEquals('<link href="/testprefix/stylesheets/foo.css"'
  201. . ' media="screen" rel="Stylesheet"'
  202. . ' type="text/plain" />'."\n",
  203. $ath->stylesheet_link_tag("foo",
  204. array("type"=>"text/plain")));
  205. $this->assertEquals('<link href="/bar/mumble.css"'
  206. . ' media="screen" rel="Stylesheet"'
  207. . ' type="text/css" />'."\n",
  208. $ath->stylesheet_link_tag("foo",
  209. array("href"=>"/bar/mumble.css")));
  210. }
  211.  
  212. /**
  213. * Test stylesheet_link_tag() function
  214. *
  215. * Test the {@link stylesheet_link_tag()} function in procedural
  216. * file {@link asset_tag_helper.php}
  217. */
  218. public function testStylesheet_link_tag_function() {
  219. $this->assertEquals('<link href="/testprefix/stylesheets/foo.css"'
  220. . ' media="screen" rel="Stylesheet"'
  221. . ' type="text/css" />'."\n",
  222. stylesheet_link_tag("foo"));
  223. }
  224.  
  225. /**
  226. * Test image_path() method
  227. *
  228. * Test the {@link AssetTagHelper::image_path()} method
  229. */
  230. public function testImage_path() {
  231. $ath = new AssetTagHelper;
  232. $this->assertEquals('/testprefix/images/foo.png',
  233. $ath->image_path('foo'));
  234. $this->assertEquals('/testprefix/images/foo.bar',
  235. $ath->image_path('foo.bar'));
  236. $this->assertEquals('/testprefix/foo.png',
  237. $ath->image_path('/foo'));
  238. $this->assertEquals('http://foo/bar',
  239. $ath->image_path('http://foo/bar'));
  240. }
  241.  
  242. /**
  243. * Test image_tag() method
  244. *
  245. * Test the {@link AssetTagHelper::image_tag()} method
  246. */
  247. public function testImage_tag_method() {
  248. $ath = new AssetTagHelper;
  249. $this->assertEquals('<img alt="Foo"'
  250. . ' src="/testprefix/images/foo.png" />'."\n",
  251. $ath->image_tag('foo'));
  252. $this->assertEquals('<img alt="Bar"'
  253. . ' src="/testprefix/images/foo.png" />'."\n",
  254. $ath->image_tag('foo', array('alt' => 'Bar')));
  255. $this->assertEquals('<img alt="Foo" height="45"'
  256. . ' src="/testprefix/images/foo.png"'
  257. . ' width="30" />'."\n",
  258. $ath->image_tag('foo', array('width' => '30',
  259. 'height' => '45')));
  260. $this->assertEquals('<img alt="Foo" height="45"'
  261. . ' src="/testprefix/images/foo.png"'
  262. . ' width="30" />'."\n",
  263. $ath->image_tag('foo', array('size' => '30x45')));
  264. }
  265.  
  266. /**
  267. * Test the image_tag() function
  268. *
  269. * Test the {@link image_tag()} function in procedural file
  270. * {@link asset_helper.php}
  271. */
  272. public function testImage_tag_function() {
  273. $this->assertEquals('<img alt="Foo"'
  274. . ' src="/testprefix/images/foo.png" />'."\n",
  275. image_tag('foo'));
  276. }
  277.  
  278. /**
  279. * @todo Implement testAuto_discovery_link_tag_method().
  280. */
  281. public function testAuto_discovery_link_tag_method() {
  282. $ath = new AssetTagHelper;
  283. // Remove the following line when you implement this test.
  284. throw new PHPUnit2_Framework_IncompleteTestError;
  285. }
  286.  
  287. /**
  288. * @todo Implement testAuto_discovery_link_tag_function().
  289. */
  290. public function testAuto_discovery_link_tag_function() {
  291. // Remove the following line when you implement this test.
  292. throw new PHPUnit2_Framework_IncompleteTestError;
  293. }
  294. }
  295.  
  296. // Call AssetTagHelperTest::main() if this source file is executed directly.
  297. if (PHPUnit2_MAIN_METHOD == "AssetTagHelperTest::main") {
  298. AssetTagHelperTest::main();
  299. }
  300.  
  301. // -- set Emacs parameters --
  302. // Local variables:
  303. // tab-width: 4
  304. // c-basic-offset: 4
  305. // c-hanging-comment-ender-p: nil
  306. // indent-tabs-mode: nil
  307. // End:
  308. ?>

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