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