File: test_ui.rb

package info (click to toggle)
ruby-openid 2.5.0debian-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,980 kB
  • ctags: 2,219
  • sloc: ruby: 16,737; xml: 219; sh: 24; makefile: 2
file content (93 lines) | stat: -rw-r--r-- 2,590 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require 'openid/extensions/ui'
require 'openid/message'
require 'openid/server'
require 'test/unit'

module OpenID
  module UITest
    class UIRequestTestCase < Test::Unit::TestCase

      def setup
        @req = UI::Request.new
      end

      def test_construct
        assert_nil @req.mode
        assert_nil @req.icon
        assert_nil @req.lang
        assert_equal 'ui', @req.ns_alias

        req2 = UI::Request.new("popup", true, "ja-JP")
        assert_equal "popup", req2.mode
        assert_equal true, req2.icon
        assert_equal "ja-JP", req2.lang
      end

      def test_add_mode
        @req.mode = "popup"
        assert_equal "popup", @req.mode
      end

      def test_add_icon
        @req.icon = true
        assert_equal true, @req.icon
      end

      def test_add_lang
        @req.lang = "ja-JP"
        assert_equal "ja-JP", @req.lang
      end

      def test_get_extension_args
        assert_equal({}, @req.get_extension_args)
        @req.mode = "popup"
        assert_equal({'mode' => 'popup'}, @req.get_extension_args)
        @req.icon = true
        assert_equal({'mode' => 'popup', 'icon' => true}, @req.get_extension_args)
        @req.lang = "ja-JP"
        assert_equal({'mode' => 'popup', 'icon' => true, 'lang' => 'ja-JP'}, @req.get_extension_args)
      end

      def test_parse_extension_args
        args = {'mode' => 'popup', 'icon' => true, 'lang' => 'ja-JP'}
        @req.parse_extension_args args
        assert_equal "popup", @req.mode
        assert_equal true, @req.icon
        assert_equal "ja-JP", @req.lang
      end

      def test_parse_extension_args_empty
        @req.parse_extension_args({})
        assert_nil @req.mode
        assert_nil @req.icon
        assert_nil @req.lang
      end

      def test_from_openid_request
        openid_req_msg = Message.from_openid_args(
          'mode' => 'checkid_setup',
          'ns' => OPENID2_NS,
          'ns.ui' => UI::NS_URI,
          'ui.mode' => 'popup',
          'ui.icon' => true,
          'ui.lang' => 'ja-JP'
        )
        oid_req = Server::OpenIDRequest.new
        oid_req.message = openid_req_msg
        req = UI::Request.from_openid_request oid_req
        assert_equal "popup", req.mode
        assert_equal true, req.icon
        assert_equal "ja-JP", req.lang
      end

      def test_from_openid_request_no_ui_params
        message = Message.new
        openid_req = Server::OpenIDRequest.new
        openid_req.message = message
        ui_req = UI::Request.from_openid_request openid_req
        assert ui_req.nil?
      end

    end
  end
end