[Rt-commit] r10730 - rt/branches/3.7-RTIR-RELENG/t/ticket
ruz at bestpractical.com
ruz at bestpractical.com
Tue Feb 5 16:15:20 EST 2008
Author: ruz
Date: Tue Feb 5 16:15:11 2008
New Revision: 10730
Added:
rt/branches/3.7-RTIR-RELENG/t/ticket/search_by_links.t
Log:
* add t/ticket/search_by_links.t
Added: rt/branches/3.7-RTIR-RELENG/t/ticket/search_by_links.t
==============================================================================
--- (empty file)
+++ rt/branches/3.7-RTIR-RELENG/t/ticket/search_by_links.t Tue Feb 5 16:15:11 2008
@@ -0,0 +1,90 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+use Test::More tests => 37;
+use RT::Test;
+use RT::Ticket;
+
+my $q = RT::Test->load_or_create_queue( Name => 'Regression' );
+ok $q && $q->id, 'loaded or created queue';
+
+my ($total, @data, @tickets, %test) = (0, ());
+
+sub add_tix_from_data {
+ my @res = ();
+ while (@data) {
+ my $t = RT::Ticket->new($RT::SystemUser);
+ my %args = %{ shift(@data) };
+ $args{$_} = $res[ $args{$_} ]->id foreach grep $args{$_}, keys %RT::Ticket::LINKTYPEMAP;
+ my ( $id, undef $msg ) = $t->Create(
+ Queue => $q->id,
+ %args,
+ );
+ ok( $id, "ticket created" ) or diag("error: $msg");
+ push @res, $t;
+ $total++;
+ }
+ return @res;
+}
+
+sub run_tests {
+ my $query_prefix = join ' OR ', map 'id = '. $_->id, @tickets;
+ foreach my $key ( sort keys %test ) {
+ my $tix = RT::Tickets->new($RT::SystemUser);
+ $tix->FromSQL( "( $query_prefix ) AND ( $key )" );
+
+ my $error = 0;
+
+ my $count = 0;
+ $count++ foreach grep $_, values %{ $test{$key} };
+ is($tix->Count, $count, "found correct number of ticket(s) by '$key'") or $error = 1;
+
+ my $good_tickets = 1;
+ while ( my $ticket = $tix->Next ) {
+ next if $test{$key}->{ $ticket->Subject };
+ diag $ticket->Subject ." ticket has been found when it's not expected";
+ $good_tickets = 0;
+ }
+ ok( $good_tickets, "all tickets are good with '$key'" ) or $error = 1;
+
+ diag "Wrong SQL query for '$key':". $tix->BuildSelectQuery if $error;
+ }
+}
+
+ at data = (
+ { Subject => '-', },
+ { Subject => 'p', },
+ { Subject => 'c', MemberOf => -1 },
+);
+ at tickets = add_tix_from_data();
+%test = (
+ 'Linked IS NOT NULL' => { '-' => 0, c => 1, p => 1 },
+ 'Linked IS NULL' => { '-' => 1, c => 0, p => 0 },
+ 'LinkedTo IS NOT NULL' => { '-' => 0, c => 1, p => 0 },
+ 'LinkedTo IS NULL' => { '-' => 1, c => 0, p => 1 },
+ 'LinkedFrom IS NOT NULL' => { '-' => 0, c => 0, p => 1 },
+ 'LinkedFrom IS NULL' => { '-' => 1, c => 1, p => 0 },
+
+ 'HasMember IS NOT NULL' => { '-' => 0, c => 0, p => 1 },
+ 'HasMember IS NULL' => { '-' => 1, c => 1, p => 0 },
+ 'MemberOf IS NOT NULL' => { '-' => 0, c => 1, p => 0 },
+ 'MemberOf IS NULL' => { '-' => 1, c => 0, p => 1 },
+
+ 'RefersTo IS NOT NULL' => { '-' => 0, c => 0, p => 0 },
+ 'RefersTo IS NULL' => { '-' => 1, c => 1, p => 1 },
+
+ 'Linked = '. $tickets[0]->id => { '-' => 0, c => 0, p => 0 },
+ 'Linked != '. $tickets[0]->id => { '-' => 1, c => 1, p => 1 },
+
+ 'MemberOf = '. $tickets[1]->id => { '-' => 0, c => 1, p => 0 },
+ 'MemberOf != '. $tickets[1]->id => { '-' => 1, c => 0, p => 1 },
+);
+{
+ my $tix = RT::Tickets->new($RT::SystemUser);
+ $tix->FromSQL("Queue = '". $q->id ."'");
+ is($tix->Count, $total, "found $total tickets");
+}
+run_tests();
+
More information about the Rt-commit
mailing list