<?php require_once dirname(__FILE__) . "/../spec_helper.php"; describe("Helpers -> to_attributes", function () { it("returns array with attributes", function () { $attr = to_attributes(array("src" => "filename", "type" => "text/javascript")); assert_equal($attr, array('src="filename"', 'type="text/javascript"')); }); }); describe("Helpers -> content_tag", function () { it("returns html tag for DIV tag", function () { $html = content_tag("div", "Div Tag"); assert_equal($html, "<div>Div Tag</div>"); }); }); describe("Helpers -> stylesheet_link_tag", function () { it("returns css stylesheet html tag", function () { $tag = stylesheet_link_tag("master"); assert_equal($tag, '<link href="/stylesheets/master.css" media="screen" rel="stylesheet" type="text/css" />'); }); it("merges attributes for stylesheet helper", function () { $tag = stylesheet_link_tag("master", array("media" => "print")); assert_equal($tag, '<link href="/stylesheets/master.css" media="print" rel="stylesheet" type="text/css" />'); }); }); describe("Helpers -> javascript_include_tag", function () { it("create html tag for javascript tag", function () { $tag = javascript_include_tag("master"); assert_equal($tag, '<script type="text/javascript" src="/javascripts/master.js"></script>'); }); });
function form_tag($url, $options = array()) { if (array_key_exists("multipart", $options) && $options["multipart"] === true) { if (empty($options["method"])) { $options["method"] = "post"; } $options["enctype"] = "multipart/form-data"; } else { $options["method"] = "get"; } $new_options = array(); foreach ($options as $k => $v) { if ($k !== "multipart") { $new_options[$k] = $v; } } $options = $new_options; unset($new_options); $attributes = join(" ", to_attributes($options)); $tag = "<form action=\"{$url}\""; if (strlen($attributes) > 0) { $tag .= " {$attributes}"; } $tag .= ">"; return $tag; }