[Rt-commit] r7143 - in rt/branches/3.7-EXPERIMENTAL-TUNIS/lib: RT

clkao at bestpractical.com clkao at bestpractical.com
Mon Mar 5 07:05:27 EST 2007


Author: clkao
Date: Mon Mar  5 07:05:26 2007
New Revision: 7143

Added:
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm
Modified:
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/02basic_web.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/03web_compiliation_errors.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/06mailgateway.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/07-acl.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/07-rights_web.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/08web_cf_access.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/17custom_search.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/18custom_frontpage.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/21query-builder.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/23-web_attachments.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/26command_line.t
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/27-make_clicky.t

Log:
tests now run without starting rt instance.

Added: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm
==============================================================================
--- (empty file)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm	Mon Mar  5 07:05:26 2007
@@ -0,0 +1,42 @@
+package RT::Test;
+
+use Test::More;
+
+my $port;
+use File::Temp;
+my $config;
+
+BEGIN {
+    # TODO: allocate a port dynamically
+    $config = File::Temp->new;
+    $port = 11229;
+    print $config qq{
+Set( \$WebPort , $port);
+Set( \$WebBaseURL , "http://localhost:\$WebPort");
+1;
+};
+    close $config;
+    $ENV{RT_SITE_CONFIG} = $config;
+    use RT;
+    RT::LoadConfig;
+    if (RT->Config->Get('DevelMode')) { require Module::Refresh; }
+
+};
+RT::Init;
+
+use RT::Interface::Web::Standalone;
+use Test::HTTP::Server::Simple;
+use Test::WWW::Mechanize;
+
+unshift @RT::Interface::Web::Standalone::ISA, 'Test::HTTP::Server::Simple';
+
+my @server;
+
+sub started_ok {
+    my $s = RT::Interface::Web::Standalone->new($port);
+    push @server, $s;
+    return ($s->started_ok, Test::WWW::Mechanize->new);
+}
+
+
+1;

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/02basic_web.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/02basic_web.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/02basic_web.t	Mon Mar  5 07:05:26 2007
@@ -1,22 +1,20 @@
 #!/usr/bin/perl
 
 use strict;
-use Test::More tests => 19;
-use WWW::Mechanize;
+use Test::More tests => 20;
 use HTTP::Request::Common;
 use HTTP::Cookies;
 use LWP;
 use Encode;
 
 my $cookie_jar = HTTP::Cookies->new;
-my $agent = WWW::Mechanize->new();
+use RT::Test;
+my ($baseurl, $agent) = RT::Test->started_ok;
 
 # give the agent a place to stash the cookies
 
 $agent->cookie_jar($cookie_jar);
 
-use RT;
-RT::LoadConfig();
 # get the top page
 my $url = RT->Config->Get('WebURL');
 diag $url;

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/03web_compiliation_errors.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/03web_compiliation_errors.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/03web_compiliation_errors.t	Mon Mar  5 07:05:26 2007
@@ -2,21 +2,19 @@
 
 use strict;
 use Test::More qw/no_plan/;
-use WWW::Mechanize;
 use HTTP::Request::Common;
 use HTTP::Cookies;
 use LWP;
 use Encode;
 
 my $cookie_jar = HTTP::Cookies->new;
-my $agent = WWW::Mechanize->new();
+
+use RT::Test;
+my ($baseurl, $agent) = RT::Test->started_ok;
 
 # give the agent a place to stash the cookies
 $agent->cookie_jar($cookie_jar);
 
-use RT;
-RT::LoadConfig();
-
 # get the top page
 my $url = RT->Config->Get('WebURL');
 diag "Base URL is '$url'" if $ENV{TEST_VERBOSE};

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/06mailgateway.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/06mailgateway.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/06mailgateway.t	Mon Mar  5 07:05:26 2007
@@ -54,11 +54,11 @@
 use strict;
 use warnings;
 
-use Test::More tests => 100;
+use Test::More tests => 101;
+
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
 
-use RT;
-RT::LoadConfig();
-RT::Init();
 use RT::Tickets;
 
 use MIME::Entity;

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/07-acl.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/07-acl.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/07-acl.t	Mon Mar  5 07:05:26 2007
@@ -1,12 +1,10 @@
 #!/usr/bin/perl -w
 use strict;
-use WWW::Mechanize;
 use HTTP::Cookies;
 
-use Test::More tests => 34;
-use RT;
-RT::LoadConfig();
-RT::Init();
+use Test::More tests => 35;
+use RT::Test;
+my ($baseurl, $agent) = RT::Test->started_ok;
 
 # Create a user with basically no rights, to start.
 my $user_obj = RT::User->new($RT::SystemUser);
@@ -22,7 +20,6 @@
 
 
 my $cookie_jar = HTTP::Cookies->new;
-my $agent = WWW::Mechanize->new();
 
 # give the agent a place to stash the cookies
 

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/07-rights_web.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/07-rights_web.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/07-rights_web.t	Mon Mar  5 07:05:26 2007
@@ -2,17 +2,10 @@
 use strict;
 
 use Test::More tests => 12;
-BEGIN {
-    use RT;
-    RT::LoadConfig;
-    RT::Init;
-}
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
 use constant BaseURL => "http://localhost:".RT->Config->Get('WebPort').RT->Config->Get('WebPath')."/";
 
-use Test::WWW::Mechanize;
-my $m = Test::WWW::Mechanize->new;
-isa_ok($m, 'Test::WWW::Mechanize');
-
 $m->get( BaseURL."?user=root;pass=password" );
 $m->content_like(qr/Logout/, 'we did log in');
 $m->follow_link_ok({ text => 'Configuration' });

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/08web_cf_access.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/08web_cf_access.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/08web_cf_access.t	Mon Mar  5 07:05:26 2007
@@ -2,12 +2,8 @@
 use strict;
 
 use Test::More tests => 15;
