diff options
author | ivan <ivan> | 2008-03-02 04:06:06 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-03-02 04:06:06 +0000 |
commit | 9c68254528b6f2c7d8c1921b452fa56064783782 (patch) | |
tree | 09623ba39355e74f1cff2f3c35b7347bd309f306 /rt/lib/t | |
parent | ef20b2b6b1feb47ad02b5ff7525f1a0fd11d0fa4 (diff) |
import rt 3.4.6
Diffstat (limited to 'rt/lib/t')
-rw-r--r-- | rt/lib/t/regression/01ticket_link_searching.t | 96 | ||||
-rw-r--r-- | rt/lib/t/regression/02basic_web.t | 27 | ||||
-rw-r--r-- | rt/lib/t/regression/03web_compiliation_errors.t | 14 | ||||
-rw-r--r-- | rt/lib/t/regression/04send_email.t | 130 | ||||
-rw-r--r-- | rt/lib/t/regression/06-mime_decoding.t | 13 | ||||
-rw-r--r-- | rt/lib/t/regression/06mailgateway.t | 76 | ||||
-rw-r--r-- | rt/lib/t/regression/07acl.t | 96 | ||||
-rw-r--r-- | rt/lib/t/regression/07rights.t | 2 | ||||
-rw-r--r-- | rt/lib/t/regression/08web_cf_access.t | 15 | ||||
-rw-r--r-- | rt/lib/t/regression/12-search.t | 59 | ||||
-rw-r--r-- | rt/lib/t/regression/13-attribute-tests.t | 24 | ||||
-rw-r--r-- | rt/lib/t/regression/14linking.t | 112 | ||||
-rw-r--r-- | rt/lib/t/regression/21query-builder.t | 74 | ||||
-rw-r--r-- | rt/lib/t/regression/22search_tix_by_txn.t | 6 | ||||
-rw-r--r-- | rt/lib/t/regression/22search_tix_by_watcher.t | 192 | ||||
-rw-r--r-- | rt/lib/t/regression/23-web_attachments.t | 10 |
16 files changed, 323 insertions, 623 deletions
diff --git a/rt/lib/t/regression/01ticket_link_searching.t b/rt/lib/t/regression/01ticket_link_searching.t index a402c7376..6d10221c1 100644 --- a/rt/lib/t/regression/01ticket_link_searching.t +++ b/rt/lib/t/regression/01ticket_link_searching.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::More tests => 30; +use Test::More tests => 25; use strict; use RT; @@ -17,46 +17,54 @@ my $queue = new RT::Queue($CurrentUser); $queue->Load('General') || Abort(loc("Queue could not be loaded.")); my $child_ticket = new RT::Ticket( $CurrentUser ); -my ($childid) = $child_ticket->Create( - Subject => 'test child', - Queue => $queue->Id, -); -ok($childid, "We created a child ticket"); + +my ( $childid ) = $child_ticket->Create + ( Subject => 'test child', + Queue => $queue->Id); + +ok($childid != 0); my $parent_ticket = new RT::Ticket( $CurrentUser ); -my ($parentid) = $parent_ticket->Create( - Subject => 'test parent', - Children => [ $childid ], - Queue => $queue->Id, -); -ok($parentid, "We created a parent ticket"); +my ( $parentid ) = $parent_ticket->Create + ( Subject => 'test parent', + Children => [$childid], + Queue => $queue->Id); + +ok($parentid != 0, "We created a parent ticket"); my $Collection = RT::Tickets->new($CurrentUser); -$Collection->LimitMemberOf( $parentid ); +$Collection->LimitMemberOf ($parentid); + +ok ($Collection->First); +is ($Collection->First->id, $childid, "We found the collection of all children of $parentid with Limit"); is($Collection->Count,1, "We found only one result"); -ok($Collection->First); -is($Collection->First->id, $childid, "We found the collection of all children of $parentid with Limit"); $Collection = RT::Tickets->new($CurrentUser); -$Collection->FromSQL("MemberOf = $parentid"); -is($Collection->Count, 1, "We found only one result"); -ok($Collection->First); -is($Collection->First->id, $childid, "We found the collection of all children of $parentid with TicketSQL"); +$Collection->FromSQL( "MemberOf = $parentid"); +is ($Collection->First->id, $childid, "We found the collection of all children of $parentid with TicketSQL"); +is($Collection->Count,1, "We found only one result"); + + + $Collection = RT::Tickets->new($CurrentUser); $Collection->LimitHasMember ($childid); + +ok ($Collection->First); +is ($Collection->First->id, $parentid, "We found the collection of all parents of $childid with Limit"); is($Collection->Count,1, "We found only one result"); -ok($Collection->First); -is($Collection->First->id, $parentid, "We found the collection of all parents of $childid with Limit"); + $Collection = RT::Tickets->new($CurrentUser); $Collection->FromSQL("HasMember = $childid"); + +ok ($Collection->First); +is ($Collection->First->id, $parentid, "We found the collection of all parents of $childid with TicketSQL"); is($Collection->Count,1, "We found only one result"); -ok($Collection->First); -is($Collection->First->id, $parentid, "We found the collection of all parents of $childid with TicketSQL"); + # Now we find a collection of all the tickets which have no members. they should have no children. @@ -67,10 +75,12 @@ my %has; while (my $t = $Collection->Next) { ++$has{$t->id}; } -ok( $has{$childid}, "The collection has our child - $childid"); +ok ($has{$childid} , "The collection has our child - $childid"); ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid"); + + # Now we find a collection of all the tickets which are not members of anything. they should have no parents. $Collection = RT::Tickets->new($CurrentUser); $Collection->LimitMemberOf(''); @@ -92,27 +102,28 @@ ok( !$has{$childid}, "The collection doesn't have our child - $childid"); $Collection = RT::Tickets->new($CurrentUser); $Collection->FromSQL ("HasMember IS NULL"); # must contain parent; must not contain child -%has = (); + %has = (); while (my $t = $Collection->Next) { ++$has{$t->id}; } -ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid"); +ok (!$has{$parentid} , "The collection doesn't have our parent - $parentid"); ok( $has{$childid}, "The collection has our child - $childid"); # Now we find a collection of all the tickets which have no members. they should have no children. # Alternate syntax $Collection = RT::Tickets->new($CurrentUser); -$Collection->FromSQL("HasMember = ''"); +$Collection->FromSQL ("HasMember = ''"); # must contain parent; must not contain child -%has = (); + %has = (); while (my $t = $Collection->Next) { ++$has{$t->id}; } -ok( !$has{$parentid}, "The collection doesn't have our parent - $parentid"); +ok (!$has{$parentid} , "The collection doesn't have our parent - $parentid"); ok( $has{$childid}, "The collection has our child - $childid"); + # Now we find a collection of all the tickets which are not members of anything. they should have no parents. $Collection = RT::Tickets->new($CurrentUser); $Collection->FromSQL("MemberOf IS NULL"); @@ -121,8 +132,8 @@ $Collection->FromSQL("MemberOf IS NULL"); while (my $t = $Collection->Next) { ++$has{$t->id}; } -ok( $has{$parentid}, "The collection has our parent - $parentid"); -ok( !$has{$childid}, "The collection doesn't have our child - $childid"); +ok ($has{$parentid} , "The collection has our parent - $parentid"); +ok(!$has{$childid}, "The collection doesn't have our child - $childid"); # Now we find a collection of all the tickets which are not members of anything. they should have no parents. @@ -133,27 +144,12 @@ $Collection->FromSQL("MemberOf = ''"); while (my $t = $Collection->Next) { ++$has{$t->id}; } -ok( $has{$parentid}, "The collection has our parent - $parentid"); -ok( !$has{$childid}, "The collection doesn't have our child - $childid"); +ok ($has{$parentid} , "The collection has our parent - $parentid"); +ok(!$has{$childid}, "The collection doesn't have our child - $childid"); -# Now we find a collection of all the tickets which are not members of the parent ticket -$Collection = RT::Tickets->new($CurrentUser); -$Collection->FromSQL("MemberOf != $parentid"); -%has = (); -while (my $t = $Collection->Next) { - ++$has{$t->id}; -} -ok( $has{$parentid}, "The collection has our parent - $parentid"); -ok( !$has{$childid}, "The collection doesn't have our child - $childid"); -$Collection = RT::Tickets->new($CurrentUser); -$Collection->LimitMemberOf($parentid, OPERATOR => '!='); -%has = (); -while (my $t = $Collection->Next) { - ++$has{$t->id}; -} -ok( $has{$parentid}, "The collection has our parent - $parentid"); -ok( !$has{$childid}, "The collection doesn't have our child - $childid"); 1; + + diff --git a/rt/lib/t/regression/02basic_web.t b/rt/lib/t/regression/02basic_web.t index 3b8619b66..d3376d011 100644 --- a/rt/lib/t/regression/02basic_web.t +++ b/rt/lib/t/regression/02basic_web.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use Test::More tests => 19; +use Test::More tests => 17; use WWW::Mechanize; use HTTP::Request::Common; use HTTP::Cookies; @@ -16,10 +16,10 @@ my $agent = WWW::Mechanize->new(); $agent->cookie_jar($cookie_jar); use RT; -RT::LoadConfig(); +RT::LoadConfig; + # get the top page my $url = $RT::WebURL; -diag $url; $agent->get($url); is ($agent->{'status'}, 200, "Loaded a page"); @@ -44,20 +44,17 @@ ok( $agent->{'content'} =~ /Logout/i, "Found a logout link"); $agent->get($url."Ticket/Create.html?Queue=1"); is ($agent->{'status'}, 200, "Loaded Create.html"); -$agent->form_number(3); +$agent->form(3); # Start with a string containing characters in latin1 my $string = "I18N Web Testing æøå"; Encode::from_to($string, 'iso-8859-1', 'utf8'); $agent->field('Subject' => "Ticket with utf8 body"); $agent->field('Content' => $string); ok($agent->submit(), "Created new ticket with $string as Content"); -like( $agent->{'content'}, qr{$string} , "Found the content"); -ok($agent->{redirected_uri}, "Did redirection"); - - +ok( $agent->{'content'} =~ qr{$string} , "Found the content"); $agent->get($url."Ticket/Create.html?Queue=1"); is ($agent->{'status'}, 200, "Loaded Create.html"); -$agent->form_number(3); +$agent->form(3); # Start with a string containing characters in latin1 my $string = "I18N Web Testing æøå"; Encode::from_to($string, 'iso-8859-1', 'utf8'); @@ -65,15 +62,9 @@ $agent->field('Subject' => $string); $agent->field('Content' => "Ticket with utf8 subject"); ok($agent->submit(), "Created new ticket with $string as Subject"); -like( $agent->{'content'}, qr{$string} , "Found the content"); +ok( $agent->{'content'} =~ qr{$string} , "Found the content"); -# Update time worked in hours -$agent->follow_link( text_regex => qr/Basics/ ); -$agent->submit_form( form_number => 3, - fields => { TimeWorked => 5, 'TimeWorked-TimeUnits' => "hours" } -); -like ($agent->{'content'}, qr/to '300'/, "5 hours is 300 minutes"); # }}} @@ -91,14 +82,14 @@ ok($agent->form_name('BuildQuery')); $agent->field("AttachmentField", "Subject"); $agent->field("AttachmentOp", "LIKE"); $agent->field("ValueOfAttachment", "aaa"); -$agent->submit("AddClause"); +$agent->submit(); # set the next value ok($agent->form_name('BuildQuery')); $agent->field("AttachmentField", "Subject"); $agent->field("AttachmentOp", "LIKE"); $agent->field("ValueOfAttachment", "bbb"); -$agent->submit("AddClause"); +$agent->submit(); ok($agent->form_name('BuildQuery')); diff --git a/rt/lib/t/regression/03web_compiliation_errors.t b/rt/lib/t/regression/03web_compiliation_errors.t index 29e56d67b..f2e62c98d 100644 --- a/rt/lib/t/regression/03web_compiliation_errors.t +++ b/rt/lib/t/regression/03web_compiliation_errors.t @@ -12,18 +12,19 @@ my $cookie_jar = HTTP::Cookies->new; my $agent = WWW::Mechanize->new(); # give the agent a place to stash the cookies + $agent->cookie_jar($cookie_jar); use RT; -RT::LoadConfig(); +RT::LoadConfig; # get the top page my $url = $RT::WebURL; -diag "Base URL is '$url'" if $ENV{TEST_VERBOSE}; $agent->get($url); is ($agent->{'status'}, 200, "Loaded a page"); + # {{{ test a login # follow the link marked "Login" @@ -44,19 +45,20 @@ use File::Find; find ( \&wanted , 'html/'); sub wanted { - -f && /\.html$/ && $_ !~ /Logout.html$/ && test_get($File::Find::name); + -f && /\.html$/ && $_ !~ /Logout.html$/ && test_get($File::Find::name); } sub test_get { my $file = shift; - $file =~ s#^html/##; - diag( "testing $url/$file" ) if $ENV{TEST_VERBOSE}; + + $file =~ s#^html/##; ok ($agent->get("$url/$file", "GET $url/$file")); is ($agent->{'status'}, 200, "Loaded $file"); # ok( $agent->{'content'} =~ /Logout/i, "Found a logout link on $file "); ok( $agent->{'content'} !~ /Not logged in/i, "Still logged in for $file"); - ok( $agent->{'content'} !~ /raw error/i, "Didn't get a Mason compilation error on $file"); + ok( $agent->{'content'} !~ /System error/i, "Didn't get a Mason compilation error on $file"); + } # }}} diff --git a/rt/lib/t/regression/04send_email.t b/rt/lib/t/regression/04send_email.t index a175ffaee..09e6e6f84 100644 --- a/rt/lib/t/regression/04send_email.t +++ b/rt/lib/t/regression/04send_email.t @@ -1,12 +1,10 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 142; - +use Test::More tests => 137; use RT; RT::LoadConfig(); RT::Init; - use RT::EmailParser; use RT::Tickets; use RT::Action::SendEmail; @@ -22,29 +20,17 @@ $everyone->PrincipalObj->GrantRight(Right =>'SuperUser'); is (__PACKAGE__, 'main', "We're operating in the main package"); + { - no warnings qw/redefine/; - sub RT::Action::SendEmail::SendMessage { +no warnings qw/redefine/; +sub RT::Action::SendEmail::SendMessage { my $self = shift; my $MIME = shift; main::_fired_scrip($self->ScripObj); main::ok(ref($MIME) eq 'MIME::Entity', "hey, look. it's a mime entity"); - } } -# some utils -sub first_txn { return $_[0]->Transactions->First } -sub first_attach { return first_txn($_[0])->Attachments->First } - -sub count_txns { return $_[0]->Transactions->Count } -sub count_attachs { return first_txn($_[0])->Attachments->Count } - -sub file_content -{ - open my $fh, "<:raw", $_[0] or die "couldn't open file '$_[0]': $!"; - local $/; - return scalar <$fh>; } # instrument SendEmail to pass us what it's about to send. @@ -54,7 +40,7 @@ my $parser = RT::EmailParser->new(); # Let's test to make sure a multipart/report is processed correctly -my $content = file_content("$RT::BasePath/lib/t/data/multipart-report"); +my $content = `cat $RT::BasePath/lib/t/data/multipart-report` || die "couldn't find new content"; # be as much like the mail gateway as possible. use RT::Interface::Email; @@ -67,7 +53,7 @@ my $tick= $tickets->First(); isa_ok($tick, "RT::Ticket", "got a ticket object"); ok ($tick->Id, "found ticket ".$tick->Id); -ok (first_txn($tick)->Content =~ /The original message was received/, "It's the bounce"); +ok ($tick->Transactions->First->Content =~ /The original message was received/, "It's the bounce"); # make sure it fires scrips. @@ -110,7 +96,7 @@ is ($#scrips_fired, 1, "Fired 2 scrips on ticket creation"); # create an iso 8859-1 ticket @scrips_fired = (); -$content = file_content("$RT::BasePath/lib/t/data/new-ticket-from-iso-8859-1"); +$content = `cat $RT::BasePath/lib/t/data/new-ticket-from-iso-8859-1` || die "couldn't find new content"; @@ -128,7 +114,7 @@ $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); $tick = $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); -ok (first_txn($tick)->Content =~ /H\x{e5}vard/, "It's signed by havard. yay"); +ok ($tick->Transactions->First->Content =~ /H\x{e5}vard/, "It's signed by havard. yay"); # make sure it fires scrips. @@ -158,7 +144,7 @@ $RT::EmailOutputEncoding = 'iso-8859-1'; # create an iso 8859-1 ticket @scrips_fired = (); - $content = file_content("$RT::BasePath/lib/t/data/new-ticket-from-iso-8859-1"); + $content = `cat $RT::BasePath/lib/t/data/new-ticket-from-iso-8859-1` || die "couldn't find new content"; # be as much like the mail gateway as possible. use RT::Interface::Email; @@ -170,7 +156,7 @@ $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); $tick = $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); -ok (first_txn($tick)->Content =~ /H\x{e5}vard/, "It's signed by havard. yay"); +ok ($tick->Transactions->First->Content =~ /H\x{e5}vard/, "It's signed by havard. yay"); # make sure it fires scrips. @@ -252,7 +238,7 @@ sub iso8859_redef_sendmessage { # {{{ test a multipart alternative containing a text-html part with an umlaut - $content = file_content("$RT::BasePath/lib/t/data/multipart-alternative-with-umlaut"); + $content = `cat $RT::BasePath/lib/t/data/multipart-alternative-with-umlaut` || die "couldn't find new content"; $parser->ParseMIMEEntityFromScalar($content); @@ -260,17 +246,16 @@ $parser->ParseMIMEEntityFromScalar($content); # be as much like the mail gateway as possible. ¨auts_redef_sendmessage; -%args = (message => $content, queue => 1, action => 'correspond'); -RT::Interface::Email::Gateway(\%args); -$tickets = RT::Tickets->new($RT::SystemUser); + %args = (message => $content, queue => 1, action => 'correspond'); + RT::Interface::Email::Gateway(\%args); + $tickets = RT::Tickets->new($RT::SystemUser); $tickets->OrderBy(FIELD => 'id', ORDER => 'DESC'); $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); -$tick = $tickets->First(); - + $tick = $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); -ok (first_txn($tick)->Content =~ /causes Error/, "We recorded the content right as text-plain"); -is (count_attachs($tick) , 3 , "Has three attachments, presumably a text-plain, a text-html and a multipart alternative"); +ok ($tick->Transactions->First->Content =~ /causes Error/, "We recorded the content right as text-plain"); +is ($tick->Transactions->First->Attachments->Count , 3 , "Has three attachments, presumably a text-plain, a text-html and a multipart alternative"); sub umlauts_redef_sendmessage { no warnings qw/redefine/; @@ -281,7 +266,7 @@ sub umlauts_redef_sendmessage { # {{{ test a text-html message with an umlaut - $content = file_content("$RT::BasePath/lib/t/data/text-html-with-umlaut"); + $content = `cat $RT::BasePath/lib/t/data/text-html-with-umlaut` || die "couldn't find new content"; $parser->ParseMIMEEntityFromScalar($content); @@ -297,28 +282,29 @@ $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); $tick = $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); -ok (first_attach($tick)->Content =~ /causes Error/, "We recorded the content as containing 'causes error'") or diag( first_attach($tick)->Content ); -ok (first_attach($tick)->ContentType =~ /text\/html/, "We recorded the content as text/html"); -is (count_attachs($tick), 1 , "Has one attachment, presumably a text-html and a multipart alternative"); +ok ($tick->Transactions->First->Attachments->First->Content =~ /causes Error/, "We recorded the content as containing 'causes error'"); +ok ($tick->Transactions->First->Attachments->First->ContentType =~ /text\/html/, "We recorded the content as text/html"); +ok ($tick->Transactions->First->Attachments->Count ==1 , "Has one attachment, presumably a text-html and a multipart alternative"); sub text_html_umlauts_redef_sendmessage { no warnings qw/redefine/; eval 'sub RT::Action::SendEmail::SendMessage { - my $self = shift; - my $MIME = shift; + my $self = shift; + my $MIME = shift; + use Data::Dumper; return (1) unless ($self->ScripObj->ScripActionObj->Name eq "Notify AdminCcs" ); - is ($MIME->parts, 2, "generated correspondence mime entityis composed of three parts"); + ok (is $MIME->parts, 2, "generated correspondence mime entityis composed of three parts"); is ($MIME->head->mime_type , "multipart/mixed", "The first part is a multipart mixed". $MIME->head->mime_type); is ($MIME->parts(0)->head->mime_type , "text/plain", "The second part is a plain"); is ($MIME->parts(1)->head->mime_type , "text/html", "The third part is an html "); - }'; + }'; } # }}} # {{{ test a text-html message with russian characters - $content = file_content("$RT::BasePath/lib/t/data/text-html-in-russian"); + $content = `cat $RT::BasePath/lib/t/data/text-html-in-russian` || die "couldn't find new content"; $parser->ParseMIMEEntityFromScalar($content); @@ -334,8 +320,8 @@ $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); $tick = $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); -ok (first_attach($tick)->ContentType =~ /text\/html/, "We recorded the content right as text-html"); -ok (count_attachs($tick) ==1 , "Has one attachment, presumably a text-html and a multipart alternative"); +ok ($tick->Transactions->First->Attachments->First->ContentType =~ /text\/html/, "We recorded the content right as text-html"); +ok ($tick->Transactions->First->Attachments->Count ==1 , "Has one attachment, presumably a text-html and a multipart alternative"); sub text_html_russian_redef_sendmessage { no warnings qw/redefine/; @@ -361,7 +347,7 @@ sub text_html_russian_redef_sendmessage { unshift (@RT::EmailInputEncodings, 'koi8-r'); $RT::EmailOutputEncoding = 'koi8-r'; -$content = file_content("$RT::BasePath/lib/t/data/russian-subject-no-content-type"); +$content = `cat $RT::BasePath/lib/t/data/russian-subject-no-content-type` || die "couldn't find new content"; $parser->ParseMIMEEntityFromScalar($content); @@ -376,8 +362,8 @@ $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); $tick= $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); -ok (first_attach($tick)->ContentType =~ /text\/plain/, "We recorded the content type right"); -ok (count_attachs($tick) ==1 , "Has one attachment, presumably a text-plain"); +ok ($tick->Transactions->First->Attachments->First->ContentType =~ /text\/plain/, "We recorded the content type right"); +ok ($tick->Transactions->First->Attachments->Count ==1 , "Has one attachment, presumably a text-plain"); is ($tick->Subject, "\x{442}\x{435}\x{441}\x{442} \x{442}\x{435}\x{441}\x{442}", "Recorded the subject right"); sub text_plain_russian_redef_sendmessage { no warnings qw/redefine/; @@ -389,7 +375,7 @@ sub text_plain_russian_redef_sendmessage { my $subject = $MIME->head->get("subject"); chomp($subject); #is( $subject , /^=\?KOI8-R\?B\?W2V4YW1wbGUuY39tICM3XSDUxdPUINTF09Q=\?=/ , "The $subject is encoded correctly"); - }; + }; '; } @@ -400,7 +386,7 @@ $RT::EmailOutputEncoding = 'utf-8'; # {{{ test a message containing a nested RFC 822 message - $content = file_content("$RT::BasePath/lib/t/data/nested-rfc-822"); + $content = `cat $RT::BasePath/lib/t/data/nested-rfc-822` || die "couldn't find new content"; ok ($content, "Loaded nested-rfc-822 to test"); $parser->ParseMIMEEntityFromScalar($content); @@ -416,8 +402,8 @@ $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); $tick= $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); is ($tick->Subject, "[Jonas Liljegren] Re: [Para] Niv\x{e5}er?"); -ok (first_attach($tick)->ContentType =~ /multipart\/mixed/, "We recorded the content type right"); -is (count_attachs($tick) , 5 , "Has one attachment, presumably a text-plain and a message RFC 822 and another plain"); +ok ($tick->Transactions->First->Attachments->First->ContentType =~ /multipart\/mixed/, "We recorded the content type right"); +is ($tick->Transactions->First->Attachments->Count , 5 , "Has one attachment, presumably a text-plain and a message RFC 822 and another plain"); sub text_plain_nested_redef_sendmessage { no warnings qw/redefine/; eval 'sub RT::Action::SendEmail::SendMessage { @@ -428,9 +414,9 @@ sub text_plain_nested_redef_sendmessage { my $subject = $MIME->head->get("subject"); $subject = MIME::Base64::decode_base64( $subject); chomp($subject); - # TODO, why does this test fail + # TODO, why does this test fail #ok($subject =~ qr{Niv\x{e5}er}, "The subject matches the word - $subject"); - 1; + 1; }'; } @@ -439,7 +425,7 @@ sub text_plain_nested_redef_sendmessage { # {{{ test a multipart alternative containing a uuencoded mesage generated by lotus notes - $content = file_content("$RT::BasePath/lib/t/data/notes-uuencoded"); + $content = `cat $RT::BasePath/lib/t/data/notes-uuencoded` || die "couldn't find new content"; $parser->ParseMIMEEntityFromScalar($content); @@ -455,8 +441,8 @@ $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); $tick= $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); -ok (first_txn($tick)->Content =~ /from Lotus Notes/, "We recorded the content right"); -is (count_attachs($tick) , 3 , "Has three attachments"); +ok ($tick->Transactions->First->Content =~ /from Lotus Notes/, "We recorded the content right"); +is ($tick->Transactions->First->Attachments->Count , 3 , "Has three attachments"); sub notes_redef_sendmessage { no warnings qw/redefine/; @@ -467,7 +453,7 @@ sub notes_redef_sendmessage { # {{{ test a multipart that crashes the file-based mime-parser works - $content = file_content("$RT::BasePath/lib/t/data/crashes-file-based-parser"); + $content = `cat $RT::BasePath/lib/t/data/crashes-file-based-parser` || die "couldn't find new content"; $parser->ParseMIMEEntityFromScalar($content); @@ -483,8 +469,8 @@ $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); $tick= $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); -ok (first_txn($tick)->Content =~ /FYI/, "We recorded the content right"); -is (count_attachs($tick) , 5 , "Has three attachments"); +ok ($tick->Transactions->First->Content =~ /FYI/, "We recorded the content right"); +is ($tick->Transactions->First->Attachments->Count , 5 , "Has three attachments"); sub crashes_redef_sendmessage { no warnings qw/redefine/; @@ -497,7 +483,7 @@ sub crashes_redef_sendmessage { # {{{ test a multi-line RT-Send-CC header - $content = file_content("$RT::BasePath/lib/t/data/rt-send-cc"); + $content = `cat $RT::BasePath/lib/t/data/rt-send-cc` || die "couldn't find new content"; $parser->ParseMIMEEntityFromScalar($content); @@ -511,7 +497,7 @@ $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0'); $tick= $tickets->First(); ok ($tick->Id, "found ticket ".$tick->Id); -my $cc = first_attach($tick)->GetHeader('RT-Send-Cc'); +my $cc = $tick->Transactions->First->Attachments->First->GetHeader('RT-Send-Cc'); ok ($cc =~ /test1/, "Found test 1"); ok ($cc =~ /test2/, "Found test 2"); ok ($cc =~ /test3/, "Found test 3"); @@ -520,30 +506,6 @@ ok ($cc =~ /test5/, "Found test 5"); # }}} -diag q{regression test for #5248 from rt3.fsck.com} if $ENV{TEST_VERBOSE}; -{ - my $content = file_content("$RT::BasePath/lib/t/data/subject-with-folding-ws"); - my ($status, $msg, $ticket) = RT::Interface::Email::Gateway( - { message => $content, queue => 1, action => 'correspond' } - ); - ok ($status, 'created ticket') or diag "error: $msg"; - ok ($ticket->id, "found ticket ". $ticket->id); - is ($ticket->Subject, 'test', 'correct subject'); -} - -diag q{regression test for #5248 from rt3.fsck.com} if $ENV{TEST_VERBOSE}; -{ - my $content = file_content("$RT::BasePath/lib/t/data/very-long-subject"); - my ($status, $msg, $ticket) = RT::Interface::Email::Gateway( - { message => $content, queue => 1, action => 'correspond' } - ); - ok ($status, 'created ticket') or diag "error: $msg"; - ok ($ticket->id, "found ticket ". $ticket->id); - is ($ticket->Subject, '0123456789'x20, 'correct subject'); -} - - - # Don't taint the environment $everyone->PrincipalObj->RevokeRight(Right =>'SuperUser'); 1; diff --git a/rt/lib/t/regression/06-mime_decoding.t b/rt/lib/t/regression/06-mime_decoding.t index 7780e8c0d..98af18513 100644 --- a/rt/lib/t/regression/06-mime_decoding.t +++ b/rt/lib/t/regression/06-mime_decoding.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 5; use_ok("RT"); @@ -41,14 +41,3 @@ diag q{'=' char in a trailing part after an encoded part} if $ENV{TEST_VERBOSE}; ); } -diag q{regression test for #5248 from rt3.fsck.com} if $ENV{TEST_VERBOSE}; -{ - my $str = qq{Subject: =?ISO-8859-1?Q?Re=3A_=5BXXXXXX=23269=5D_=5BComment=5D_Frag?=} - . qq{\n =?ISO-8859-1?Q?e_zu_XXXXXX--xxxxxx_/_Xxxxx=FCxxxxxxxxxx?=}; - is( - RT::I18N::DecodeMIMEWordsToUTF8($str), - qq{Subject: Re: [XXXXXX#269] [Comment] Frage zu XXXXXX--xxxxxx / Xxxxxüxxxxxxxxxx}, - "right decoding" - ); -} - diff --git a/rt/lib/t/regression/06mailgateway.t b/rt/lib/t/regression/06mailgateway.t index 5fc502926..12b55885e 100644 --- a/rt/lib/t/regression/06mailgateway.t +++ b/rt/lib/t/regression/06mailgateway.t @@ -52,20 +52,19 @@ rt-mailgate - Mail interface to RT3. =cut use strict; -use Test::More tests => 109; +use Test::More tests => 104; use RT; RT::LoadConfig(); RT::Init(); use RT::I18N; -use Digest::MD5 qw(md5_base64); no warnings 'once'; my $url = join( ':', grep $_, "http://localhost", $RT::WebPort ) . $RT::WebPath ."/"; # Make sure that when we call the mailgate wrong, it tempfails -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url http://this.test.for.non-connection.is.expected.to.generate.an.error"), "Opened the mailgate - The error below is expected - $@"); print MAIL <<EOF; From: root\@localhost @@ -82,7 +81,7 @@ is ( $? >> 8, 75, "The error message above is expected The mail gateway exited w # {{{ Test new ticket creation by root who is privileged and superuser -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --debug --url $url --queue general --action correspond"), "Opened the mailgate - $!"); print MAIL <<EOF; From: root\@localhost @@ -108,36 +107,10 @@ ok ($tick->Subject eq 'This is a test of new ticket creation', "Created the tick # }}} -# {{{ Test new ticket creation without --action argument - -$! = 0; -ok(open(MAIL, "|$RT::BinPath/rt-mailgate --debug --url $url --queue general"), "Opened the mailgate - $!"); -print MAIL <<EOF; -From: root\@localhost -To: rt\@$RT::rtname -Subject: using mailgate without --action arg - -Blah! -Foob! -EOF -close (MAIL); - -#Check the return value -is ($? >> 8, 0, "The mail gateway exited normally. yay"); - -$tickets = RT::Tickets->new($RT::SystemUser); -$tickets->OrderBy(FIELD => 'id', ORDER => 'DESC'); -$tickets->Limit(FIELD => 'id', OPERATOR => '>', VALUE => '0'); -$tick = $tickets->First; -isa_ok ($tick,'RT::Ticket'); -ok ($tick->Id, "found ticket ".$tick->Id); -is ($tick->Subject, 'using mailgate without --action arg', "using mailgate without --action arg"); - -# }}} # {{{This is a test of new ticket creation as an unknown user -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!"); print MAIL <<EOF; From: doesnotexist\@$RT::rtname @@ -159,7 +132,7 @@ ok ($tick->Id, "found ticket ".$tick->Id); ok ($tick->Subject ne 'This is a test of new ticket creation as an unknown user', "failed to create the new ticket from an unprivileged account"); my $u = RT::User->new($RT::SystemUser); $u->Load("doesnotexist\@$RT::rtname"); -ok( !$u->Id, " user does not exist and was not created by failed ticket submission"); +ok( $u->Id == 0, " user does not exist and was not created by failed ticket submission"); # }}} @@ -174,7 +147,7 @@ my ($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket'); ok ($val, "Granted everybody the right to create tickets - $msg"); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!"); print MAIL <<EOF; From: doesnotexist\@$RT::rtname @@ -208,7 +181,7 @@ ok( $u->Id != 0, " user does not exist and was created by ticket submission"); #($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket'); #ok ($val, "Granted everybody the right to create tickets - $msg"); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!"); print MAIL <<EOF; From: doesnotexist-2\@$RT::rtname @@ -224,7 +197,7 @@ is ($? >> 8, 0, "The mail gateway exited normally. yay"); $u = RT::User->new($RT::SystemUser); $u->Load('doesnotexist-2@$RT::rtname'); -ok( !$u->Id, " user does not exist and was not created by ticket correspondence submission"); +ok( $u->Id == 0, " user does not exist and was not created by ticket correspondence submission"); # }}} @@ -234,7 +207,7 @@ ok( !$u->Id, " user does not exist and was not created by ticket correspondence ($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'ReplyToTicket'); ok ($val, "Granted everybody the right to reply to tickets - $msg"); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!"); print MAIL <<EOF; From: doesnotexist-2\@$RT::rtname @@ -261,7 +234,7 @@ ok( $u->Id != 0, " user exists and was created by ticket correspondence submissi #($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket'); #ok ($val, "Granted everybody the right to create tickets - $msg"); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $!"); print MAIL <<EOF; From: doesnotexist-3\@$RT::rtname @@ -278,7 +251,7 @@ is ($? >> 8, 0, "The mail gateway exited normally. yay"); $u = RT::User->new($RT::SystemUser); $u->Load("doesnotexist-3\@$RT::rtname"); -ok( !$u->Id, " user does not exist and was not created by ticket comment submission"); +ok( $u->Id == 0, " user does not exist and was not created by ticket comment submission"); # }}} # {{{ can another random reply to a ticket after being granted privs? answer should be yes @@ -287,7 +260,7 @@ ok( !$u->Id, " user does not exist and was not created by ticket comment submiss ($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CommentOnTicket'); ok ($val, "Granted everybody the right to reply to tickets - $msg"); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $!"); print MAIL <<EOF; From: doesnotexist-3\@$RT::rtname @@ -329,7 +302,7 @@ $entity->attach(Path => $LOGO_FILE, Encoding => 'base64'); # Create a ticket with a binary attachment -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!"); $entity->print(\*MAIL); @@ -351,7 +324,8 @@ my $file = `cat $LOGO_FILE`; ok ($file, "Read in the logo image"); -diag( "for the raw file the content is ". md5_base64($file) ); + use Digest::MD5; +warn "for the raw file the content is ".Digest::MD5::md5_base64($file); @@ -363,7 +337,7 @@ my $attachment = $attachments->First; ok($attachment->Id); my $acontent = $attachment->Content; -diag( "coming from the database, the content is ". md5_base64($acontent) ); + warn "coming from the database, the content is ".Digest::MD5::md5_base64($acontent); is( $acontent, $file, 'The attachment isn\'t screwed up in the database.'); # Log in as root @@ -387,7 +361,7 @@ is($file, $r->content, 'The attachment isn\'t screwed up in download'); # {{{ Simple I18N testing -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!"); print MAIL <<EOF; @@ -422,7 +396,7 @@ is ($unitick->Transactions->First->Content, $unitick->Transactions->First->Attac ok($unitick->Transactions->First->Attachments->First->Content =~ /$unistring/i, $unitick->Id." appears to be unicode ". $unitick->Transactions->First->Attachments->First->Id); # supposedly I18N fails on the second message sent in. -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!"); print MAIL <<EOF; @@ -482,7 +456,7 @@ my ($id) = $tick->Create( Queue => 'ext-mailgate', Subject => 'test'); ok( $id, 'new ticket created' ); is( $tick->Owner, $RT::Nobody->Id, 'owner of the new ticket is nobody' ); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take"), "Opened the mailgate - $!"); print MAIL <<EOF; From: root\@localhost @@ -507,7 +481,7 @@ is( $tick->Owner, $RT::Nobody->Id, 'set owner back to nobody'); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $RT::WebURL --queue ext-mailgate --action take-correspond"), "Opened the mailgate - $@"); print MAIL <<EOF; From: root\@localhost @@ -531,7 +505,7 @@ $txns->OrderBy( FIELD => 'id', ORDER => 'DESC' ); is( $tick->Transactions->Count, 6, 'no superfluous transactions'); is( $txns->First->Subject, "[$RT::rtname \#$id] correspondence", 'successfuly add correspond within take via email' ); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action resolve --debug"), "Opened the mailgate - $!"); print MAIL <<EOF; From: root\@localhost @@ -563,7 +537,7 @@ $tick = RT::Ticket->new($RT::SystemUser); ($id) = $tick->Create( Queue => $qid, Subject => 'test' ); ok( $id, 'create new ticket' ); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take"), "Opened the mailgate - $!"); print MAIL <<EOF; From: ext-mailgate\@localhost @@ -581,7 +555,7 @@ ok( $status, "successfuly granted right: $msg" ); my $ace_id = $status; ok( $user->HasRight( Right => 'ReplyToTicket', Object => $tick ), "User can reply to ticket" ); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action correspond-take"), "Opened the mailgate - $!"); print MAIL <<EOF; From: ext-mailgate\@localhost @@ -596,7 +570,7 @@ DBIx::SearchBuilder::Record::Cachable->FlushCache; cmp_ok( $tick->Owner, '!=', $user->id, "we didn't change owner" ); is( $tick->Transactions->Count, 3, "one transactions added" ); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take-correspond"), "Opened the mailgate - $!"); print MAIL <<EOF; From: ext-mailgate\@localhost @@ -637,7 +611,7 @@ ok( $status, "successfuly granted right: $msg" ); ($status, $msg) = $user->PrincipalObj->GrantRight( Object => $queue, Right => 'TakeTicket' ); ok( $status, "successfuly granted right: $msg" ); -$! = 0; +$! = ''; ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take-correspond"), "Opened the mailgate - $!"); print MAIL <<EOF; From: ext-mailgate\@localhost diff --git a/rt/lib/t/regression/07acl.t b/rt/lib/t/regression/07acl.t index efd87016d..e30a59bef 100644 --- a/rt/lib/t/regression/07acl.t +++ b/rt/lib/t/regression/07acl.t @@ -1,9 +1,9 @@ #!/usr/bin/perl -w -use strict; + use WWW::Mechanize; use HTTP::Cookies; -use Test::More tests => 34; +use Test::More qw/no_plan/; use RT; RT::LoadConfig(); RT::Init(); @@ -20,7 +20,6 @@ ok($ret, "ACL test password set. $msg"); # Now test the web interface, making sure objects come and go as # required. - my $cookie_jar = HTTP::Cookies->new; my $agent = WWW::Mechanize->new(); @@ -28,53 +27,62 @@ my $agent = WWW::Mechanize->new(); $agent->cookie_jar($cookie_jar); -no warnings 'once'; + # get the top page -login($agent, $user_obj); +my $url = $RT::WebURL; +$agent->get($url); + +is ($agent->{'status'}, 200, "Loaded a page - $RT::WebURL"); +# {{{ test a login + +# follow the link marked "Login" + +ok($agent->{form}->find_input('user')); + +ok($agent->{form}->find_input('pass')); +ok ($agent->{'content'} =~ /username:/i); +$agent->field( 'user' => 'customer-'.$$ ); +$agent->field( 'pass' => 'customer' ); +# the field isn't named, so we have to click link 0 +$agent->click(0); +is($agent->{'status'}, 200, "Fetched the page ok"); +ok($agent->{'content'} =~ /Logout/i, "Found a logout link"); # Test for absence of Configure and Preferences tabs. -ok(!$agent->find_link( url => $RT::WebPath . "/Admin/", +ok(!$agent->find_link( url => "$RT::WebPath/Admin/", text => 'Configuration'), "No config tab" ); -ok(!$agent->find_link( url => $RT::WebPath . "/User/Prefs.html", +ok(!$agent->find_link( url => "$RT::WebPath/User/Prefs.html", text => 'Preferences'), "No prefs pane" ); # Now test for their presence, one at a time. Sleep for a bit after # ACL changes, thanks to the 10s ACL cache. -my ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ShowConfigTab', Object => $RT::System); - -ok($grantid,$grantmsg); - -$agent->reload; - +$user_obj->PrincipalObj->GrantRight(Right => 'ShowConfigTab'); +$agent->reload(); ok($agent->{'content'} =~ /Logout/i, "Reloaded page successfully"); -ok($agent->find_link( url => $RT::WebPath . "/Admin/", +ok($agent->find_link( url => "$RT::WebPath/Admin/", text => 'Configuration'), "Found config tab" ); -my ($revokeid,$revokemsg) =$user_obj->PrincipalObj->RevokeRight(Right => 'ShowConfigTab'); -ok ($revokeid,$revokemsg); -($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf'); -ok ($grantid,$grantmsg); +$user_obj->PrincipalObj->RevokeRight(Right => 'ShowConfigTab'); +$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf'); $agent->reload(); ok($agent->{'content'} =~ /Logout/i, "Reloaded page successfully"); -ok($agent->find_link( url => $RT::WebPath . "/User/Prefs.html", +ok($agent->find_link( url => "$RT::WebPath/User/Prefs.html", text => 'Preferences'), "Found prefs pane" ); -($revokeid,$revokemsg) = $user_obj->PrincipalObj->RevokeRight(Right => 'ModifySelf'); -ok ($revokeid,$revokemsg); +$user_obj->PrincipalObj->RevokeRight(Right => 'ModifySelf'); + # Good. Now load the search page and test Load/Save Search. -$agent->follow_link( url => $RT::WebPath . "/Search/Build.html", +$agent->follow_link( url => "$RT::WebPath/Search/Build.html", text => 'Tickets'); is($agent->{'status'}, 200, "Fetched search builder page"); ok($agent->{'content'} !~ /Load saved search/i, "No search loading box"); ok($agent->{'content'} !~ /Saved searches/i, "No saved searches box"); -($grantid,$grantmsg) = $user_obj->PrincipalObj->GrantRight(Right => 'LoadSavedSearch'); -ok($grantid,$grantmsg); +$user_obj->PrincipalObj->GrantRight(Right => 'LoadSavedSearch'); $agent->reload(); ok($agent->{'content'} =~ /Load saved search/i, "Search loading box exists"); ok($agent->{'content'} !~ /input\s+type=.submit.\s+name=.Save./i, "Still no saved searches box"); -($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch'); -ok ($grantid,$grantmsg); +$user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch'); $agent->reload(); ok($agent->{'content'} =~ /Load saved search/i, "Search loading box still exists"); @@ -85,24 +93,22 @@ ok($agent->{'content'} =~ /input\s+type=.submit.\s+name=.Save./i, # via SelectOwner. my $queue_obj = RT::Queue->new($RT::SystemUser); -($ret, $msg) = $queue_obj->Create(Name => 'CustomerQueue-'.$$, +($ret, $msg) = $queue_obj->Create(Name => 'CustomerQueue', Description => 'queue for SelectOwner testing'); ok($ret, "SelectOwner test queue creation. $msg"); my $group_obj = RT::Group->new($RT::SystemUser); -($ret, $msg) = $group_obj->CreateUserDefinedGroup(Name => 'CustomerGroup-'.$$, +($ret, $msg) = $group_obj->CreateUserDefinedGroup(Name => 'CustomerGroup', Description => 'group for SelectOwner testing'); ok($ret, "SelectOwner test group creation. $msg"); # Add our customer to the customer group, and give it queue rights. ($ret, $msg) = $group_obj->AddMember($user_obj->PrincipalObj->Id()); ok($ret, "Added customer to its group. $msg"); -($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'OwnTicket', +$group_obj->PrincipalObj->GrantRight(Right => 'OwnTicket', Object => $queue_obj); - -ok($grantid,$grantmsg); -($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'SeeQueue', +$group_obj->PrincipalObj->GrantRight(Right => 'SeeQueue', Object => $queue_obj); -ok ($grantid,$grantmsg); + # Now. When we look at the search page we should be able to see # ourself in the list of possible owners. @@ -111,28 +117,4 @@ ok($agent->form_name('BuildQuery'), "Yep, form is still there"); my $input = $agent->current_form->find_input('ValueOfActor'); ok(grep(/customer-$$/, $input->value_names()), "Found self in the actor listing"); -sub login { - my $agent = shift; - - my $url = $RT::WebURL; - $agent->get($url); - is( $agent->{'status'}, 200, - "Loaded a page - $url" ); - - # {{{ test a login - - # follow the link marked "Login" - - ok( $agent->{form}->find_input('user') ); - - ok( $agent->{form}->find_input('pass') ); - ok( $agent->{'content'} =~ /username:/i ); - $agent->field( 'user' => $user_obj->Name ); - $agent->field( 'pass' => 'customer' ); - - # the field isn't named, so we have to click link 0 - $agent->click(0); - is( $agent->{'status'}, 200, "Fetched the page ok" ); - ok( $agent->{'content'} =~ /Logout/i, "Found a logout link" ); -} 1; diff --git a/rt/lib/t/regression/07rights.t b/rt/lib/t/regression/07rights.t index 6c35a0717..d34627705 100644 --- a/rt/lib/t/regression/07rights.t +++ b/rt/lib/t/regression/07rights.t @@ -112,7 +112,7 @@ ok( $user->HasRight( Right => 'ReplyToTicket', Object => $ticket ), "user is own $group = RT::Group->new( $RT::SystemUser ); ok( $group->LoadQueueRoleGroup( Queue => $queue_id, Type=> 'AdminCc' ), "load queue AdminCc role group" ); $ace = RT::ACE->new( $RT::SystemUser ); -($ace_id, $msg) = $group->PrincipalObj->GrantRight( Right => 'ModifyTicket', Object => $queue ); +my ($ace_id, $msg) = $group->PrincipalObj->GrantRight( Right => 'ModifyTicket', Object => $queue ); ok( $ace_id, "Granted queue AdminCc role group with ModifyTicket right: $msg" ); ok( $group->PrincipalObj->HasRight( Right => 'ModifyTicket', Object => $queue ), "role group can modify ticket" ); ok( !$user->HasRight( Right => 'ModifyTicket', Object => $ticket ), "user is not AdminCc and can't modify ticket" ); diff --git a/rt/lib/t/regression/08web_cf_access.t b/rt/lib/t/regression/08web_cf_access.t index c352bbcf8..012d73381 100644 --- a/rt/lib/t/regression/08web_cf_access.t +++ b/rt/lib/t/regression/08web_cf_access.t @@ -2,14 +2,13 @@ use strict; use Test::More tests => 15; -BEGIN { - use RT; - RT::LoadConfig; - RT::Init; -} +use RT; +RT::LoadConfig; +RT::Init; use Test::WWW::Mechanize; -use constant BaseURL => $RT::WebURL; +$RT::WebURL ||= 0; # avoid stupid warning +my $BaseURL = $RT::WebURL; use constant ImageFile => $RT::MasonComponentRoot .'/NoAuth/images/bplogo.gif'; use constant ImageFileContent => do { local $/; @@ -21,7 +20,7 @@ use constant ImageFileContent => do { my $m = Test::WWW::Mechanize->new; isa_ok($m, 'Test::WWW::Mechanize'); -$m->get( BaseURL."?user=root;pass=password" ); +$m->get( $BaseURL."?user=root;pass=password" ); $m->content_like(qr/Logout/, 'we did log in'); $m->follow_link( text => 'Configuration' ); $m->title_is(q/RT Administration/, 'admin screen'); @@ -86,7 +85,7 @@ $m->title_like(qr/testing img cf creation/, "its title is the Subject"); $m->follow_link( text => 'bplogo.gif' ); $m->content_is(ImageFileContent, "it links to the uploaded image"); -$m->get( BaseURL ); +$m->get( $BaseURL ); $m->follow_link( text => 'Tickets' ); $m->follow_link( text => 'New Query' ); diff --git a/rt/lib/t/regression/12-search.t b/rt/lib/t/regression/12-search.t index 210d4fe33..9cc4aa441 100644 --- a/rt/lib/t/regression/12-search.t +++ b/rt/lib/t/regression/12-search.t @@ -6,7 +6,7 @@ use strict; use warnings; -use Test::More tests => 44; +use Test::More tests => 35; use_ok('RT'); RT::LoadConfig(); RT::Init(); @@ -38,24 +38,6 @@ ok($cf3->id, "Created the SearchTest3 CF"); my $cflabel3 = "CustomField-".$cf3->id; -# There was a bug involving a missing join to ObjectCustomFields that -# caused spurious results on negative searches if another custom field -# with the same name existed on a different queue. Hence, we make -# duplicate CFs on a different queue here -my $dup = RT::Queue->new($RT::SystemUser); -$dup->Create(Name => $queue . "-Copy"); -ok ($dup->id, "Created the duplicate queue"); -my $dupcf = RT::CustomField->new($RT::SystemUser); -$dupcf->Create(Name => 'SearchTest', Type => 'Freeform', MaxValues => 0, Queue => $dup->id); -ok($dupcf->id, "Created the duplicate SearchTest CF"); -$dupcf = RT::CustomField->new($RT::SystemUser); -$dupcf->Create(Name => 'SearchTest2', Type => 'Freeform', MaxValues => 0, Queue => $dup->id); -ok($dupcf->id, "Created the SearchTest2 CF"); -$dupcf = RT::CustomField->new($RT::SystemUser); -$dupcf->Create(Name => 'SearchTest3', Type => 'Freeform', MaxValues => 0, Queue => $dup->id); -ok($dupcf->id, "Created the SearchTest3 CF"); - - # setup some tickets # we'll need a small pile of them, to test various combinations and nulls. # there's probably a way to think harder and do this with fewer @@ -166,7 +148,8 @@ is($tix->Count, 5, "matched LIKE subject"); $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL"); -is($tix->Count, 2, "IS null CF"); + + is($tix->Count, 2, "IS null CF"); $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search1'"); @@ -180,9 +163,14 @@ $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search'"); is($tix->Count, 6, "LIKE requestor"); -$tix = RT::Tickets->new($RT::SystemUser); -$tix->FromSQL("Queue = '$queue' AND Requestors IS NULL"); -is($tix->Count, 1, "Search for no requestor"); +TODO: { + + local $TODO = "Can't search for 'no requestor"; + $tix = RT::Tickets->new($RT::SystemUser); + $tix->FromSQL("Queue = '$queue' AND Requestors IS NULL"); + is($tix->Count, 1, "Search for no requestor"); + +}; $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("Queue = '$queue' AND Subject = 'SearchTest1'"); @@ -235,32 +223,13 @@ is($tix->Count, 4, "like cf and like subject"); $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("CF.SearchTest IS NULL AND CF.SearchTest2 = 'bar2'"); -is($tix->Count, 1, "null cf and is cf"); + + is($tix->Count, 1, "null cf and is cf"); $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL AND CF.SearchTest2 IS NULL"); -is($tix->Count, 1, "null cf and null cf"); -# tests with the same CF listed twice + is($tix->Count, 1, "null cf and null cf"); -$tix = RT::Tickets->new($RT::SystemUser); -$tix->FromSQL("CF.{SearchTest} = 'foo1'"); -is($tix->Count, 1, "is cf.{name} format"); - -$tix = RT::Tickets->new($RT::SystemUser); -$tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3'"); -is($tix->Count, 2, "is cf1 or is cf1"); - -$tix = RT::Tickets->new($RT::SystemUser); -$tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest IS NULL"); -is($tix->Count, 3, "is cf1 or null cf1"); - -$tix = RT::Tickets->new($RT::SystemUser); -$tix->FromSQL("(CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3') AND (CF.SearchTest2 = 'bar1' OR CF.SearchTest2 = 'bar2')"); -is($tix->Count, 1, "(is cf1 or is cf1) and (is cf2 or is cf2)"); - -$tix = RT::Tickets->new($RT::SystemUser); -$tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3' OR CF.SearchTest2 = 'bar1' OR CF.SearchTest2 = 'bar2'"); -is($tix->Count, 3, "is cf1 or is cf1 or is cf2 or is cf2"); diff --git a/rt/lib/t/regression/13-attribute-tests.t b/rt/lib/t/regression/13-attribute-tests.t index fdac94e63..945bbcfb0 100644 --- a/rt/lib/t/regression/13-attribute-tests.t +++ b/rt/lib/t/regression/13-attribute-tests.t @@ -1,6 +1,5 @@ -use strict; -use warnings; -use Test::More tests => 34; + +use Test::More tests => 24; use RT; RT::LoadConfig(); RT::Init(); @@ -20,8 +19,6 @@ ok($user->id, "Created a test user"); ok(1, $user->Attributes->BuildSelectQuery); my $attr = $user->Attributes; -# XXX: Order by id as some tests depend on it -$attr->OrderByCols({ FIELD => 'id' }); ok(1, $attr->BuildSelectQuery); @@ -31,12 +28,6 @@ ok (UNIVERSAL::isa($attr,'RT::Attributes'), 'got the attributes object'); ($id, $msg) = $user->AddAttribute(Name => 'TestAttr', Content => 'The attribute has content'); ok ($id, $msg); is ($attr->Count,1, " One attr after adidng a first one"); - -my $first_attr = $user->FirstAttribute('TestAttr'); -ok($first_attr, "got some sort of attribute"); -isa_ok($first_attr, 'RT::Attribute'); -is($first_attr->Content, 'The attribute has content', "got the right content back"); - ($id, $msg) = $attr->DeleteEntry(Name => $runid); ok(!$id, "Deleted non-existant entry - $msg"); is ($attr->Count,1, "1 attr after deleting an empty attr"); @@ -46,22 +37,11 @@ is ("@names", "TestAttr"); ($id, $msg) = $user->AddAttribute(Name => $runid, Content => "First"); -ok($id, $msg); - -my $runid_attr = $user->FirstAttribute($runid); -ok($runid_attr, "got some sort of attribute"); -isa_ok($runid_attr, 'RT::Attribute'); -is($runid_attr->Content, 'First', "got the right content back"); is ($attr->Count,2, " Two attrs after adding an attribute named $runid"); ($id, $msg) = $user->AddAttribute(Name => $runid, Content => "Second"); ok($id, $msg); -$runid_attr = $user->FirstAttribute($runid); -ok($runid_attr, "got some sort of attribute"); -isa_ok($runid_attr, 'RT::Attribute'); -is($runid_attr->Content, 'First', "got the first content back still"); - is ($attr->Count,3, " Three attrs after adding a secondvalue to $runid"); ($id, $msg) = $attr->DeleteEntry(Name => $runid, Content => "First"); ok($id, $msg); diff --git a/rt/lib/t/regression/14linking.t b/rt/lib/t/regression/14linking.t index c8e57eadd..6fdf61405 100644 --- a/rt/lib/t/regression/14linking.t +++ b/rt/lib/t/regression/14linking.t @@ -1,4 +1,4 @@ -use Test::More tests => '70'; +use Test::More tests => '39'; use_ok('RT'); use_ok('RT::Ticket'); use_ok('RT::ScripConditions'); @@ -12,9 +12,7 @@ RT::Init(); use File::Temp qw/tempfile/; my ($fh, $filename) = tempfile( UNLINK => 1, SUFFIX => '.rt'); my $link_scrips_orig = $RT::LinkTransactionsRun1Scrip; -my $link_acl_chacks_orig = $RT::StrictLinkACL; $RT::LinkTransactionsRun1Scrip = 1; -$RT::StrictLinkACL = 1; my $condition = RT::ScripCondition->new( $RT::SystemUser ); $condition->Load('User Defined'); @@ -70,123 +68,32 @@ my $scrip = RT::Scrip->new($RT::SystemUser); ok($id, "Scrip created"); my $u1 = RT::User->new($RT::SystemUser); -($id,$msg) = $u1->Create(Name => "LinkTestUser.$$"); -ok ($id,$msg); +($id,$msg) =$u1->Create(Name => "LinkTestUser.$$"); -my $creator = RT::CurrentUser->new($u1->id); +ok ($id,$msg); ($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'CreateTicket'); ok ($id,$msg); - -diag('Create tickets without rights to link') if $ENV{'TEST_VERBOSE'}; -{ - # on q2 we have no rights, yet - my $parent = RT::Ticket->new( $RT::SystemUser ); - ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id ); - ok($id,$msg); - my $child = RT::Ticket->new( $creator ); - ($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id ); - ok($id,$msg); - $child->CurrentUser( $RT::SystemUser ); - is($child->_Links('Base')->Count, 0, 'link was not created, no permissions'); - is($child->_Links('Target')->Count, 0, 'link was not create, no permissions'); -} - -diag('Create tickets with rights checks on one end of a link') if $ENV{'TEST_VERBOSE'}; -{ - # on q2 we have no rights, but use checking one only on thing - local $RT::StrictLinkACL = 0; - my $parent = RT::Ticket->new( $RT::SystemUser ); - ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id ); - ok($id,$msg); - my $child = RT::Ticket->new( $creator ); - ($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id, MemberOf => $parent->id ); - ok($id,$msg); - $child->CurrentUser( $RT::SystemUser ); - is($child->_Links('Base')->Count, 1, 'link was created'); - is($child->_Links('Target')->Count, 0, 'link was created only one'); - # no scrip run on second ticket accroding to config option - is(link_count($filename), 0, "scrips ok"); -} - ($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'ModifyTicket'); ok ($id,$msg); -diag('try to add link without rights') if $ENV{'TEST_VERBOSE'}; -{ - # on q2 we have no rights, yet - my $parent = RT::Ticket->new( $RT::SystemUser ); - ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id ); - ok($id,$msg); - my $child = RT::Ticket->new( $creator ); - ($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id ); - ok($id,$msg); - my ($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id); - ok(!$id, $msg); - is(link_count($filename), 0, "scrips ok"); - $child->CurrentUser( $RT::SystemUser ); - is($child->_Links('Base')->Count, 0, 'link was not created, no permissions'); - is($child->_Links('Target')->Count, 0, 'link was not create, no permissions'); -} +my $tid; -diag('add link with rights only on base') if $ENV{'TEST_VERBOSE'}; -{ - # on q2 we have no rights, but use checking one only on thing - local $RT::StrictLinkACL = 0; - my $parent = RT::Ticket->new( $RT::SystemUser ); - ($id,$tid,$msg) = $parent->Create( Subject => 'Link test 1', Queue => $q2->id ); - ok($id,$msg); - my $child = RT::Ticket->new( $creator ); - ($id,$tid,$msg) = $child->Create( Subject => 'Link test 1', Queue => $q1->id ); - ok($id,$msg); - my ($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id); - ok($id, $msg); - is(link_count($filename), 1, "scrips ok"); - $child->CurrentUser( $RT::SystemUser ); - is($child->_Links('Base')->Count, 1, 'link was created'); - is($child->_Links('Target')->Count, 0, 'link was created only one'); - $child->CurrentUser( $creator ); - - # turn off feature and try to delete link, we should fail - $RT::StrictLinkACL = 1; - my ($id, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id); - ok(!$id, $msg); - is(link_count($filename), 1, "scrips ok"); - $child->CurrentUser( $RT::SystemUser ); - $child->_Links('Base')->_DoCount; - is($child->_Links('Base')->Count, 1, 'link was not deleted'); - $child->CurrentUser( $creator ); - - # try to delete link, we should success as feature is active - $RT::StrictLinkACL = 0; - my ($id, $msg) = $child->DeleteLink(Type => 'MemberOf', Target => $parent->id); - ok($id, $msg); - is(link_count($filename), 0, "scrips ok"); - $child->CurrentUser( $RT::SystemUser ); - $child->_Links('Base')->_DoCount; - is($child->_Links('Base')->Count, 0, 'link was deleted'); -} +my $creator = RT::CurrentUser->new($u1->id); -my $tid; my $ticket = RT::Ticket->new( $creator); ok($ticket->isa('RT::Ticket')); ($id,$tid, $msg) = $ticket->Create(Subject => 'Link test 1', Queue => $q1->id); ok ($id,$msg); -diag('try link to itself') if $ENV{'TEST_VERBOSE'}; -{ - my ($id, $msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket->id); - ok(!$id, $msg); - is(link_count($filename), 0, "scrips ok"); -} my $ticket2 = RT::Ticket->new($RT::SystemUser); ($id, $tid, $msg) = $ticket2->Create(Subject => 'Link test 2', Queue => $q2->id); ok ($id, $msg); + ($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); ok(!$id,$msg); ok(link_count($filename) == 0, "scrips ok"); - ($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q2, Right => 'CreateTicket'); ok ($id,$msg); ($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q2, Right => 'ModifyTicket'); @@ -197,9 +104,6 @@ ok(link_count($filename) == 1, "scrips ok"); ($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => -1); ok(!$id,$msg); ok(link_count($filename) == 1, "scrips ok"); -($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); -ok($id,$msg); -is(link_count($filename), 1, "scrips ok"); my $transactions = $ticket2->Transactions; $transactions->Limit( FIELD => 'Type', VALUE => 'AddLink' ); @@ -217,7 +121,6 @@ ok( $transactions->First->Field eq 'ReferredToBy'); ok( $transactions->First->OldValue eq $ticket->URI ); $RT::LinkTransactionsRun1Scrip = 0; - ($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id); ok($id,$msg); ok(link_count($filename) == 2, "scrips ok"); @@ -227,9 +130,6 @@ ok(link_count($filename) == 0, "scrips ok"); # restore $RT::LinkTransactionsRun1Scrip = $link_scrips_orig; -$RT::StrictLinkACL = $link_acl_checks_orig; - -exit(0); sub link_count { diff --git a/rt/lib/t/regression/21query-builder.t b/rt/lib/t/regression/21query-builder.t index 7f9990a30..be04599bc 100644 --- a/rt/lib/t/regression/21query-builder.t +++ b/rt/lib/t/regression/21query-builder.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use Test::More tests => 39; +use Test::More tests => 31; use Test::WWW::Mechanize; use HTTP::Request::Common; use HTTP::Cookies; @@ -16,20 +16,7 @@ my $agent = Test::WWW::Mechanize->new(); $agent->cookie_jar($cookie_jar); use RT; -RT::LoadConfig(); -RT::Init(); - -# create a regression queue if it doesn't exist -{ - my $queue = RT::Queue->new( $RT::SystemUser ); - $queue->Load( 'Regression' ); - if ( $queue->id ) { - ok(1, "queue 'Regression' exists"); - } else { - $queue->Create( Name => 'Regression' ); - ok($queue->id, "created queue 'Regression'"); - } -} +RT::LoadConfig; # get the top page my $url = $RT::WebURL; @@ -78,7 +65,6 @@ $agent->submit(); ok($agent->form_name('BuildQuery'), "found the form a third time"); sub getQueryFromForm { - $agent->form_name('BuildQuery'); # This pulls out the "hidden input" query from the page my $q = $agent->current_form->find_input("Query")->value; $q =~ s/^\s+//g; @@ -140,37 +126,38 @@ $agent->select("clauses", ["1"]); $agent->click("Up"); ok($agent->form_name('BuildQuery'), "found the form again"); -is(getQueryFromForm, "( id > 1234 ) OR Queue != 'Regression'", "moved up"); +TODO: { + local $TODO = "query builder incorrectly changes OR to AND"; + is(getQueryFromForm, "( id > 1234 ) OR Queue != 'Regression'", "moved up"); +} $agent->select("clauses", ["0"]); # this is a null clause + $agent->click("Up"); + ok($agent->form_name('BuildQuery'), "found the form again"); + $agent->content_like(qr/error: can\S+t move up/, "i shouldn't have been able to hit up"); $agent->click("Left"); + ok($agent->form_name('BuildQuery'), "found the form again"); + $agent->content_like(qr/error: can\S+t move left/, "i shouldn't have been able to hit left"); $agent->select("clauses", ["1"]); $agent->select("ValueOfStatus" => "stalled"); + $agent->submit; ok($agent->form_name('BuildQuery'), "found the form again"); is_deeply(selectedClauses, ["2"], 'the one we added is selected'); -is( getQueryFromForm, "( id > 1234 AND Status = 'stalled' ) OR Queue != 'Regression'", "added new one" ); - -# click advanced, enter "C1 OR ( C2 AND C3 )", apply, aggregators should stay the same. -{ - my $response = $agent->get($url."Search/Edit.html"); - ok( $response->is_success, "Fetched /Search/Edit.html" ); - ok($agent->form_number(3), "found the form"); - $agent->field("Query", "Status = 'new' OR ( Status = 'open' AND Subject LIKE 'office' )"); - $agent->submit; - is( getQueryFromForm, - "Status = 'new' OR ( Status = 'open' AND Subject LIKE 'office' )", - "no aggregators change" - ); +TODO: { + local $TODO = "query builder incorrectly changes OR to AND"; + is(getQueryFromForm, "( id > 1234 AND Status = 'stalled' ) OR Queue != 'Regression'", "added new one"); } + + # - new items go one level down # - add items at currently selected level # - if nothing is selected, add at end, one level down @@ -213,32 +200,5 @@ is( getQueryFromForm, "( id > 1234 AND Status = 'stalled' ) OR Queue != 'Regress # }}} -# create a custom field with nonascii name and try to add a condition -{ - my $cf = RT::CustomField->new( $RT::SystemUser ); - $cf->LoadByName( Name => "\x{442}", Queue => 0 ); - if ( $cf->id ) { - is($cf->Type, 'Freeform', 'loaded and type is correct'); - } else { - my ($return, $msg) = $cf->Create( - Name => "\x{442}", - Queue => 0, - Type => 'Freeform', - ); - ok($return, 'created CF') or diag "error: $msg"; - } - - my $response = $agent->get($url."Search/Build.html?NewQuery=1"); - ok( $response->is_success, "Fetched " . $url."Search/Build.html" ); - - ok($agent->form_name('BuildQuery'), "found the form once"); - $agent->field("ValueOf'CF.{\321\202}'", "\321\201"); - $agent->submit(); - is( getQueryFromForm, - "'CF.{\321\202}' LIKE '\321\201'", - "no changes, no duplicate condition with badly encoded text" - ); - -} 1; diff --git a/rt/lib/t/regression/22search_tix_by_txn.t b/rt/lib/t/regression/22search_tix_by_txn.t index bec61b5ad..f43fc6401 100644 --- a/rt/lib/t/regression/22search_tix_by_txn.t +++ b/rt/lib/t/regression/22search_tix_by_txn.t @@ -3,9 +3,10 @@ use warnings; use strict; -use Test::More tests => 10; +#use Test::More tests => 26; +use Test::More qw/no_plan/; -BEGIN{ $ENV{'TZ'} = 'GMT'}; +$ENV{'TZ'} = 'GMT'; use RT; RT::LoadConfig(); @@ -36,3 +37,4 @@ is($txnobj->CreatedObj->ISO,'2005-08-05 20:00:56'); $tix->FromSQL(qq{Updated = "2005-08-05" AND Subject = "$SUBJECT"}); is( $tix->Count, 1); +exit 0; diff --git a/rt/lib/t/regression/22search_tix_by_watcher.t b/rt/lib/t/regression/22search_tix_by_watcher.t index 1df7e72b2..dd87de989 100644 --- a/rt/lib/t/regression/22search_tix_by_watcher.t +++ b/rt/lib/t/regression/22search_tix_by_watcher.t @@ -1,19 +1,23 @@ #!/usr/bin/perl -w - use strict; use warnings; -use Test::More tests => 79; +use Test::More qw/no_plan/; use_ok('RT'); RT::LoadConfig(); RT::Init(); use RT::Ticket; -my $q = RT::Queue->new( $RT::SystemUser ); -my $queue = 'SearchTests-'. rand(200); -$q->Create( Name => $queue ); +my $q = RT::Queue->new($RT::SystemUser); +my $queue = 'SearchTests-'.rand(200); +$q->Create(Name => $queue); + +my @data = ( + { Subject => '1', Requestor => 'bravo@example.com' }, + { Subject => '2', Cc => 'alpha@example.com' }, +); -my ($total, @data, @tickets, %test) = (0, ()); +my $total = 0; sub add_tix_from_data { my @res = (); @@ -29,111 +33,102 @@ sub add_tix_from_data { } return @res; } +add_tix_from_data(); -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 $tix = RT::Tickets->new($RT::SystemUser); + $tix->FromSQL("Queue = '$queue'"); + is($tix->Count, $total, "found $total tickets"); +} - my $count = 0; - $count++ foreach grep $_, values %{ $test{$key} }; - TODO: { - local $TODO = "we can't generate this query yet"; - is($tix->Count, $count, "found correct number of ticket(s) by '$key'") or $error = 1; - }; +{ + my $tix = RT::Tickets->new($RT::SystemUser); + $tix->FromSQL("Queue = '$queue' AND Requestor = 'bravo\@example.com'"); + is($tix->Count, 1, "found ticket(s)"); + is($tix->First->RequestorAddresses, 'bravo@example.com',"correct requestor"); +} - 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; +{ + my $tix = RT::Tickets->new($RT::SystemUser); + $tix->FromSQL("Queue = '$queue' AND Cc = 'alpha\@example.com'"); + is($tix->Count, 1, "found ticket(s)"); + is($tix->First->CcAddresses, 'alpha@example.com', "correct Cc"); +} - diag "Wrong SQL query for '$key':". $tix->BuildSelectQuery if $error; +{ + my $tix = RT::Tickets->new($RT::SystemUser); + $tix->FromSQL("Queue = '$queue' AND (Cc = 'alpha\@example.com' OR Requestor = 'bravo\@example.com')"); + is($tix->Count, 2, "found ticket(s)"); + my @mails; + while (my $t = $tix->Next) { + push @mails, $t->RequestorAddresses; + push @mails, $t->CcAddresses; } + @mails = sort grep $_, @mails; + is_deeply(\@mails, ['alpha@example.com', 'bravo@example.com'], "correct addresses"); } -@data = ( - { Subject => 'xy', Requestor => ['x@example.com', 'y@example.com'] }, - { Subject => 'x', Requestor => 'x@example.com' }, - { Subject => 'y', Requestor => 'y@example.com' }, - { Subject => '-', }, - { Subject => 'z', Requestor => 'z@example.com' }, -); -%test = ( - 'Requestor = "x@example.com"' => { xy => 1, x => 1, y => 0, '-' => 0, z => 0 }, - 'Requestor != "x@example.com"' => { xy => 0, x => 0, y => 1, '-' => 1, z => 1 }, - - 'Requestor = "y@example.com"' => { xy => 1, x => 0, y => 1, '-' => 0, z => 0 }, - 'Requestor != "y@example.com"' => { xy => 0, x => 1, y => 0, '-' => 1, z => 1 }, - - 'Requestor LIKE "@example.com"' => { xy => 1, x => 1, y => 1, '-' => 0, z => 1 }, - 'Requestor NOT LIKE "@example.com"' => { xy => 0, x => 0, y => 0, '-' => 1, z => 0 }, +{ + my $tix = RT::Tickets->new($RT::SystemUser); + $tix->FromSQL("Queue = '$queue' AND (Cc = 'alpha\@example.com' AND Requestor = 'bravo\@example.com')"); + is($tix->Count, 0, "found ticket(s)"); +} - 'Requestor IS NULL' => { xy => 0, x => 0, y => 0, '-' => 1, z => 0 }, - 'Requestor IS NOT NULL' => { xy => 1, x => 1, y => 1, '-' => 0, z => 1 }, +{ + my $tix = RT::Tickets->new($RT::SystemUser); + $tix->FromSQL("Queue = '$queue' AND Cc != 'alpha\@example.com'"); + is($tix->Count, 1, "found ticket(s)"); + is($tix->First->RequestorAddresses, 'bravo@example.com',"correct requestor"); +} - 'Requestor = "x@example.com" AND Requestor = "y@example.com"' => { xy => 1, x => 0, y => 0, '-' => 0, z => 0 }, - 'Requestor = "x@example.com" OR Requestor = "y@example.com"' => { xy => 1, x => 1, y => 1, '-' => 0, z => 0 }, +@data = ( { Subject => '3' } ); +add_tix_from_data(); - 'Requestor != "x@example.com" AND Requestor != "y@example.com"' => { xy => 0, x => 0, y => 0, '-' => 1, z => 1 }, - 'Requestor != "x@example.com" OR Requestor != "y@example.com"' => { xy => 0, x => 1, y => 1, '-' => 1, z => 1 }, +{ + my $tix = RT::Tickets->new($RT::SystemUser); + $tix->FromSQL("Queue = '$queue' AND Cc != 'alpha\@example.com'"); + is($tix->Count, 2, "found ticket(s)"); + my @mails; + while (my $t = $tix->Next) { push @mails, ($t->CcAddresses||'') } + is( scalar(grep 'alpha@example.com' eq $_, @mails), 0, "no tickets with non required data"); +} - 'Requestor = "x@example.com" AND Requestor != "y@example.com"' => { xy => 0, x => 1, y => 0, '-' => 0, z => 0 }, - 'Requestor = "x@example.com" OR Requestor != "y@example.com"' => { xy => 1, x => 1, y => 0, '-' => 1, z => 1 }, +{ + # has no requestor search + my $tix = RT::Tickets->new($RT::SystemUser); + $tix->FromSQL("Queue = '$queue' AND Requestor IS NULL"); + is($tix->Count, 2, "found ticket(s)"); + my @mails; + while (my $t = $tix->Next) { push @mails, ($t->RequestorAddresses||'') } + is( scalar(grep $_, @mails), 0, "no tickets with non required data"); +} - 'Requestor != "x@example.com" AND Requestor = "y@example.com"' => { xy => 0, x => 0, y => 1, '-' => 0, z => 0 }, - 'Requestor != "x@example.com" OR Requestor = "y@example.com"' => { xy => 1, x => 0, y => 1, '-' => 1, z => 1 }, -); -@tickets = add_tix_from_data(); { + # has at least one requestor search my $tix = RT::Tickets->new($RT::SystemUser); - $tix->FromSQL("Queue = '$queue'"); - is($tix->Count, $total, "found $total tickets"); + $tix->FromSQL("Queue = '$queue' AND Requestor IS NOT NULL"); + is($tix->Count, 1, "found ticket(s)"); + my @mails; + while (my $t = $tix->Next) { push @mails, ($t->RequestorAddresses||'') } + is( scalar(grep !$_, @mails), 0, "no tickets with non required data"); } -run_tests(); -@data = ( - { Subject => 'xy', Cc => ['x@example.com'], Requestor => [ 'y@example.com' ] }, - { Subject => 'x-', Cc => ['x@example.com'], Requestor => [] }, - { Subject => '-y', Cc => [], Requestor => [ 'y@example.com' ] }, - { Subject => '-', }, - { Subject => 'zz', Cc => ['z@example.com'], Requestor => [ 'z@example.com' ] }, - { Subject => 'z-', Cc => ['z@example.com'], Requestor => [] }, - { Subject => '-z', Cc => [], Requestor => [ 'z@example.com' ] }, -); -%test = ( - 'Cc = "x@example.com" AND Requestor = "y@example.com"' => - { xy => 1, 'x-' => 0, '-y' => 0, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - 'Cc = "x@example.com" OR Requestor = "y@example.com"' => - { xy => 1, 'x-' => 1, '-y' => 1, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - - 'Cc != "x@example.com" AND Requestor = "y@example.com"' => - { xy => 0, 'x-' => 0, '-y' => 1, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - 'Cc != "x@example.com" OR Requestor = "y@example.com"' => - { xy => 1, 'x-' => 0, '-y' => 1, '-' => 1, zz => 1, 'z-' => 1, '-z' => 1 }, - - 'Cc IS NULL AND Requestor = "y@example.com"' => - { xy => 0, 'x-' => 0, '-y' => 1, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - 'Cc IS NULL OR Requestor = "y@example.com"' => - { xy => 1, 'x-' => 0, '-y' => 1, '-' => 1, zz => 0, 'z-' => 0, '-z' => 1 }, - - 'Cc IS NOT NULL AND Requestor = "y@example.com"' => - { xy => 1, 'x-' => 0, '-y' => 0, '-' => 0, zz => 0, 'z-' => 0, '-z' => 0 }, - 'Cc IS NOT NULL OR Requestor = "y@example.com"' => - { xy => 1, 'x-' => 1, '-y' => 1, '-' => 0, zz => 1, 'z-' => 1, '-z' => 0 }, -); -@tickets = add_tix_from_data(); +@data = ( { Subject => '3', Requestor => 'charly@example.com' } ); +add_tix_from_data(); + { + # has no requestor search my $tix = RT::Tickets->new($RT::SystemUser); - $tix->FromSQL("Queue = '$queue'"); - is($tix->Count, $total, "found $total tickets"); + $tix->FromSQL("Queue = '$queue' AND + (Requestor = 'bravo\@example.com' OR Requestor = 'charly\@example.com')"); + is($tix->Count, 2, "found ticket(s)"); + my @mails; + while (my $t = $tix->Next) { push @mails, ($t->RequestorAddresses||'') } + is_deeply( [sort @mails], + ['bravo@example.com', 'charly@example.com'], + "requestor addresses are correct" + ); } -run_tests(); # owner is special watcher because reference is duplicated in two places, # owner was an ENUM field now it's WATCHERFIELD, but should support old @@ -142,12 +137,12 @@ my $nobody = RT::Nobody(); { my $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner = '". $nobody->id ."'"); - ok($tix->Count, "found ticket(s)"); + is($tix->Count, 4, "found ticket(s)"); } { my $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner = '". $nobody->Name ."'"); - ok($tix->Count, "found ticket(s)"); + is($tix->Count, 4, "found ticket(s)"); } { my $tix = RT::Tickets->new($RT::SystemUser); @@ -163,7 +158,7 @@ my $nobody = RT::Nobody(); { my $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner.Name LIKE 'nob'"); - ok($tix->Count, "found ticket(s)"); + is($tix->Count, 4, "found ticket(s)"); } { @@ -181,7 +176,7 @@ my $nobody = RT::Nobody(); my $tix = RT::Tickets->new($RT::SystemUser); $tix->FromSQL("Queue = '$queue' AND Owner = 'Nobody'"); - is($tix->Count, $total, "found ticket(s)"); + is($tix->Count, 4, "found ticket(s)"); } { @@ -194,7 +189,7 @@ my $nobody = RT::Nobody(); ok($id, "granted OwnTicket right to Everyone on '$queue'") or diag("error: $msg"); my $u = RT::User->new( $RT::SystemUser ); - $u->LoadOrCreateByEmail('alpha@example.com'); + $u->LoadByCols( EmailAddress => 'alpha@example.com' ); ok($u->id, "loaded user"); @data = ( { Subject => '4', Owner => $u->id } ); my($t) = add_tix_from_data(); @@ -202,7 +197,7 @@ my $nobody = RT::Nobody(); my $u_alpha_id = $u->id; $u = RT::User->new( $RT::SystemUser ); - $u->LoadOrCreateByEmail('bravo@example.com'); + $u->LoadByCols( EmailAddress => 'bravo@example.com' ); ok($u->id, "loaded user"); @data = ( { Subject => '5', Owner => $u->id } ); ($t) = add_tix_from_data(); @@ -217,5 +212,4 @@ my $nobody = RT::Nobody(); is($tix->Count, 2, "found ticket(s)"); } - exit(0) diff --git a/rt/lib/t/regression/23-web_attachments.t b/rt/lib/t/regression/23-web_attachments.t index adc38adb5..d9d1a8440 100644 --- a/rt/lib/t/regression/23-web_attachments.t +++ b/rt/lib/t/regression/23-web_attachments.t @@ -22,17 +22,17 @@ $m->content_like(qr/Logout/, 'we did log in'); my $qid; { - $m->content =~ /<SELECT\s+NAME\s*="Queue"\s*>.*?<OPTION\s+VALUE="(\d+)".*?>\s*\Q$queue_name\E\s*<\/OPTION>/msig; + $m->content =~ /<SELECT\s+NAME\s*="Queue">.*?<OPTION\s+VALUE="(\d+)"\s*\d*>\s*\Q$queue_name\E\s*<\/OPTION>/msi; ok( $qid = $1, "found id of the '$queue_name' queue"); } -$m->form_name('CreateTicketInQueue'); +$m->form_number(1); $m->field('Queue', $qid); $m->submit; is($m->status, 200, "request successful"); $m->content_like(qr/Create a new ticket/, 'ticket create page'); -$m->form_name('TicketCreate'); +$m->form('TicketCreate'); $m->field('Subject', 'Attachments test'); $m->field('Attach', LogoFile); $m->field('Content', 'Some content'); @@ -44,12 +44,12 @@ $m->content_like(qr/Some content/, 'and content'); $m->content_like(qr/Download bplogo\.gif/, 'page has file name'); $m->follow_link_ok({text => 'Reply'}, "reply to the ticket"); -$m->form_name('TicketUpdate'); +$m->form('TicketUpdate'); $m->field('Attach', LogoFile); $m->click('AddMoreAttach'); is($m->status, 200, "request successful"); -$m->form_name('TicketUpdate'); +$m->form('TicketUpdate'); $m->field('Attach', FaviconFile); $m->field('UpdateContent', 'Message'); $m->click('SubmitTicket'); |