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