5 use RT::Test tests => 67;
11 my $CLASS = 'ArticleTest-'.$$;
13 my $user = RT::CurrentUser->new('root');
15 my $class = RT::Class->new($user);
18 my ($id, $msg) = $class->Create(Name =>$CLASS);
23 my $article = RT::Article->new($user);
24 ok (UNIVERSAL::isa($article, 'RT::Article'));
25 ok (UNIVERSAL::isa($article, 'RT::Record'));
26 ok (UNIVERSAL::isa($article, 'RT::Record'));
27 ok (UNIVERSAL::isa($article, 'DBIx::SearchBuilder::Record') , "It's a searchbuilder record!");
30 ($id, $msg) = $article->Create( Class => $CLASS, Summary => $CLASS);
33 is ($article->Summary, $CLASS, "The summary is set correct");
34 my $at = RT::Article->new($RT::SystemUser);
37 is ($at->Summary, $article->Summary);
42 my $a1 = RT::Article->new($RT::SystemUser);
43 ($id, $msg) = $a1->Create(Class => $class->id, Name => 'ValidateNameTest'.$$);
48 my $a2 = RT::Article->new($RT::SystemUser);
49 ($id, $msg) = $a2->Create(Class => $class->id, Name => 'ValidateNameTest'.$$);
52 my $a3 = RT::Article->new($RT::SystemUser);
53 ($id, $msg) = $a3->Create(Class => $class->id, Name => 'ValidateNameTest2'.$$);
55 ($id, $msg) =$a3->SetName('ValidateNameTest'.$$);
59 ($id, $msg) =$a3->SetName('ValidateNametest2'.$$);
67 my $newart = RT::Article->new($RT::SystemUser);
68 $newart->Create(Name => 'DeleteTest'.$$, Class => '1');
71 ok($id, "New article has an id");
74 $article = RT::Article->new($RT::SystemUser);
76 ok ($article->Id, "Found the article");
78 ($val, $msg) = $article->Delete();
79 ok ($val, "Article Deleted: $msg");
81 $a2 = RT::Article->new($RT::SystemUser);
83 ok (!$a2->Id, "Did not find the article");
86 #$RT::Handle->SimpleQuery("DELETE FROM Links");
88 my $article_a = RT::Article->new($RT::SystemUser);
89 ($id, $msg) = $article_a->Create( Class => $CLASS, Summary => "ArticleTestlink1".$$);
92 my $article_b = RT::Article->new($RT::SystemUser);
93 ($id, $msg) = $article_b->Create( Class => $CLASS, Summary => "ArticleTestlink2".$$);
96 # Create a link between two articles
97 ($id, $msg) = $article_a->AddLink( Type => 'RefersTo', Target => $article_b->URI);
100 # Make sure that Article Bs "ReferredToBy" links object refers to to this article
101 my $refers_to_b = $article_b->ReferredToBy;
102 is($refers_to_b->Count, 1, "Found one thing referring to b");
103 my $first = $refers_to_b->First;
104 ok ($first->isa('RT::Link'), "IT's an RT link - ref ".ref($first) );
105 is($first->TargetObj->Id, $article_b->Id, "Its target is B");
107 ok($refers_to_b->First->BaseObj->isa('RT::Article'), "Yep. its an article");
110 # Make sure that Article A's "RefersTo" links object refers to this article"
111 my $referred_To_by_a = $article_a->RefersTo;
112 is($referred_To_by_a->Count, 1, "Found one thing referring to b ".$referred_To_by_a->Count. "-".$referred_To_by_a->First->id . " - ".$referred_To_by_a->Last->id);
113 $first = $referred_To_by_a->First;
114 ok ($first->isa('RT::Link'), "IT's an RT link - ref ".ref($first) );
115 is ($first->TargetObj->Id, $article_b->Id, "Its target is B - " . $first->TargetObj->Id);
116 is ($first->BaseObj->Id, $article_a->Id, "Its base is A");
118 ok($referred_To_by_a->First->BaseObj->isa('RT::Article'), "Yep. its an article");
121 ($id, $msg) = $article_a->DeleteLink(Type => 'RefersTo', Target => $article_b->URI);
125 # Create an Article A RefersTo Ticket 1 from the Articles side
129 my $tick = RT::Ticket->new($RT::SystemUser);
130 $tick->Create(Subject => "Article link test ", Queue => 'General');
131 $tick->Load($tick->Id);
132 ok ($tick->Id, "Found ticket ".$tick->id);
133 ($id, $msg) = $article_a->AddLink(Type => 'RefersTo', Target => $tick->URI);
136 # Find all tickets whhich refer to Article A
141 my $tix = RT::Tickets->new($RT::SystemUser);
142 ok ($tix, "Got an RT::Tickets object");
143 ok ($tix->LimitReferredToBy($article_a->URI));
144 is ($tix->Count, 1, "Found one ticket linked to that article");
145 is ($tix->First->Id, $tick->id, "It's even the right one");
149 # Find all articles which refer to Ticket 1
152 my $articles = RT::Articles->new($RT::SystemUser);
153 ok($articles->isa('RT::Articles'), "Created an article collection");
154 ok($articles->isa('RT::SearchBuilder'), "Created an article collection");
155 ok($articles->isa('DBIx::SearchBuilder'), "Created an article collection");
156 ok($tick->URI, "The ticket does still have a URI");
157 $articles->LimitRefersTo($tick->URI);
159 is($articles->Count(), 1);
160 is ($articles->First->Id, $article_a->Id);
161 is ($articles->First->URI, $article_a->URI);
165 # Find all things which refer to ticket 1 using the RT API.
167 my $tix2 = RT::Links->new($RT::SystemUser);
168 ok ($tix2->isa('RT::Links'));
169 ok($tix2->LimitRefersTo($tick->URI));
170 is ($tix2->Count, 1);
171 is ($tix2->First->BaseObj->URI ,$article_a->URI);
175 # Delete the link from the RT side.
176 my $t2 = RT::Ticket->new($RT::SystemUser);
177 $t2->Load($tick->Id);
178 ($id, $msg)= $t2->DeleteLink( Base => $article_a->URI, Type => 'RefersTo');
179 ok ($id, $msg . " - $id - $msg");
181 # it is actually deleted
182 my $tix3 = RT::Links->new($RT::SystemUser);
183 $tix3->LimitReferredToBy($tick->URI);
184 is ($tix3->Count, 0);
186 # Recreate the link from teh RT site
187 ($id, $msg) = $t2->AddLink( Base => $article_a->URI, Type => 'RefersTo');
190 # Find all tickets whhich refer to Article A
192 # Find all articles which refer to Ticket 1
197 my $art = RT::Article->new($RT::SystemUser);
198 ($id, $msg) = $art->Create (Class => $CLASS);
202 ok($art->__Value('URI') eq $art->URI, "The uri in the db is set correctly");
207 $art = RT::Article->new($RT::SystemUser);
208 ($id, $msg) = $art->Create (Class => $CLASS);
212 ok($art->__Value('URI') eq $art->URIObj->URI, "The uri in the db is set correctly");
215 my $art_id = $art->id;
216 $art = RT::Article->new($RT::SystemUser);
218 is ($art->Id, $art_id, "Loaded article 1");
219 my $s =$art->Summary;
220 ($val, $msg) = $art->SetSummary("testFoo");
222 ok ($art->Summary eq 'testFoo', "The Summary was set to foo");
223 my $t = $art->Transactions();
224 my $trans = $t->Last;
225 ok ($trans->Type eq 'Set', "It's a Set transaction");
226 ok ($trans->Field eq 'Summary', "it is about setting the Summary");
227 is ($trans->NewValue , 'testFoo', "The new content is 'foo'");
228 is ($trans->OldValue,$s, "the old value was preserved");