some
[appoyo.git] / vendor / plugins / facebooker / test / facebooker / data_test.rb
blob7798fd119ed2ef914c9c4ba80ce74a6675b0c38c
1 require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
3 class Facebooker::DataTest < Test::Unit::TestCase
4   def setup
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
8   end
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'))
13   end
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))
18   end
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
26   end
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'))
31   end
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))
36   end
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)
42   end
44   private
45   def example_set_cookie_xml
46     <<-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>
50     XML
51   end
53   def example_get_cookies_xml
54     <<-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">
58       <cookies>
59         <uid>508508326</uid>
60         <name>Foo</name>
61         <value>Bar</value>
62         <expires>0</expires>
63         <path>/tmp/</path>
64       </cookies>
65     </data_getCookie_response>
66     XML
67   end
69   def example_set_preference_xml
70     <<-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"/>
74     XML
75   end
77   def example_get_preference_xml
78     <<-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">
82       hello
83     </data_getUserPreference_response>
84     XML
85   end
86 end