#!/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_field') class TestTextField < Test::Unit::TestCase include MasterView::Directives def setup @directives = MasterView::DirectiveSet.new end def text_field_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_field.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_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text' } ) assert_equal "<%= text_field #{obj}, #{method} %>", ret end def test_extra obj = ':product' method = ':price' ret = text_field_exec(obj, method, "'more', 'stuff'", { 'type' => 'text', 'value' => 'fake text' } ) assert_equal "<%= text_field #{obj}, #{method} %>", ret end def test_disabled obj = ':product' method = ':price' ret = text_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'disabled' => 'disabled'} ) assert_equal "<%= text_field #{obj}, #{method}, :disabled => true %>", ret end def test_size obj = ':product' method = ':price' ret = text_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'size' => '10' } ) assert_equal "<%= text_field #{obj}, #{method}, :size => 10 %>", ret end def test_maxlength obj = ':product' method = ':price' ret = text_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'maxlength' => '21' } ) assert_equal "<%= text_field #{obj}, #{method}, :maxlength => 21 %>", ret end def test_all obj = ':product' method = ':price' ret = text_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'disabled' => 'disabled', 'size' => '10', 'maxlength' => '21', 'readonly' => 'readonly', 'class' => 'classfoo', 'style' => 'stylebar', 'tabindex' => 'tab1', 'accesskey' => 'ak2' } ) assert_equal "<%= text_field #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :disabled => true, :maxlength => 21, :readonly => true, :size => 10, :style => \"stylebar\", :tabindex => \"tab1\" %>", ret end def test_all_uc obj = ':product' method = ':price' ret = text_field_exec(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'DISABLED' => 'DISABLED', 'SIZE' => '10', 'MAXLENGTH' => '21', 'READONLY' => 'readonly', 'CLASS' => 'classfoo', 'STYLE' => 'stylebar', 'TABINDEX' => 'tab1', 'ACCESSKEY' => 'ak2' } ) assert_equal "<%= text_field #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :disabled => true, :maxlength => 21, :readonly => true, :size => 10, :style => \"stylebar\", :tabindex => \"tab1\" %>", ret end end