1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
49 package RT::Test::Web;
54 use base qw(Test::WWW::Mechanize);
62 if ( $url =~ s!^/!! ) {
63 $url = $self->rt_base_url . $url;
65 my $rv = $self->SUPER::get_ok($url, @_);
66 Test::More::diag( "Couldn't get $url" ) unless $rv;
71 return $RT::Test::existing_server if $RT::Test::existing_server;
72 return "http://localhost:" . RT->Config->Get('WebPort') . RT->Config->Get('WebPath') . "/";
77 my $user = shift || 'root';
78 my $pass = shift || 'password';
80 my $url = $self->rt_base_url;
83 Test::More::diag( "error: status is ". $self->status )
84 unless $self->status == 200;
85 if ( $self->content =~ qr/Logout/i ) {
86 $self->follow_link( text => 'Logout' );
89 $self->get($url . "?user=$user;pass=$pass");
90 unless ( $self->status == 200 ) {
91 Test::More::diag( "error: status is ". $self->status );
94 unless ( $self->content =~ qr/Logout/i ) {
95 Test::More::diag("error: page has no Logout");
104 unless ( $id && int $id ) {
105 Test::More::diag( "error: wrong id ". defined $id? $id : '(undef)' );
109 my $url = $self->rt_base_url;
110 $url .= "/Ticket/Display.html?id=$id";
112 unless ( $self->status == 200 ) {
113 Test::More::diag( "error: status is ". $self->status );
119 sub goto_create_ticket {
126 } elsif ( $queue =~ /^\d+$/ ) {
129 die "not yet implemented";
133 $self->form_name('CreateTicketInQueue');
134 $self->select( 'Queue', $id );
142 my $server_class = 'RT::Interface::Web::Standalone';
144 my $url = $server_class->test_warning_path;
146 local $Test::Builder::Level = $Test::Builder::Level + 1;
147 return unless $self->get_ok($url);
149 my @warnings = $server_class->decode_warnings($self->content);
158 local $Test::Builder::Level = $Test::Builder::Level + 1;
160 my @warnings = $self->get_warnings;
161 if (@warnings == 0) {
162 Test::More::fail("no warnings emitted; expected 1");
165 elsif (@warnings > 1) {
166 Test::More::fail(scalar(@warnings) . " warnings emitted; expected 1");
168 Test::More::diag("got warning: $_");
173 return Test::More::like($warnings[0], $re, $name);
178 my $name = shift || "no warnings emitted";
180 local $Test::Builder::Level = $Test::Builder::Level + 1;
182 my @warnings = $self->get_warnings;
184 Test::More::is(@warnings, 0, $name);
186 Test::More::diag("got warning: $_");
189 return @warnings == 0 ? 1 : 0;