X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Ft%2Fweb%2Fcommand_line.t;h=47f672856aaa2ebf062143c72dde690acd3e0158;hb=681a340f6be4184b1472a8e1fa9cd5d074f6f325;hp=1fed8e69e535d65a0c19df642d47e2a8aa93f18c;hpb=f3c4966ed1f6ec3db7accd6dcdd3a5a3821d72a7;p=freeside.git diff --git a/rt/t/web/command_line.t b/rt/t/web/command_line.t index 1fed8e69e..47f672856 100644 --- a/rt/t/web/command_line.t +++ b/rt/t/web/command_line.t @@ -1,9 +1,8 @@ -#!/usr/bin/perl -w - use strict; +use warnings; use File::Spec (); use Test::Expect; -use RT::Test tests => 303, actual_server => 1; +use RT::Test tests => undef, actual_server => 1; my ($baseurl, $m) = RT::Test->started_ok; use RT::User; @@ -83,6 +82,16 @@ TODO: { expect_like(qr/$queue_id: EditedQueue$$/, 'Found the queue'); } +# Queues with spaces in their names +expect_send("create -t queue set Name='Spaced Out'", 'Creating a queue...'); +expect_like(qr/Queue \d+ created/, 'Created the queue'); +expect_handle->before() =~ /Queue (\d+) created/; +my $other_queue = $1; +ok($other_queue, "Got queue id=$other_queue"); +expect_send("show 'queue/Spaced Out'", 'Showing the queue...'); +expect_like(qr/id: queue\/$other_queue/, 'Saw the queue'); +expect_like(qr/Name: Spaced Out/, 'Saw the modification'); + # Set up a custom field for editing tests @@ -102,11 +111,11 @@ ok($val,$msg); # add a comment to ticket expect_send("comment -m 'comment-$$' $ticket_id", "Adding a comment..."); - expect_like(qr/Message recorded/, "Added the comment"); + expect_like(qr/Comments added/, "Added the comment"); ### should test to make sure it actually got added # add correspondance to ticket (?) expect_send("correspond -m 'correspond-$$' $ticket_id", "Adding correspondence..."); - expect_like(qr/Message recorded/, "Added the correspondence"); + expect_like(qr/Correspondence added/, "Added the correspondence"); ### should test to make sure it actually got added my $test_email = RT::Test::get_relocatable_file('lorem-ipsum', @@ -115,7 +124,7 @@ ok($val,$msg); # text attachment check_attachment($test_email); # binary attachment - check_attachment($RT::MasonComponentRoot.'/NoAuth/images/bpslogo.png'); + check_attachment($RT::StaticPath . '/images/bpslogo.png'); # change a ticket's Owner expect_send("edit ticket/$ticket_id set owner=root", 'Changing owner...'); @@ -149,112 +158,165 @@ expect_send("show ticket/$ticket_id -f queue", 'Verifying change...'); expect_like(qr/Queue: EditedQueue$$/, 'Verified change'); # cannot move ticket to a nonexistent queue expect_send("edit ticket/$ticket_id set queue=nonexistent-$$", 'Changing to nonexistent queue...'); -expect_like(qr/queue does not exist/i, 'Errored out'); +expect_like(qr/Queue nonexistent-$$ does not exist/i, 'Errored out'); expect_send("show ticket/$ticket_id -f queue", 'Verifying lack of change...'); expect_like(qr/Queue: EditedQueue$$/, 'Verified lack of change'); # Test reading and setting custom fields without spaces expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking initial value'); -expect_like(qr/CF\.{myCF$$}:/i, 'Verified initial empty value (CF-x syntax)'); +expect_like(qr/\QCF.{myCF$$}\E:/i, 'Verified initial empty value (CF-x syntax)'); expect_send("show ticket/$ticket_id -f CF.{myCF$$}", 'Checking initial value'); -expect_like(qr/CF\.{myCF$$}:/i, 'Verified initial empty value (CF.{x} syntax)'); +expect_like(qr/\QCF.{myCF$$}\E:/i, 'Verified initial empty value (CF.{x} syntax)'); expect_send("edit ticket/$ticket_id set 'CF-myCF$$=VALUE' ", 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed cf'); expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking new value'); -expect_like(qr/CF\.{myCF$$}: VALUE/i, 'Verified change'); +expect_like(qr/\QCF.{myCF$$}\E: VALUE/i, 'Verified change'); # Test setting 0 as value of the custom field expect_send("edit ticket/$ticket_id set 'CF-myCF$$=0' ", 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed cf'); expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking new value'); -expect_like(qr/CF\.{myCF$$}: 0/i, 'Verified change'); +expect_like(qr/\QCF.{myCF$$}\E: 0/i, 'Verified change'); expect_send("edit ticket/$ticket_id set 'CF.{myCF$$}=VALUE' ",'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed cf'); expect_send("show ticket/$ticket_id -f CF.{myCF$$}", 'Checking new value'); -expect_like(qr/CF\.{myCF$$}: VALUE/i, 'Verified change'); +expect_like(qr/\QCF.{myCF$$}\E: VALUE/i, 'Verified change'); # Test setting 0 as value of the custom field expect_send("edit ticket/$ticket_id set 'CF.{myCF$$}=0' ", 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed cf'); expect_send("show ticket/$ticket_id -f CF.{myCF$$}", 'Checking new value'); -expect_like(qr/CF\.{myCF$$}: 0/i, 'Verified change'); +expect_like(qr/\QCF.{myCF$$}\E: 0/i, 'Verified change'); # Test reading and setting custom fields with spaces expect_send("show ticket/$ticket_id -f 'CF-my CF$$'", 'Checking initial value'); -expect_like(qr/CF\.{my CF$$}:/i, 'Verified change'); +expect_like(qr/\QCF.{my CF$$}\E:/i, 'Verified change'); expect_send("edit ticket/$ticket_id set 'CF-my CF$$=VALUE' ", 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed cf'); expect_send("show ticket/$ticket_id -f 'CF-my CF$$'", 'Checking new value'); -expect_like(qr/CF\.{my CF$$}: VALUE/i, 'Verified change'); +expect_like(qr/\QCF.{my CF$$}\E: VALUE/i, 'Verified change'); expect_send("ls -l 'id = $ticket_id' -f 'CF-my CF$$'", 'Checking new value'); -expect_like(qr/CF\.{my CF$$}: VALUE/i, 'Verified change'); +expect_like(qr/\QCF.{my CF$$}\E: VALUE/i, 'Verified change'); expect_send("show ticket/$ticket_id -f 'CF.{my CF$$}'", 'Checking initial value'); -expect_like(qr/CF\.{my CF$$}: VALUE/i, 'Verified change'); +expect_like(qr/\QCF.{my CF$$}\E: VALUE/i, 'Verified change'); expect_send("edit ticket/$ticket_id set 'CF.{my CF$$}=NEW' ", 'Changing CF...'); expect_send("show ticket/$ticket_id -f 'CF.{my CF$$}'", 'Checking new value'); -expect_like(qr/CF\.{my CF$$}: NEW/i, 'Verified change'); +expect_like(qr/\QCF.{my CF$$}\E: NEW/i, 'Verified change'); expect_send("ls -l 'id = $ticket_id' -f 'CF.{my CF$$}'", 'Checking new value'); -expect_like(qr/CF\.{my CF$$}: NEW/i, 'Verified change'); +expect_like(qr/\QCF.{my CF$$}\E: NEW/i, 'Verified change'); # Test reading and setting single value custom field with commas or quotes expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking initial value'); -expect_like(qr/CF\.{myCF$$}:/i, 'Verified change'); +expect_like(qr/\QCF.{myCF$$}\E:/i, 'Verified change'); expect_send("edit ticket/$ticket_id set CF-myCF$$=1,2,3", 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed cf'); expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking new value'); -expect_like(qr/CF\.{myCF$$}: 1,2,3/i, 'Verified change'); -expect_send("edit ticket/$ticket_id set CF-myCF$$=\"1's,2,3\"", 'Changing CF...'); +expect_like(qr/\QCF.{myCF$$}\E: 1,2,3/i, 'Verified change'); +expect_send(qq{edit ticket/$ticket_id set CF-myCF$$="1's,2,3"}, 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed cf'); expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking new value'); -expect_like(qr/CF\.{myCF$$}: 1's,2,3/i, 'Verified change'); +expect_like(qr/\QCF.{myCF$$}\E: 1's,2,3/i, 'Verified change'); # Test reading and setting custom fields with multiple values expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking initial value'); -expect_like(qr/CF\.{MultipleCF$$}:/i, 'Verified multiple cf change'); +expect_like(qr/\QCF.{MultipleCF$$}\E:/i, 'Verified multiple cf change'); expect_send("edit ticket/$ticket_id set CF.{MultipleCF$$}=1,2,3 ", 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf'); expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: 1,\s*2,\s*3/i, 'Verified multiple cf change'); +expect_like(qr/\QCF.{MultipleCF$$}\E: 1,\s*2,\s*3/i, 'Verified multiple cf change'); expect_send("edit ticket/$ticket_id set CF.{MultipleCF$$}=a,b,c ", 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf'); expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: a,\s*b,\s*c/i, 'Verified change'); +expect_like(qr/\QCF.{MultipleCF$$}\E: a,\s*b,\s*c/i, 'Verified change'); expect_send("edit ticket/$ticket_id del CF.{MultipleCF$$}=a", 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'del multiple cf'); expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: b,\s*c/i, 'Verified multiple cf change'); +expect_like(qr/\QCF.{MultipleCF$$}\E: b,\s*c/i, 'Verified multiple cf change'); expect_send("edit ticket/$ticket_id add CF.{MultipleCF$$}=o", 'Changing CF...'); expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf'); expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: b,\s*c,\s*o/i, 'Verified multiple cf change'); - -expect_send("edit ticket/$ticket_id set CF.{MultipleCF$$}=\"'a,b,c'\" ", 'Changing CF...'); -expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf'); -expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: 'a,b,c'/i, 'Verified change'); -expect_send("edit ticket/$ticket_id del CF.{MultipleCF$$}=a", 'Changing CF...'); -expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf'); -expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: 'a,b,c'/i, 'Verified change'); +expect_like(qr/\QCF.{MultipleCF$$}\E: b,\s*c,\s*o/i, 'Verified multiple cf change'); + +sub multi_round_trip { + my ($op, $value, $regex) = @_; + $Test::Builder::Level++; + # The outer double quotes are for the argument parsing that the + # command-line does; the extra layer of escaping is to for them, as + # well. It is equivilent to the quoting that the shell would + # require. + my $quoted = $value; + $quoted =~ s/(["\\])/\\$1/g; + expect_send(qq{edit ticket/$ticket_id $op CF.{MultipleCF$$}="$quoted"}, qq{CF $op $value}); + expect_like(qr/Ticket $ticket_id updated/, qq{Got expected "updated" answer}); + expect_send(qq{show ticket/$ticket_id -f CF.{MultipleCF$$}}, qq{Sent "show"}); + expect_like(qr/\QCF.{MultipleCF$$}\E: $regex$/i, qq{Answer matches $regex}); +} -expect_send("edit ticket/$ticket_id set CF.{MultipleCF$$}=q{a,b,c}", 'Changing CF...'); -expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf'); -expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: 'a,b,c'/i, 'Verified change'); -expect_send("edit ticket/$ticket_id del CF.{MultipleCF$$}=a", 'Changing CF...'); -expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf'); -expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: 'a,b,c'/i, 'Verified change'); -expect_send("edit ticket/$ticket_id del CF.{MultipleCF$$}=\"'a,b,c'\"", 'Changing CF...'); +# Test simple quoting +my $ticket = RT::Ticket->new($RT::SystemUser); +$ticket->Load($ticket_id); +multi_round_trip(set => q|'a,b,c'|, qr/'a,b,c'/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 1, "Has only one CF value"); +is($ticket->FirstCustomFieldValue("MultipleCF$$"), q{a,b,c}, "And that CF value is as expected"); + +multi_round_trip(del => q|a|, qr/'a,b,c'/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 1, "Still has only one CF value"); +is($ticket->FirstCustomFieldValue("MultipleCF$$"), q{a,b,c}, "And that CF value is as expected"); + +multi_round_trip(set => q|q{a,b,c}|, qr/'a,b,c'/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 1, "Still has only one CF value"); +is($ticket->FirstCustomFieldValue("MultipleCF$$"), q{a,b,c}, "And that CF value is as expected"); + +multi_round_trip(del => q|a|, qr/'a,b,c'/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 1, "Still has only one CF value"); +is($ticket->FirstCustomFieldValue("MultipleCF$$"), q{a,b,c}, "And that CF value is as expected"); + +multi_round_trip(del => q|'a,b,c'|, qr/\s*/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 0, "Now has no CF values"); + +multi_round_trip(set => q|q{1,2's,3}|, qr/'1,2\\'s,3'/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 1, "Still has only one CF value"); +is($ticket->FirstCustomFieldValue("MultipleCF$$"), q{1,2's,3}, "And that CF value is as expected"); + +multi_round_trip(del => q|q{1,2's,3}|, qr/\s*/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 0, "Now has no CF values"); + +# Test escaping of quotes - generate (foo)(bar') with no escapes +multi_round_trip(set => q|'foo',bar'|, qr/foo,bar'/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 2, "Has two values"); +is($ticket->CustomFieldValues("MultipleCF$$")->First->Content, q|foo|, "Direct value checks out"); +is($ticket->CustomFieldValues("MultipleCF$$")->Last->Content, q|bar'|, "Direct value checks out"); +multi_round_trip(del => q|bar'|, qr/foo/); + +# With one \, generate (foo',bar) + +# We obviously need two \s in the following q|| string in order to +# generate a string with one actual \ in it; this causes the string to, +# in general, have twice as many \s in it as we wish to test. +multi_round_trip(set => q|'foo\\',bar'|, qr/'foo\\',bar'/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 1, "Has one value"); +is($ticket->CustomFieldValues("MultipleCF$$")->First->Content, q|foo',bar|, "Direct value checks out"); + +# With two \, generate (foo\)(bar') +multi_round_trip(set => q|'foo\\\\',bar'|, qr/foo\\,bar'/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 2, "Has two values"); +is($ticket->CustomFieldValues("MultipleCF$$")->First->Content, q|foo\\|, "Direct value checks out"); +is($ticket->CustomFieldValues("MultipleCF$$")->Last->Content, q|bar'|, "Direct value checks out"); +multi_round_trip(del => q|bar'|, qr/foo\\/); + +# With three \, generate (foo\',bar) +multi_round_trip(set => q|'foo\\\\\\',bar'|, qr/'foo\\\\\\',bar'/); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 1, "Has one value"); +is($ticket->CustomFieldValues("MultipleCF$$")->First->Content, q|foo\\',bar|, "Direct value checks out"); + +# Check that we don't infinite-loop on 'foo'bar,baz; this should be ('foo'bar)(baz) +expect_send("edit ticket/$ticket_id set CF.{MultipleCF$$}=\"'foo'bar,baz\"", 'Changing CF to have quotes not at commas'); expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf'); -expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: \s*$/i, 'Verified change'); +is($ticket->CustomFieldValues("MultipleCF$$")->Count, 2, "Has two value"); +is($ticket->CustomFieldValues("MultipleCF$$")->First->Content, q|'foo'bar|, "Direct value checks out"); +is($ticket->CustomFieldValues("MultipleCF$$")->Last->Content, q|baz|, "Direct value checks out"); -expect_send("edit ticket/$ticket_id set CF.{MultipleCF$$}=\"q{1,2's,3}\"", 'Changing CF...'); -expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf'); -expect_send("show ticket/$ticket_id -f CF.{MultipleCF$$}", 'Checking new value'); -expect_like(qr/CF\.{MultipleCF$$}: '1,2\\'s,3'/i, 'Verified change'); # ... # change a ticket's ...[other properties]... @@ -392,9 +454,9 @@ expect_send("merge $merge_ticket_B $merge_ticket_A", 'Merging the tickets...'); expect_like(qr/Merge completed/, 'Merged the tickets'); expect_send("show ticket/$merge_ticket_A/history", 'Checking merge on first ticket'); -expect_like(qr/Merged into ticket #$merge_ticket_A by root/, 'Merge recorded in first ticket'); +expect_like(qr/Merged into #$merge_ticket_A: CLIMergeTest1-$$ by root/, 'Merge recorded in first ticket'); expect_send("show ticket/$merge_ticket_B/history", 'Checking merge on second ticket'); -expect_like(qr/Merged into ticket #$merge_ticket_A by root/, 'Merge recorded in second ticket'); +expect_like(qr/Merged into #$merge_ticket_A: CLIMergeTest1-$$ by root/, 'Merge recorded in second ticket'); { # create a user; give them privileges to take and steal @@ -480,6 +542,8 @@ expect_like(qr/Merged into ticket #$merge_ticket_A by root/, 'Merge recorded in expect_like(qr/Created link $link1_id $reln $link2_id/, 'Linked'); expect_send("show -s ticket/$link1_id/links", "Checking creation of $reln..."); expect_like(qr/$display_relns{$reln}: [\w\d\.\-]+:\/\/[\w\d\.]+\/ticket\/$link2_id/, "Created link $reln"); + expect_send("show ticket/$link1_id/links", "Checking show links without format"); + expect_like(qr/$display_relns{$reln}: [\w\d\.\-]+:\/\/[\w\d\.]+\/ticket\/$link2_id/, "Found link $reln"); # delete link expect_send("link -d $link1_id $reln $link2_id", "Delete $reln..."); @@ -511,7 +575,7 @@ sub check_attachment { my $attachment_path = shift; (my $filename = $attachment_path) =~ s/.*\/(.*)$/$1/; expect_send("comment -m 'attach file' -a $attachment_path $ticket_id", "Adding an attachment ($filename)"); - expect_like(qr/Message recorded/, "Added the attachment"); + expect_like(qr/Comments added/, "Added the attachment"); expect_send("show ticket/$ticket_id/attachments","Finding Attachment"); my $attachment_regex = qr/(\d+):\s+$filename/; expect_like($attachment_regex,"Attachment Uploaded"); @@ -525,7 +589,11 @@ sub check_attachment { TODO: { local $TODO = "Binary PNG content is getting mangled somewhere along the way" if $attachment_path =~ /\.png$/; - expect_is($attachment_content,"Attachment contains original text"); + is( + MIME::Base64::encode_base64(Test::Expect::before()), + MIME::Base64::encode_base64($attachment_content), + "Attachment contains original text" + ); } } @@ -534,4 +602,7 @@ sub check_attachment { my @warnings = grep { $_ !~ /\$ampm/ } $m->get_warnings; is( scalar @warnings, 0, 'no extra warnings' ); +undef $m; +done_testing; + 1; # needed to avoid a weird exit value from expect_quit