2011-04-28 06:49:03 +00:00
|
|
|
require 'test_helper'
|
|
|
|
require 'mocha'
|
|
|
|
require 'ostruct'
|
|
|
|
|
2011-06-16 03:37:23 +00:00
|
|
|
class SpritesImageTest < Test::Unit::TestCase
|
|
|
|
include SpriteHelper
|
2011-04-28 06:49:03 +00:00
|
|
|
def setup
|
2011-07-26 20:20:51 +00:00
|
|
|
create_sprite_temp
|
2011-04-28 06:49:03 +00:00
|
|
|
file = StringIO.new("images_path = #{@images_src_path.inspect}\n")
|
|
|
|
Compass.add_configuration(file, "sprite_config")
|
|
|
|
@repeat = 'no-repeat'
|
|
|
|
@spacing = 0
|
|
|
|
@position = 100
|
|
|
|
@offset = 100
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:sprite_filename) { 'squares/ten-by-ten.png' }
|
2011-07-27 06:39:24 +00:00
|
|
|
let(:sprite_path) { File.join(@images_tmp_path, sprite_filename) }
|
2011-04-28 06:49:03 +00:00
|
|
|
let(:sprite_name) { File.basename(sprite_filename, '.png') }
|
2011-04-29 03:09:43 +00:00
|
|
|
|
2011-04-28 06:49:03 +00:00
|
|
|
|
2011-06-16 03:37:23 +00:00
|
|
|
def options
|
2011-04-28 06:49:03 +00:00
|
|
|
options = {:offset => @offset}
|
|
|
|
options.stubs(:get_var).with(anything).returns(nil)
|
|
|
|
::OpenStruct.any_instance.stubs(:unitless?).returns(true)
|
|
|
|
options.stubs(:get_var).with("#{sprite_name}-repeat").returns(::OpenStruct.new(:value => @repeat))
|
|
|
|
options.stubs(:get_var).with("#{sprite_name}-spacing").returns(::OpenStruct.new(:value => @spacing))
|
|
|
|
options.stubs(:get_var).with("#{sprite_name}-position").returns(::OpenStruct.new(:value => @position))
|
2011-06-25 05:28:01 +00:00
|
|
|
options.stubs(:get_var).with("layout").returns(::OpenStruct.new(:value => 'vertical'))
|
2011-04-28 06:49:03 +00:00
|
|
|
options
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let(:digest) { Digest::MD5.file(sprite_path).hexdigest }
|
|
|
|
|
|
|
|
|
2011-06-19 16:26:38 +00:00
|
|
|
let(:image) { Compass::SassExtensions::Sprites::Image.new(sprite_map_test(options), File.join(sprite_filename), options)}
|
2011-04-28 06:49:03 +00:00
|
|
|
|
|
|
|
test 'initialize' do
|
|
|
|
assert_equal sprite_name, image.name
|
|
|
|
assert_equal sprite_path, image.file
|
|
|
|
assert_equal sprite_filename, image.relative_file
|
|
|
|
assert_equal 10, image.width
|
|
|
|
assert_equal 10, image.height
|
|
|
|
assert_equal digest, image.digest
|
|
|
|
assert_equal 0, image.top
|
|
|
|
assert_equal 0, image.left
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'hover' do
|
|
|
|
assert_equal 'ten-by-ten_hover', image.hover.name
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'no parent' do
|
|
|
|
assert_nil image.parent
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'image type is nil' do
|
|
|
|
@repeat = nil
|
|
|
|
assert_nil image.repeat
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test 'image type is "global"' do
|
|
|
|
@repeat = 'global'
|
|
|
|
assert_equal @repeat, image.repeat
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'image type is "no-repeat"' do
|
|
|
|
assert_equal 'no-repeat', image.repeat
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'image position' do
|
|
|
|
assert_equal Sass::Script::Number.new(100, ["px"]).value, image.position.value
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'image spacing' do
|
|
|
|
@spacing = 10
|
|
|
|
assert_equal @spacing, image.spacing
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'offset' do
|
|
|
|
assert_equal @offset, image.offset
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'neither, uses 0' do
|
|
|
|
@offset = 0
|
|
|
|
img = image
|
|
|
|
img.position.stubs(:unitless?).returns(false)
|
|
|
|
assert_equal 0, img.offset
|
|
|
|
end
|
|
|
|
|
2011-07-27 06:39:24 +00:00
|
|
|
|
|
|
|
test 'gets name for sprite in search path' do
|
|
|
|
Compass.reset_configuration!
|
|
|
|
uri = 'foo/*.png'
|
|
|
|
other_folder = File.join(@images_tmp_path, '../other-temp')
|
|
|
|
FileUtils.mkdir_p other_folder
|
|
|
|
FileUtils.mkdir_p File.join(other_folder, 'foo')
|
|
|
|
%w(my bar).each do |file|
|
|
|
|
FileUtils.touch(File.join(other_folder, "foo/#{file}.png"))
|
|
|
|
end
|
|
|
|
config = Compass::Configuration::Data.new('config')
|
|
|
|
config.images_path = @images_tmp_path
|
|
|
|
config.sprite_load_path = [@images_tmp_path, other_folder]
|
|
|
|
Compass.add_configuration(config, "sprite_config")
|
|
|
|
image = Compass::SassExtensions::Sprites::Image.new(sprite_map_test(options), "foo/my.png", options)
|
|
|
|
assert_equal File.join(other_folder, 'foo/my.png'), image.file
|
|
|
|
assert_equal 0, image.size
|
|
|
|
FileUtils.rm_rf other_folder
|
|
|
|
end
|
|
|
|
|
2011-04-28 06:49:03 +00:00
|
|
|
end
|