Sha256: 532eb37f5537d70719fcdef0c5fdb543116b7e9865a9866e5819082a7e947d0c

Contents?: true

Size: 1.86 KB

Versions: 30

Compression:

Stored size: 1.86 KB

Contents

#!/usr/bin/ruby

$:.unshift File::dirname(__FILE__) + '/../../lib'

require 'test/unit'
require 'xmpp4r/rexmladdons'
require 'xmpp4r/roster/x/roster'
require 'xmpp4r/jid'
include Jabber

class Roster::XRosterTest < Test::Unit::TestCase
  def test_create
    r1 = Roster::XRoster.new
    assert_equal('x', r1.name)
    assert_equal('jabber:x:roster', r1.namespace)
    r2 = Roster::RosterX.new
    assert_equal('x', r2.name)
    assert_equal('http://jabber.org/protocol/rosterx', r2.namespace)
  end

  def test_import
    x1 = X.new
    x1.add_namespace('jabber:x:roster')
    x2 = X::import(x1)
    assert_equal(Roster::XRoster, x2.class)
    assert_equal('jabber:x:roster', x2.namespace)
  end

  def test_typed_add
    x = REXML::Element.new('x')
    x.add(REXML::Element.new('item'))
    r = Roster::XRoster.new.import(x)
    assert_kind_of(Roster::XRosterItem, r.first_element('item'))
    assert_kind_of(Roster::XRosterItem, r.typed_add(REXML::Element.new('item')))
  end

  def test_items
    j1 = Roster::XRosterItem.new
    assert_equal(JID.new(nil), j1.jid)
    assert_equal(nil, j1.iname)

    j2 = Roster::XRosterItem.new(JID.new('a@b/c'))
    assert_equal(JID.new('a@b/c'), j2.jid)
    assert_equal(nil, j2.iname)
    j3 = Roster::XRosterItem.new(JID.new('a@b/c'), 'Mr. Abc')
    assert_equal(JID.new('a@b/c'), j3.jid)
    assert_equal('Mr. Abc', j3.iname)
    assert_equal([], j3.groups)

    j3.groups = ['X', 'Y', 'Z']
    assert_equal(['X', 'Y', 'Z'], j3.groups)
  end

  def test_actions
    j = Roster::XRosterItem.new
    assert_equal(:add, j.action)

    j.action = :modify
    assert_equal(:modify, j.action)

    j.action = :delete
    assert_equal(:delete, j.action)

    j.action = :invalid
    assert_equal(:add, j.action)

    j.attributes['action'] = 'modify'
    assert_equal(:modify, j.action)

    j.attributes['action'] = 'invalid'
    assert_equal(:add, j.action)
  end
end

Version data entries

30 entries across 30 versions & 12 rubygems

Version Path
brontes3d-xmpp4r-0.4 test/roster/tc_xroster.rb
bryanl-xmpp4r-0.3.2 test/roster/tc_xroster.rb
edavey-xmpp4r-0.4.1 test/roster/tc_xroster.rb
edavey-xmpp4r-0.4.2 test/roster/tc_xroster.rb
edavey-xmpp4r-0.4 test/roster/tc_xroster.rb
heipei-xmpp4r-0.3.2 test/roster/tc_xroster.rb
ln-xmpp4r-0.5 test/roster/tc_xroster.rb
mojodna-xmpp4r-0.4.0.2 test/roster/tc_xroster.rb
mojodna-xmpp4r-0.4.0.3 test/roster/tc_xroster.rb
seanohalpin-xmpp4r-0.4.1 test/roster/tc_xroster.rb
xmpp4r-0.5.6 test/roster/tc_xroster.rb
xmpp4r-0.5.5 test/roster/tc_xroster.rb
mad-p-xmpp4r-0.6.3 test/roster/tc_xroster.rb
mad-p-xmpp4r-0.6.2 test/roster/tc_xroster.rb
mad-p-xmpp4r-0.6.1 test/roster/tc_xroster.rb
mad-p-xmpp4r-0.6.0 test/roster/tc_xroster.rb
cerberus-0.8.0 lib/vendor/xmpp4r/test/roster/tc_xroster.rb
cerberus-0.7.9 lib/vendor/xmpp4r/test/roster/tc_xroster.rb
edavis10-cerberus-0.7.8 lib/vendor/xmpp4r/test/roster/tc_xroster.rb
cerberus-0.7.8 lib/vendor/xmpp4r/test/roster/tc_xroster.rb