require 'test/unit' require 'passiveldap' require 'tests/user.rb' # test attribute changing class Test_PassiveLDAP_Attributes < Test::Unit::TestCase # creates a new user 12345 in the directory # tests finding objects, creation of objects, mandatory_attribute insertions and such def setup a = TestUser.new(12345) a.save! end # deletes the user 12345 from the directory # tests finding objects, and the destroy method def teardown a = TestUser.new(12345) a.destroy end # tests adding a new attribute to a record def test_add_attribute a = TestUser.new(12345) a.mail = "test@mail.com" a.save! b = TestUser.new(12345) assert_equal("test@mail.com",b.mail) assert_raise(PassiveLDAP::AttributeAssignmentError) { b.mail = ["not@good.de"] } assert_raise(PassiveLDAP::AttributeAssignmentError) { b[:nonexistent] = "not@good.de" } end # tests deletion of an attribute def test_delete_attribute a = TestUser.new(12345) a.mail = "test@mail.com" a.save! b = TestUser.new(12345) assert_equal("test@mail.com",b.mail) b.mail = nil b.save! c = TestUser.new(12345) assert_nil(c.mail) end # tests adding multi_valued attributes def test_add_multi_attribute a = TestUser.new(12345) a.other_mailbox = ["test@mail.com", "othertest@mail.hu"] a.save! b = TestUser.new(12345) assert_equal(["test@mail.com", "othertest@mail.hu"].sort,b.other_mailbox.sort) assert_raise(PassiveLDAP::AttributeAssignmentError) { b.other_mailbox = "not@good.de" } end # tests adding values to a multi_valued attribute def test_add_value_to_multi a = TestUser.new(12345) a.other_mailbox = ["test@mail.com"] a.save! b = TestUser.new(12345) assert_equal(["test@mail.com"],b.other_mailbox) b.other_mailbox <<= "othertest@mail.hu" b.save! c = TestUser.new(12345) assert_equal(["test@mail.com", "othertest@mail.hu"].sort,c.other_mailbox.sort) end # test deletion of a value of a multi_valued attribute def test_delete_value_from_multi a = TestUser.new(12345) a.other_mailbox = ["test@mail.com", "othertest@mail.hu"] a.save! b = TestUser.new(12345) assert_equal(["test@mail.com", "othertest@mail.hu"].sort,b.other_mailbox.sort) b.other_mailbox = ["othertest@mail.hu"] b.save! c = TestUser.new(12345) assert_equal(["othertest@mail.hu"],c.other_mailbox) end end