first pass RT4 merge, RT#13852
[freeside.git] / rt / t / api / attribute-tests.t
1 use strict;
2 use warnings;
3 use RT;
4 use RT::Test nodata => 1, tests => 34;
5
6
7
8 my $runid = rand(200);
9
10 my $attribute = "squelch-$runid";
11
12 ok(require RT::Attributes);
13
14 my $user = RT::User->new(RT->SystemUser);
15 ok (UNIVERSAL::isa($user, 'RT::User'));
16 my ($id,$msg)  = $user->Create(Name => 'attrtest-'.$runid);
17 ok ($id, $msg);
18 ok($user->id, "Created a test user");
19
20 ok(1, $user->Attributes->BuildSelectQuery);
21 my $attr = $user->Attributes;
22 # XXX: Order by id as some tests depend on it
23 $attr->OrderByCols({ FIELD => 'id' });
24
25 ok(1, $attr->BuildSelectQuery);
26
27
28 ok (UNIVERSAL::isa($attr,'RT::Attributes'), 'got the attributes object');
29
30 ($id, $msg) =  $user->AddAttribute(Name => 'TestAttr', Content => 'The attribute has content'); 
31 ok ($id, $msg);
32 is ($attr->Count,1, " One attr after adding a first one");
33
34 my $first_attr = $user->FirstAttribute('TestAttr');
35 ok($first_attr, "got some sort of attribute");
36 isa_ok($first_attr, 'RT::Attribute');
37 is($first_attr->Content, 'The attribute has content', "got the right content back");
38
39 ($id, $msg) = $attr->DeleteEntry(Name => $runid);
40 ok(!$id, "Deleted non-existant entry  - $msg");
41 is ($attr->Count,1, "1 attr after deleting an empty attr");
42
43 my @names = $attr->Names;
44 is ("@names", "TestAttr");
45
46
47 ($id, $msg) = $user->AddAttribute(Name => $runid, Content => "First");
48 ok($id, $msg);
49
50 my $runid_attr = $user->FirstAttribute($runid);
51 ok($runid_attr, "got some sort of attribute");
52 isa_ok($runid_attr, 'RT::Attribute');
53 is($runid_attr->Content, 'First', "got the right content back");
54
55 is ($attr->Count,2, " Two attrs after adding an attribute named $runid");
56 ($id, $msg) = $user->AddAttribute(Name => $runid, Content => "Second");
57 ok($id, $msg);
58
59 $runid_attr = $user->FirstAttribute($runid);
60 ok($runid_attr, "got some sort of attribute");
61 isa_ok($runid_attr, 'RT::Attribute');
62 is($runid_attr->Content, 'First', "got the first content back still");
63
64 is ($attr->Count,3, " Three attrs after adding a secondvalue to $runid");
65 ($id, $msg) = $attr->DeleteEntry(Name => $runid, Content => "First");
66 ok($id, $msg);
67 is ($attr->Count,2);
68
69 #$attr->_DoSearch();
70 ($id, $msg) = $attr->DeleteEntry(Name => $runid, Content => "Second");
71 ok($id, $msg);
72 is ($attr->Count,1);
73
74 #$attr->_DoSearch();
75 ok(1, $attr->BuildSelectQuery);
76 ($id, $msg) = $attr->DeleteEntry(Name => "moose");
77 ok(!$id, "Deleted non-existant entry - $msg");
78 is ($attr->Count,1);
79
80 ok(1, $attr->BuildSelectQuery);
81 @names = $attr->Names;
82 is("@names", "TestAttr");
83