#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) require File.join( currentPath, '../../lib/masterview/directives/text_area') class TestTextArea < Test::Unit::TestCase include MasterView::Directives def setup @directives = MasterView::DirectiveSet.new end def text_area_exec(obj, method, other, options) attr_value = "#{obj}, #{method}" attr_value << ', ' << other unless other.nil? tag = MasterView::Tag.new(@directives, 'input', options, :normal, nil) @directives.directives = [] @directives << Text_area.new(attr_value) assert_equal nil, @directives.determine_dcs(:stag).render dcs = @directives.determine_dcs(:etag) dcs.context = tag.create_context dcs.context[:tag].content = "hello world" dcs.render end def test_normal obj = ':product' method = ':price' ret = text_area_exec(obj, method, nil, {} ) assert_equal "<%= text_area #{obj}, #{method} %>", ret end def test_extra obj = ':product' method = ':price' ret = text_area_exec(obj, method, "'more', 'stuff'", { 'type' => 'text', 'value' => 'fake text' } ) assert_equal "<%= text_area #{obj}, #{method} %>", ret end def test_rows obj = ':product' method = ':price' ret = text_area_exec(obj, method, nil, { 'rows' => '4'} ) assert_equal "<%= text_area #{obj}, #{method}, :rows => 4 %>", ret end def test_cols obj = ':product' method = ':price' ret = text_area_exec(obj, method, nil, { 'cols' => 6 } ) assert_equal "<%= text_area #{obj}, #{method}, :cols => 6 %>", ret end def test_all obj = ':product' method = ':price' ret = text_area_exec(obj, method, nil, { 'rows' => 4, 'cols' => 6, 'disabled' => 'disabled', 'readonly' => 'readonly', 'class' => 'classfoo', 'style' => 'stylebar', 'tabindex' => 'tab1', 'accesskey' => 'ak2' } ) assert_equal "<%= text_area #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :cols => 6, :disabled => true, :readonly => true, :rows => 4, :style => \"stylebar\", :tabindex => \"tab1\" %>", ret end def test_all_uc obj = ':product' method = ':price' ret = text_area_exec(obj, method, nil, { 'ROWS' => 4, 'COLS' => 6, 'DISABLED' => 'DISABLED', 'READONLY' => 'readonly', 'CLASS' => 'classfoo', 'STYLE' => 'stylebar', 'TABINDEX' => 'tab1', 'ACCESSKEY' => 'ak2' } ) assert_equal "<%= text_area #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :cols => 6, :disabled => true, :readonly => true, :rows => 4, :style => \"stylebar\", :tabindex => \"tab1\" %>", ret end end