+sub no_leftover_warnings_ok {
+ my $self = shift;
+
+ my $name = shift || "no leftover warnings";
+
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+ # we clear the warnings because we don't want to break later tests
+ # in case there *are* leftover warnings
+ my @warnings = splice @{ $self->{stashed_server_warnings} || [] };
+
+ Test::More::is(@warnings, 0, $name);
+ for (@warnings) {
+ Test::More::diag("leftover warning: $_");
+ }
+
+ return @warnings == 0 ? 1 : 0;
+}
+
+sub ticket_status {
+ my $self = shift;
+ my $id = shift;
+
+ $self->display_ticket( $id);
+ my ($got) = ($self->content =~ m{Status:\s*</td>\s*<td[^>]*?class="value"[^>]*?>\s*([\w ]+?)\s*</td>}ism);
+ unless ( $got ) {
+ Test::More::diag("Error: couldn't find status value on the page, may be regexp problem");
+ }
+ return $got;
+}
+
+sub ticket_status_is {
+ my $self = shift;
+ my $id = shift;
+ my $status = shift;
+ my $desc = shift || "Status of the ticket #$id is '$status'";
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ return Test::More::is($self->ticket_status( $id), $status, $desc);
+}
+
+sub get_ticket_id {
+ my $self = shift;
+ my $content = $self->content;
+ my $id = 0;
+ if ($content =~ /.*Ticket (\d+) created.*/g) {
+ $id = $1;
+ }
+ elsif ($content =~ /.*No permission to view newly created ticket #(\d+).*/g) {
+ Test::More::diag("\nNo permissions to view the ticket.\n") if($ENV{'TEST_VERBOSE'});
+ $id = $1;
+ }
+ return $id;
+}
+
+sub set_custom_field {
+ my $self = shift;
+ my $queue = shift;
+ my $cf_name = shift;
+ my $val = shift;
+
+ my $field_name = $self->custom_field_input( $queue, $cf_name )
+ or return 0;
+
+ $self->field($field_name, $val);
+ return 1;
+}
+
+sub custom_field_input {
+ my $self = shift;
+ my $queue = shift;
+ my $cf_name = shift;
+
+ my $cf_obj = RT::CustomField->new( $RT::SystemUser );
+ $cf_obj->LoadByName( Queue => $queue, Name => $cf_name );
+ unless ( $cf_obj->id ) {
+ Test::More::diag("Can not load custom field '$cf_name' in queue '$queue'");
+ return undef;
+ }
+ my $cf_id = $cf_obj->id;
+
+ my ($res) =
+ grep /^Object-RT::Ticket-\d*-CustomField-$cf_id-Values?$/,
+ map $_->name,
+ $self->current_form->inputs;
+ unless ( $res ) {
+ Test::More::diag("Can not find input for custom field '$cf_name' #$cf_id");
+ return undef;
+ }
+ return $res;
+}
+
+sub check_links {
+ my $self = shift;
+ my %args = @_;
+
+ my %has = map {$_ => 1} @{ $args{'has'} };
+ my %has_no = map {$_ => 1} @{ $args{'has_no'} };
+
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+ my @found;
+
+ my @links = $self->followable_links;
+ foreach my $text ( grep defined && length, map $_->text, @links ) {
+ push @found, $text if $has_no{ $text };
+ delete $has{ $text };
+ }
+ if ( @found || keys %has ) {
+ Test::More::ok( 0, "expected links" );
+ Test::More::diag( "didn't expect, but found: ". join ', ', map "'$_'", @found )
+ if @found;
+ Test::More::diag( "didn't find, but expected: ". join ', ', map "'$_'", keys %has )
+ if keys %has;
+ return 0;
+ }
+ return Test::More::ok( 1, "expected links" );
+}
+
+sub DESTROY {
+ my $self = shift;
+ if ( !$RT::Test::Web::DESTROY++ ) {
+ $self->no_warnings_ok;
+ }
+}
+
+END {
+ return unless $instance;
+ return if RT::Test->builder->{Original_Pid} != $$;
+ $instance->no_warnings_ok if !$RT::Test::Web::DESTROY++;
+}
+