#!/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') require File.join( currentPath, '../directive_test_helper' ) DirectiveTestHelpers.load_masterview_directive('text_field') class TestTextField < Test::Unit::TestCase include DirectiveTestHelpers TextField = MasterView::Directives::TextField # test subject ELEMENT_TAG = 'input' def test_metadata assert_equal MasterView::ConfigSettings.namespace_prefix, TextField.namespace_prefix assert_equal 'text_field', TextField.attribute_name end def create_element_with_text_field_directive(obj, method, other_attr_values, attributes) attr_value = "#{obj}, #{method}" attr_value << ', ' << other_attr_values unless other_attr_values.nil? input_tag = create_template_element ELEMENT_TAG, :attributes => attributes, :content => 'hello world' create_directive TextField, attr_value assert_equal '', render_element_event(:stag) # end def test_normal obj = ':product' method = ':price' create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text' } ) expected_content = "<%= text_field( #{obj}, #{method} ) %>" assert_equal expected_content, render_element_event(:etag) end def test_disabled obj = ':product' method = ':price' create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'disabled' => 'disabled'} ) expected_content = "<%= text_field( #{obj}, #{method}, :disabled => true ) %>" assert_equal expected_content, render_element_event(:etag) end def test_size obj = ':product' method = ':price' create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'size' => '10' } ) expected_content = "<%= text_field( #{obj}, #{method}, :size => 10 ) %>" assert_equal expected_content, render_element_event(:etag) end def test_maxlength obj = ':product' method = ':price' create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'maxlength' => '21' } ) expected_content = "<%= text_field( #{obj}, #{method}, :maxlength => 21 ) %>" assert_equal expected_content, render_element_event(:etag) end def test_all obj = ':product' method = ':price' create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'disabled' => 'disabled', 'size' => '10', 'maxlength' => '21', 'readonly' => 'readonly', 'class' => 'classfoo', 'style' => 'stylebar', 'tabindex' => 'tab1', 'accesskey' => 'ak2' } ) expected_content = "<%= text_field( #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :disabled => true, :maxlength => 21, :readonly => true, :size => 10, :style => \"stylebar\", :tabindex => \"tab1\" ) %>" assert_equal expected_content, render_element_event(:etag) end def test_all_uc obj = ':product' method = ':price' create_element_with_text_field_directive(obj, method, nil, { 'type' => 'text', 'value' => 'fake text', 'DISABLED' => 'DISABLED', 'SIZE' => '10', 'MAXLENGTH' => '21', 'READONLY' => 'readonly', 'CLASS' => 'classfoo', 'STYLE' => 'stylebar', 'TABINDEX' => 'tab1', 'ACCESSKEY' => 'ak2' } ) expected_content = "<%= text_field( #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :disabled => true, :maxlength => 21, :readonly => true, :size => 10, :style => \"stylebar\", :tabindex => \"tab1\" ) %>" assert_equal expected_content, render_element_event(:etag) end end