-BEGIN {
-    use RT;
-    RT::LoadConfig;
-    RT::Init;
-}
-use Test::WWW::Mechanize;
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
 
 use constant BaseURL => RT->Config->Get('WebURL');
 use constant ImageFile => $RT::MasonComponentRoot .'/NoAuth/images/bplogo.gif';
@@ -17,9 +13,6 @@
     scalar <$fh>;
 };
 
-my $m = Test::WWW::Mechanize->new;
-isa_ok($m, 'Test::WWW::Mechanize');
-
 $m->get( BaseURL."?user=root;pass=password" );
 $m->content_like(qr/Logout/, 'we did log in');
 

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/17custom_search.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/17custom_search.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/17custom_search.t	Mon Mar  5 07:05:26 2007
@@ -2,12 +2,8 @@
 use strict;
 
 use Test::More tests => 10;
-BEGIN {
-    use RT;
-    RT::LoadConfig;
-    RT::Init;
-}
-use Test::WWW::Mechanize;
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
 
 use constant BaseURL => RT->Config->Get('WebURL');
 
@@ -18,9 +14,6 @@
 	   Owner => 'root', Requestor => 'customsearch at localhost');
 ok(my $id = $t->id, 'created ticket for custom search');
 
-my $m = Test::WWW::Mechanize->new ( autocheck => 1 );
-isa_ok($m, 'Test::WWW::Mechanize');
-
 $m->get( BaseURL."?user=root;pass=password" );
 $m->content_like(qr/Logout/, 'we did log in');
 

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/18custom_frontpage.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/18custom_frontpage.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/18custom_frontpage.t	Mon Mar  5 07:05:26 2007
@@ -2,12 +2,8 @@
 use strict;
 
 use Test::More tests => 7;
-BEGIN {
-    use RT;
-    RT::LoadConfig;
-    RT::Init;
-}
-use Test::WWW::Mechanize;
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
 
 use constant BaseURL => RT->Config->Get('WebURL');
 
@@ -22,9 +18,6 @@
 $user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch');
 $user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
 
-my $m = Test::WWW::Mechanize->new ( autocheck => 1 );
-isa_ok($m, 'Test::WWW::Mechanize');
-
 $m->get( BaseURL."?user=customer;pass=customer" );
 
 $m->content_like(qr/Logout/, 'we did log in');

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/21query-builder.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/21query-builder.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/21query-builder.t	Mon Mar  5 07:05:26 2007
@@ -1,24 +1,21 @@
 #!/usr/bin/perl
 
 use strict;
-use Test::More tests => 39;
-use Test::WWW::Mechanize;
+use Test::More tests => 40;
 use HTTP::Request::Common;
 use HTTP::Cookies;
 use LWP;
 use Encode;
+use RT::Test;
 
 my $cookie_jar = HTTP::Cookies->new;
-my $agent = Test::WWW::Mechanize->new();
+my ($baseurl, $agent) = RT::Test->started_ok;
+
 
 # give the agent a place to stash the cookies
 
 $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 );

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/23-web_attachments.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/23-web_attachments.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/23-web_attachments.t	Mon Mar  5 07:05:26 2007
@@ -2,10 +2,8 @@
 use strict;
 
 use Test::More tests => 15;
-use RT;
-RT::LoadConfig;
-RT::Init;
-use Test::WWW::Mechanize;
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
 
 $RT::WebURL ||= 0; # avoid stupid warning
 my $BaseURL = $RT::WebURL;
@@ -14,9 +12,6 @@
 
 my $queue_name = 'General';
 
-my $m = Test::WWW::Mechanize->new;
-isa_ok($m, 'Test::WWW::Mechanize');
-
 $m->get_ok( $BaseURL."?user=root;pass=password" );
 $m->content_like(qr/Logout/, 'we did log in');
 

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/26command_line.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/26command_line.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/26command_line.t	Mon Mar  5 07:05:26 2007
@@ -3,11 +3,9 @@
 use strict;
 use Test::Expect;
 #use Test::More qw/no_plan/;
-use Test::More tests => 148;
-
-use RT;
-RT::LoadConfig();
-RT::Init;
+use Test::More tests => 149;
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
 
 use RT::User;
 use RT::Queue;

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/27-make_clicky.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/27-make_clicky.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/t/regression/27-make_clicky.t	Mon Mar  5 07:05:26 2007
@@ -5,11 +5,6 @@
 
 use Test::More;
 
-BEGIN {
-    use RT;
-    RT::LoadConfig();
-    RT::Init();
-}
 
 my %clicky = map { $_ => 1 } grep $_, RT->Config->Get('Active_MakeClicky');
 if ( keys %clicky ) {
@@ -19,6 +14,9 @@
     plan skip_all => 'No active Make Clicky actions';
 }
 
+use RT::Test;
+my ($baseurl, $m) = RT::Test->started_ok;
+
 use_ok('MIME::Entity');
 
 my $CurrentUser = $RT::SystemUser;
@@ -47,10 +45,7 @@
 ok($id, "We created a ticket #$id");
 ok($ticket->Transactions->First->Content, "Has some content");
 
-use Test::WWW::Mechanize;
 use constant BaseURL => "http://localhost:".RT->Config->Get('WebPort').RT->Config->Get('WebPath')."/";
-my $m = Test::WWW::Mechanize->new;
-isa_ok($m, 'Test::WWW::Mechanize');
 
 $m->get_ok( BaseURL."?user=root;pass=password" );
 $m->content_like(qr/Logout/, 'we did log in');


More information about the Rt-commit mailing list