1 require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
3 class Facebooker::DataTest < Test::Unit::TestCase
5 @session = Facebooker::Session.create('apikey', 'secretkey')
6 #make sure we use net::http since that's what the tests expect
7 Facebooker.use_curl=false
10 def test_can_ask_facebook_to_set_a_cookies
11 expect_http_posts_with_responses(example_set_cookie_xml)
12 assert(@session.data.set_cookie(12345, 'name', 'value'))
15 def test_can_ask_facebook_to_get_cookies
16 expect_http_posts_with_responses(example_get_cookies_xml)
17 assert(@session.data.get_cookies(12345))
20 def test_can_get_cookies_for_user
21 mock_http = establish_session
22 mock_http.should_receive(:post_form).and_return(example_get_cookies_xml).once.ordered(:posts)
23 cookies = @session.data.get_cookies(508508326)
24 assert_equal 'Foo', cookies.first.name
25 assert_equal 'Bar', cookies.first.value
28 def test_can_ask_facebook_to_set_a_preference
29 expect_http_posts_with_responses(example_set_preference_xml)
30 assert(@session.data.set_preference(0, 'hello'))
33 def test_can_ask_facebook_to_get_preference
34 expect_http_posts_with_responses(example_get_preference_xml)
35 assert(@session.data.get_preference(0))
38 def test_can_get_preference
39 mock_http = establish_session
40 mock_http.should_receive(:post_form).and_return(example_get_preference_xml).once.ordered(:posts)
41 assert_equal 'hello', @session.data.get_preference(0)
45 def example_set_cookie_xml
47 <?xml version="1.0" encoding="UTF-8"?>
48 <data_setCookie_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
49 xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</data_setCookie_response>
53 def example_get_cookies_xml
55 <?xml version="1.0" encoding="UTF-8"?>
56 <data_getCookie_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
57 xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
65 </data_getCookie_response>
69 def example_set_preference_xml
71 <?xml version="1.0" encoding="UTF-8"?>
72 <data_setUserPreference_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
73 xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd"/>
77 def example_get_preference_xml
79 <?xml version="1.0" encoding="UTF-8"?>
80 <data_getUserPreference_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
81 xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
83 </data_getUserPreference_response>