0
@@ -8,7 +8,7 @@ class BackendController; def rescue_action(e) raise e end; end
0
class BackendControllerTest < Test::Unit::TestCase
0
fixtures :users, :sections, :assigned_sections, :contents, :sites
0
@controller = BackendController.new
0
@request = ActionController::TestRequest.new
0
@@ -16,11 +16,70 @@ class BackendControllerTest < Test::Unit::TestCase
0
FileUtils.mkdir_p ASSET_PATH
0
FileUtils.rm_rf ASSET_PATH
0
+ # Movable Type Backend Api Tests
0
+ def test_movable_type_get_category_list
0
+ # test test_movable_type_get_category_list
0
+ args = [ 1, 'quentin', 'test' ]
0
+ result = invoke_layered :mt, :getCategoryList, *args
0
+ assert_equal 'Home', result.first['categoryName']
0
+ def test_movable_type_get_post_categories
0
+ # test test_movable_type_get_post_categories
0
+ args = [ 1, 'quentin', 'test' ]
0
+ result = invoke_layered :mt, :getPostCategories, *args
0
+ assert_equal %w(About Home), result.collect { |c| c['categoryName'] }
0
+ def test_movable_type_set_post_categories
0
+ # test test_movable_type_set_post_categories
0
+ # this needs some work!! FIXME FIXME FIXME
0
+ c1 = MovableTypeStructs::PostCategory.new(:categoryId => 1, :categoryName => 'Home', :isPrimary => false)
0
+ c2 = MovableTypeStructs::PostCategory.new(:categoryId => 2, :categoryName => 'About', :isPrimary => false)
0
+ c3 = MovableTypeStructs::PostCategory.new(:categoryId => 9, :categoryName => 'Links', :isPrimary => false)
0
+ args = [ 1, 'quentin', 'test', [ c1, c2, c3 ]]
0
+ result = invoke_layered :mt, :setPostCategories, *args
0
+ assert_equal true, result
0
+ # see if the categories have been set
0
+ args = [ 1, 'quentin', 'test' ]
0
+ result = invoke_layered :mt, :getPostCategories, *args
0
+ assert_equal ["1","2","9"], result.collect { |c| c['categoryId'] }.sort
0
+ # set the categories back to the default
0
+ args = [ 1, 'quentin', 'test', [c1,c2] ]
0
+ result = invoke_layered :mt, :setPostCategories, *args
0
+ assert_equal true, result
0
+ def test_movable_type_supported_methods
0
+ # test test_movable_type_supported_methods
0
+ result = invoke_layered :mt, :supportedMethods
0
+ assert_instance_of Array, result
0
+ def test_movable_type_supported_text_filters
0
+ # test test_movable_type_supported_text_filters
0
+ result = invoke_layered :mt, :supportedTextFilters
0
+ assert_instance_of Array, result
0
def test_meta_weblog_get_categories
0
args = [ 1, 'quentin', 'test' ]
0
@@ -84,7 +143,7 @@ class BackendControllerTest < Test::Unit::TestCase
0
result = invoke_layered :metaWeblog, :newPost, *args
0
new_post = Article.find(result)
0
assert_equal "Posted via Test", new_post.title
0
assert_equal article.body, new_post.body
0
assert_equal "<p>body</p>", new_post.body_html
0
@@ -92,9 +151,57 @@ class BackendControllerTest < Test::Unit::TestCase
0
+ def test_meta_weblog_new_post_min
0
+ # This is going to test weather a post is correctly submited or not without the published_at field!
0
+ # See http://www.xmlrpc.com/metaWeblogApi#theStruct or
0
+ # See http://www.sixapart.com/developers/xmlrpc/metaweblog_api/metaweblognewpost.html for more information
0
+ assert_difference Article, :count do
0
+ article.title = 'This is a title'
0
+ article.body = 'This is a post'
0
+ args = [ 1, 'quentin', 'test', MetaWeblogService.new(@controller).article_dto_from(article), 1 ]
0
+ result = invoke_layered :metaWeblog, :newPost, *args
0
+ new_post = Article.find(result)
0
+ assert_equal 'This is a post', new_post.body
0
+ assert_equal '<p>This is a post</p>', new_post.body_html
0
+ assert_equal 'This is a title', new_post.title
0
+ assert_equal :published, new_post.status
0
+ def test_meta_weblog_new_post_publish
0
+ # Test weather publish is set correctly on 1 and true to :published otherwise :pending
0
+ [{ :set => 1, :expect => :published },
0
+ { :set => 0, :expect => :pending },
0
+ { :set => true, :expect => :published},
0
+ { :set => false, :expect => :pending }].each do |c|
0
+ assert_difference Article, :count do
0
+ article.title = 'This is a title'
0
+ article.body = 'This is a post'
0
+ args = [ 1, 'quentin', 'test', MetaWeblogService.new(@controller).article_dto_from(article), c[:set] ]
0
+ result = invoke_layered :metaWeblog, :newPost, *args
0
+ new_post = Article.find(result)
0
+ assert_equal 'This is a post', new_post.body
0
+ assert_equal '<p>This is a post</p>', new_post.body_html
0
+ assert_equal 'This is a title', new_post.title
0
+ assert_equal c[:expect], new_post.status
0
def test_should_upload_file_via_meta_weblog_new_media_object
0
- media_object = new_media_object
0
+ media_object = new_media_object
0
args = [ 1, 'quentin', 'test', media_object ]
0
result = invoke_layered :metaWeblog, :newMediaObject, *args
0
@@ -102,14 +209,14 @@ class BackendControllerTest < Test::Unit::TestCase
0
assert_file_exists File.join(ASSET_PATH, now.year.to_s, now.month.to_s, now.day.to_s, media_object['name'])
0
def test_should_guess_content_type_for_gif
0
media_object = new_media_object 'type' => nil, :name => 'filename.gif'
0
assert_nil media_object['type']
0
args = [ 1, 'quentin', 'test', media_object ]
0
result = invoke_layered :metaWeblog, :newMediaObject, *args
0
new_asset = Asset.find :first, :order => 'created_at DESC'
0
assert_equal 'image/gif', new_asset.content_type
0
@@ -117,10 +224,10 @@ class BackendControllerTest < Test::Unit::TestCase
0
def test_should_guess_content_type_for_jpg
0
media_object = new_media_object 'type' => nil
0
assert_nil media_object['type']
0
args = [ 1, 'quentin', 'test', media_object ]
0
result = invoke_layered :metaWeblog, :newMediaObject, *args
0
new_asset = Asset.find :first, :order => 'created_at DESC'
0
assert_equal 'image/jpeg', new_asset.content_type
0
@@ -136,9 +243,9 @@ class BackendControllerTest < Test::Unit::TestCase
0
# This will be a little more useful with the upstream changes in [1093]
0
assert_raise(XMLRPC::FaultException) { invoke_layered :metaWeblog, :getRecentPosts, *args }
0
def new_media_object(options = {})
0
MetaWeblogStructs::MediaObject.new(options.reverse_merge!(
0
'name' => Digest::SHA1.hexdigest("upload-test--#{Time.now}--") + ".jpg",
0
@@ -146,5 +253,5 @@ class BackendControllerTest < Test::Unit::TestCase
0
'bits' => Base64.encode64(File.open(File.expand_path(RAILS_ROOT) + '/public/images/mephisto/shadow.png', 'rb') { |f| f.read })
Comments
No one has commented yet.