1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
6 # <sales@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';
82 my $url = $self->rt_base_url;
83 $self->get($url . "?user=$user;pass=$pass");
84 unless ( $self->status == 200 ) {
85 Test::More::diag( "error: status is ". $self->status );
88 unless ( $self->content =~ qr/Logout/i ) {
89 Test::More::diag("error: page has no Logout");
92 unless ( $self->content =~ m{<span>\Q$user\E</span>}i ) {
93 Test::More::diag("Page has no user name");
102 my $url = $self->rt_base_url;
104 Test::More::diag( "error: status is ". $self->status )
105 unless $self->status == 200;
107 if ( $self->content =~ qr/Logout/i ) {
108 $self->follow_link( text => 'Logout' );
109 Test::More::diag( "error: status is ". $self->status ." when tried to logout" )
110 unless $self->status == 200;
117 if ( $self->content =~ qr/Logout/i ) {
118 Test::More::diag( "error: couldn't logout" );
127 unless ( $id && int $id ) {
128 Test::More::diag( "error: wrong id ". defined $id? $id : '(undef)' );
132 my $url = $self->rt_base_url;
133 $url .= "/Ticket/Display.html?id=$id";
135 unless ( $self->status == 200 ) {
136 Test::More::diag( "error: status is ". $self->status );
142 sub goto_create_ticket {
149 } elsif ( $queue =~ /^\d+$/ ) {
152 die "not yet implemented";
156 $self->form_name('CreateTicketInQueue');
157 $self->select( 'Queue', $id );
165 my $server_class = 'RT::Interface::Web::Standalone';
167 my $url = $server_class->test_warning_path;
169 local $Test::Builder::Level = $Test::Builder::Level + 1;
170 return unless $self->get_ok($url);
172 my @warnings = $server_class->decode_warnings($self->content);
181 local $Test::Builder::Level = $Test::Builder::Level + 1;
183 my @warnings = $self->get_warnings;
184 if (@warnings == 0) {
185 Test::More::fail("no warnings emitted; expected 1");
188 elsif (@warnings > 1) {
189 Test::More::fail(scalar(@warnings) . " warnings emitted; expected 1");
191 Test::More::diag("got warning: $_");
196 return Test::More::like($warnings[0], $re, $name);
201 my $name = shift || "no warnings emitted";
203 local $Test::Builder::Level = $Test::Builder::Level + 1;
205 my @warnings = $self->get_warnings;
207 Test::More::is(@warnings, 0, $name);
209 Test::More::diag("got warning: $_");
212 return @warnings == 0 ? 1 : 0;