#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) require File.join( currentPath, '../../lib/masterview/directives/image_tag' ) class ImageTagTest < Test::Unit::TestCase include MasterView::Directives def setup @directives = MasterView::DirectiveSet.new end def test_default tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil) @directives.directives = [] attr_value = "hello world" @directives << Image_tag.new(attr_value) assert_equal nil, @directives.determine_dcs(:stag).render dcs = @directives.determine_dcs(:etag) dcs.context = tag.create_context assert_equal "<%= image_tag 'hello world' %>", dcs.render end def test_default_size tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil) @directives.directives = [] attr_value = "hello world" @directives << Image_tag.new(attr_value) assert_equal nil, @directives.determine_dcs(:stag).render dcs = @directives.determine_dcs(:etag) dcs.context = tag.create_context dcs.context[:tag].attributes['width'] = '20' dcs.context[:tag].attributes['height'] = '10' assert_equal "<%= image_tag 'hello world', :size => '20x10' %>", dcs.render end def test_default_size_alt tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil) @directives.directives = [] attr_value = "hello world" @directives << Image_tag.new(attr_value) assert_equal nil, @directives.determine_dcs(:stag).render dcs = @directives.determine_dcs(:etag) dcs.context = tag.create_context dcs.context[:tag].attributes['width'] = '20' dcs.context[:tag].attributes['height'] = '10' dcs.context[:tag].attributes['alt'] = 'foo' assert_equal "<%= image_tag 'hello world', :alt => 'foo', :size => '20x10' %>", dcs.render end def test_empty_infer_path tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil) @directives.directives = [] attr_value = "" @directives << Image_tag.new(attr_value) assert_equal nil, @directives.determine_dcs(:stag).render dcs = @directives.determine_dcs(:etag) dcs.context = tag.create_context dcs.context[:tag].attributes['src'] = '../../public/images/foo.js' assert_equal "<%= image_tag 'foo.js' %>", dcs.render end def test_empty_infer_path_sub tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil) @directives.directives = [] attr_value = "" @directives << Image_tag.new(attr_value) assert_equal nil, @directives.determine_dcs(:stag).render dcs = @directives.determine_dcs(:etag) dcs.context = tag.create_context dcs.context[:tag].attributes['src'] = '../../public/images/bar/foo.js' assert_equal "<%= image_tag 'bar/foo.js' %>", dcs.render end def test_empty_use_src tag = MasterView::Tag.new(@directives, 'foo', {}, :normal, nil) @directives.directives = [] attr_value = "" @directives << Image_tag.new(attr_value) assert_equal nil, @directives.determine_dcs(:stag).render dcs = @directives.determine_dcs(:etag) dcs.context = tag.create_context dcs.context[:tag].attributes['src'] = '/myimages/foo.js' assert_equal "<%= image_tag '/myimages/foo.js' %>", dcs.render end end