require File.dirname(__FILE__) + '/test_helper.rb' require 'rubygems' require 'flexmock/test_unit' class UserTest < Test::Unit::TestCase def setup @session = Facebooker::Session.create('apikey', 'secretkey') @user = Facebooker::User.new(1234, @session) @other_user = Facebooker::User.new(4321, @session) @user.friends = [@other_user] end def test_can_ask_user_if_he_or_she_is_friends_with_another_user assert(@user.friends_with?(@other_user)) end def test_can_ask_user_if_he_or_she_is_friends_with_another_user_by_user_id assert(@user.friends_with?(@other_user.id)) end def test_can_create_from_current_session Facebooker::Session.expects(:current).returns("current") user=Facebooker::User.new(1) assert_equal("current",user.session) end def test_can_set_mobile_fbml @user.expects(:set_profile_fbml).with(nil,"test",nil) @user.mobile_fbml="test" end def test_can_set_profile_action @user.expects(:set_profile_fbml).with(nil,nil,"test") @user.profile_action="test" end def test_can_set_profile_fbml @user.expects(:set_profile_fbml).with("test",nil,nil) @user.profile_fbml="test" end def test_can_call_set_profile_fbml @session.expects(:post).with('facebook.profile.setFBML', :uid=>1234,:profile=>"profile",:profile_action=>"action",:mobile_profile=>"mobile") @user.set_profile_fbml("profile","mobile","action") end def test_can_get_profile_photos @user.expects(:profile_photos) @user.profile_photos end def test_can_set_cookie @user.expects(:set_cookie).with('name', 'value') @user.set_cookie('name', 'value') end def test_can_get_cookies @user.expects(:get_cookies).with('name') @user.get_cookies('name') end def test_get_profile_photos @user = Facebooker::User.new(548871286, @session) expect_http_posts_with_responses(example_profile_photos_get_xml) photos = @user.profile_photos assert_equal "2357384227378429949", photos.first.aid end def test_can_send_email @user.expects(:send_email).with("subject", "body text") @user.send_email("subject", "body text") @user.expects(:send_email).with("subject", nil, "body fbml") @user.send_email("subject", nil, "body fbml") end def test_can_set_status_with_string @session.expects(:post).with('facebook.users.setStatus', :status=>"my status",:status_includes_verb=>1) @user.status="my status" end def test_get_events @user = Facebooker::User.new(9507801, @session) expect_http_posts_with_responses(example_events_get_xml) events = @user.events assert_equal "29511517904", events.first.eid end def test_can_get_events @user.expects(:events) @user.events end def test_to_s assert_equal("1234",@user.to_s) end private def example_profile_photos_get_xml " 34585991612804 2357384227378429949 1240077 http://ip002.facebook.com/v11/135/18/8055/s1240077_30043524_2020.jpg http://ip002.facebook.com/v11/135/18/8055/n1240077_30043524_2020.jpg http://ip002.facebook.com/v11/135/18/8055/t1240077_30043524_2020.jpg http://www.facebook.com/photo.php?pid=30043524&id=8055 From The Deathmatch (Trailer) (1999) 1132553361 34585991612805 2357384227378429949 1240077 http://ip002.facebook.com/v11/135/18/8055/s1240077_30043525_2184.jpg http://ip002.facebook.com/v11/135/18/8055/n1240077_30043525_2184.jpg http://ip002.facebook.com/v11/135/18/8055/t1240077_30043525_2184.jpg http://www.facebook.com/photo.php?pid=30043525&id=8055 Mexico City, back cover of the CYHS Student Underground 1999. 1132553362 " end def example_events_get_xml " 29511517904 PUMA SALE 0 http://profile.ak.facebook.com/object3/370/66/s29511517904_6952.jpg http://profile.ak.facebook.com/object3/370/66/n29511517904_6952.jpg http://profile.ak.facebook.com/object3/370/66/t29511517904_6952.jpg PUMA PUMA SALE Education Study Group 1212166800 1212364800 1234261165 1209768148 PUMA LOT 5 LYBERTY WAY Westford Massachusetts United States 42.5792 -71.4383 " end end