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-12-10 05:55:16 +00:00
|
|
|
|
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
|
|
|
end
|
|
|
|
|
2011-12-10 05:55:16 +00:00
|
|
|
def teardown
|
|
|
|
clean_up_sprites
|
|
|
|
end
|
|
|
|
|
2011-08-12 19:12:31 +00:00
|
|
|
SPRITE_FILENAME = 'selectors/ten-by-ten.png'
|
2011-04-29 03:09:43 +00:00
|
|
|
|
2011-08-12 19:12:31 +00:00
|
|
|
def sprite_path
|
|
|
|
File.join(@images_tmp_path, SPRITE_FILENAME)
|
|
|
|
end
|
2011-04-28 06:49:03 +00:00
|
|
|
|
2011-08-12 19:12:31 +00:00
|
|
|
def sprite_name
|
|
|
|
File.basename(SPRITE_FILENAME, '.png')
|
2011-04-28 06:49:03 +00:00
|
|
|
end
|
|
|
|
|
2011-08-12 19:12:31 +00:00
|
|
|
def digest
|
|
|
|
Digest::MD5.file(sprite_path).hexdigest
|
|
|
|
end
|
2011-04-28 06:49:03 +00:00
|
|
|
|
2011-08-12 19:12:31 +00:00
|
|
|
def test_map(options ={})
|
|
|
|
options = {'cleanup' => Sass::Script::Bool.new(true), 'layout' => Sass::Script::String.new('vertical')}.merge(options)
|
|
|
|
map = sprite_map_test(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_image(options ={})
|
|
|
|
test_map(options).images.first
|
|
|
|
end
|
2011-04-28 06:49:03 +00:00
|
|
|
|
|
|
|
test 'initialize' do
|
2011-08-12 19:12:31 +00:00
|
|
|
image = test_image
|
2011-04-28 06:49:03 +00:00
|
|
|
assert_equal sprite_name, image.name
|
|
|
|
assert_equal sprite_path, image.file
|
2011-08-12 19:12:31 +00:00
|
|
|
assert_equal SPRITE_FILENAME, image.relative_file
|
2011-04-28 06:49:03 +00:00
|
|
|
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
|
2011-08-12 19:12:31 +00:00
|
|
|
assert_equal 'ten-by-ten_hover', test_image.hover.name
|
2011-04-28 06:49:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'no parent' do
|
2011-08-12 19:12:31 +00:00
|
|
|
assert_nil test_image.parent
|
2011-04-28 06:49:03 +00:00
|
|
|
end
|
|
|
|
|
2011-12-10 05:55:16 +00:00
|
|
|
test 'image type is "global" should raise exception' do
|
|
|
|
assert_raise ::Compass::SpriteException do
|
|
|
|
image = test_image "selectors_ten_by_ten_repeat" => Sass::Script::String.new('global')
|
|
|
|
image.repeat
|
|
|
|
end
|
2011-04-28 06:49:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'image type is "no-repeat"' do
|
2011-12-10 05:55:16 +00:00
|
|
|
img = test_image
|
|
|
|
assert_equal 'no-repeat', img.repeat
|
|
|
|
assert img.no_repeat?
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'image repeat-x' do
|
|
|
|
img = test_image "selectors_ten_by_ten_repeat" => Sass::Script::String.new('repeat-x')
|
|
|
|
assert img.repeat_x?
|
2011-04-28 06:49:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'image position' do
|
2011-09-17 04:45:35 +00:00
|
|
|
image = test_image "selectors_ten_by_ten_position" => Sass::Script::Number.new(100, ["px"])
|
2011-08-12 19:12:31 +00:00
|
|
|
assert_equal 100, image.position.value
|
2011-04-28 06:49:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'image spacing' do
|
|
|
|
@spacing = 10
|
2011-08-12 19:12:31 +00:00
|
|
|
image = test_image "spacing" => Sass::Script::Number.new(100, ["px"])
|
|
|
|
assert_equal 100, image.spacing
|
2011-04-28 06:49:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'offset' do
|
2011-09-17 04:45:35 +00:00
|
|
|
image = test_image "selectors_ten_by_ten_position" => Sass::Script::Number.new(100, ["px"])
|
2011-08-12 19:12:31 +00:00
|
|
|
assert_equal 100, image.offset
|
2011-04-28 06:49:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'neither, uses 0' do
|
2011-08-12 19:12:31 +00:00
|
|
|
img = test_image
|
2011-04-28 06:49:03 +00:00
|
|
|
img.position.stubs(:unitless?).returns(false)
|
|
|
|
assert_equal 0, img.offset
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|