[Rt-commit] r4906 - in rtir/branches/1.9-EXPERIMENTAL: t
glasser at bestpractical.com
glasser at bestpractical.com
Thu Mar 30 12:52:29 EST 2006
Author: glasser
Date: Thu Mar 30 12:52:27 2006
New Revision: 4906
Added:
rtir/branches/1.9-EXPERIMENTAL/t/000-rtir-test-setup.t
rtir/branches/1.9-EXPERIMENTAL/t/001-basic-RTIR.t
- copied, changed from r4899, /rtir/branches/1.9-EXPERIMENTAL/t/02regression.t
rtir/branches/1.9-EXPERIMENTAL/t/rtir-test.pl
Removed:
rtir/branches/1.9-EXPERIMENTAL/t/02regression.t
Modified:
rtir/branches/1.9-EXPERIMENTAL/Makefile.PL
Log:
beginning of refactored test suite
Modified: rtir/branches/1.9-EXPERIMENTAL/Makefile.PL
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/Makefile.PL (original)
+++ rtir/branches/1.9-EXPERIMENTAL/Makefile.PL Thu Mar 30 12:52:27 2006
@@ -12,7 +12,4 @@
requires('Net::Whois::RIPE');
&auto_install;
-# Test all of our sub-dist tests too
-tests('t/*.t t/*/t/*.t');
-
&WriteAll;
Added: rtir/branches/1.9-EXPERIMENTAL/t/000-rtir-test-setup.t
==============================================================================
--- (empty file)
+++ rtir/branches/1.9-EXPERIMENTAL/t/000-rtir-test-setup.t Thu Mar 30 12:52:27 2006
@@ -0,0 +1,9 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+require "t/rtir-test.pl";
+
+create_user();
Copied: rtir/branches/1.9-EXPERIMENTAL/t/001-basic-RTIR.t (from r4899, /rtir/branches/1.9-EXPERIMENTAL/t/02regression.t)
==============================================================================
--- /rtir/branches/1.9-EXPERIMENTAL/t/02regression.t (original)
+++ rtir/branches/1.9-EXPERIMENTAL/t/001-basic-RTIR.t Thu Mar 30 12:52:27 2006
@@ -1,38 +1,12 @@
#!/usr/bin/perl
-# RTHOME must be set to run this. Note that this runs on an
-# *INSTALLED* copy of RTIR, with a running server.
-
-use Test::More tests => 23;
-
use strict;
use warnings;
-use Test::WWW::Mechanize;
-use HTTP::Cookies;
-
-BEGIN {
- unless ($ENV{RTHOME}) {
- die "\n\nYou must set the RTHOME environment variable to the root of your RT install.\n\n";
- }
-}
-
-use lib "$ENV{RTHOME}/lib";
-use lib "$ENV{RTHOME}/local/lib";
-
-use RT;
-ok(RT::LoadConfig);
-ok(RT::Init, "Basic initialization and DB connectivity");
-
+use Test::More tests => 19;
-# set things up
-my $RTIR_TEST_USER = "rtir_test_user";
-my $RTIR_TEST_PASS = "rtir_test_pass";
+require "t/rtir-test.pl";
-create_user();
-
-
-my $agent = Test::WWW::Mechanize->new();
-$agent->cookie_jar(HTTP::Cookies->new);
+my $agent = default_agent();
# Create a report
my $report = CreateReport(Subject => "foo", Content => "bar baz");
@@ -61,7 +35,7 @@
my $subject = $args{'Subject'};
my $content = $args{'Content'};
- DisplayTicket($id);
+ display_ir($agent, $id);
# Select the "New" link from the Display page
$agent->follow_link_ok({text => "[New]"}, "Followed 'New (Incident)' link");
@@ -71,7 +45,7 @@
$agent->field("Subject", $subject) if $subject;
$agent->field("Content", $content) if $content;
- set_custom_field(Function => "IncidentCoord");
+ set_custom_field($agent, Function => "IncidentCoord");
$agent->click("CreateIncident");
@@ -90,7 +64,7 @@
my $id = $args{'id'};
my $incident = $args{'incident'};
- DisplayTicket($id);
+ display_ir($agent, $id);
# Select the "Link" link from the Display page
$agent->follow_link_ok({text => "[Link]", n => "1"}, "Followed 'Link(to Incident)' link");
@@ -112,10 +86,6 @@
sub CreateReport {
my %args = ( @_ );
- $agent->get_ok("$RT::WebURL/RTIR/index.html", "loaded front page");
-
- LoginIfNecessary();
-
$agent->follow_link_ok({text => "Incident Reports", n => "1"}, "Followed 'Incident Reports' link");
$agent->follow_link_ok({text => "New Report", n => "1"}, "Followed 'New Report' link");
@@ -149,10 +119,6 @@
sub CreateIncident {
my %args = ( @_ );
- $agent->get_ok("$RT::WebURL/RTIR/index.html", "Loaded home page");
-
- LoginIfNecessary();
-
$agent->follow_link_ok({text => "Incidents", n => "1"}, "Followed 'Incidents' link");
$agent->follow_link_ok({text => "New Incident", n => "1"}, "Followed 'New Incident' link");
@@ -166,7 +132,7 @@
# set the content
$agent->field("Content", $args{'Content'});
- set_custom_field(Function => "IncidentCoord");
+ set_custom_field($agent, Function => "IncidentCoord");
# Create it!
$agent->click("CreateIncident");
@@ -183,52 +149,3 @@
return $id;
}
-
-sub set_custom_field {
- my $cf_name = shift;
- my $val = shift;
-
- my $field_name = $agent->value($cf_name);
- diag("found $cf_name at $field_name");
- $agent->field($field_name, $val);
-}
-
-sub LoginIfNecessary {
-
- if ($agent->title eq 'Login') {
- diag("logging in");
- $agent->form_number(1);
- $agent->field("user", $RTIR_TEST_USER);
- $agent->field("pass", $RTIR_TEST_PASS);
- $agent->submit_form(form_number => "1");
- }
-}
-
-sub DisplayTicket {
- my $id = shift;
-
- $agent->get_ok("$RT::WebURL/RTIR/Display.html?id=$id", "Loaded Display page");
-}
-
-sub create_user {
- my $user_obj = RT::User->new($RT::SystemUser);
- $user_obj->Load($RTIR_TEST_USER);
- if ($user_obj->Id) {
- $user_obj->SetPassword($RTIR_TEST_PASS);
- } else {
- $user_obj->Create(Name => $RTIR_TEST_USER,
- Password => $RTIR_TEST_PASS,
- EmailAddress => "$RTIR_TEST_USER\@example.com",
- RealName => "$RTIR_TEST_USER Smith",
- Privileged => 1);
- }
-
- ok($user_obj->Id > 0, "Successfully found the user");
-
- my $group_obj = RT::Group->new($RT::SystemUser);
- $group_obj->LoadUserDefinedGroup("DutyTeam");
- ok($group_obj->Id > 0, "Successfully found the DutyTeam group");
-
- $group_obj->AddMember($user_obj->Id);
- ok($group_obj->HasMember($user_obj->PrincipalObj), "user is in the group");
-}
Added: rtir/branches/1.9-EXPERIMENTAL/t/rtir-test.pl
==============================================================================
--- (empty file)
+++ rtir/branches/1.9-EXPERIMENTAL/t/rtir-test.pl Thu Mar 30 12:52:27 2006
@@ -0,0 +1,98 @@
+#!/usr/bin/perl
+
+# Load this in test scripts with: require "t/rtir-test.pl";
+# *AFTER* loading in Test::More.
+
+# RTHOME must be set to run this. Note that this runs on an
+# *INSTALLED* copy of RTIR, with a running server.
+
+use strict;
+use warnings;
+
+use Test::WWW::Mechanize;
+use HTTP::Cookies;
+
+BEGIN {
+ unless ($ENV{RTHOME}) {
+ die "\n\nYou must set the RTHOME environment variable to the root of your RT install.\n\n";
+ }
+}
+
+use lib "$ENV{RTHOME}/lib";
+use lib "$ENV{RTHOME}/local/lib";
+
+use RT;
+ok(RT::LoadConfig);
+ok(RT::Init, "Basic initialization and DB connectivity");
+
+my $RTIR_TEST_USER = "rtir_test_user";
+my $RTIR_TEST_PASS = "rtir_test_pass";
+
+
+sub default_agent {
+ my $agent = Test::WWW::Mechanize->new();
+ $agent->cookie_jar(HTTP::Cookies->new);
+
+ go_home($agent);
+ log_in($agent);
+ return $agent;
+}
+
+sub set_custom_field {
+ my $agent = shift;
+ my $cf_name = shift;
+ my $val = shift;
+
+ my $field_name = $agent->value($cf_name);
+ diag("found $cf_name at $field_name");
+ $agent->field($field_name, $val);
+}
+
+sub go_home {
+ my $agent = shift;
+ $agent->get_ok("$RT::WebURL/RTIR/index.html", "Loaded home page");
+}
+
+sub log_in {
+ my $agent = shift;
+
+ if ($agent->title eq 'Login') {
+ diag("logging in");
+ $agent->form_number(1);
+ $agent->field("user", $RTIR_TEST_USER);
+ $agent->field("pass", $RTIR_TEST_PASS);
+ $agent->submit_form(form_number => "1");
+ }
+}
+
+sub display_ir {
+ my $agent = shift;
+ my $id = shift;
+
+ $agent->get_ok("$RT::WebURL/RTIR/Display.html?id=$id", "Loaded Display page");
+}
+
+sub create_user {
+ my $user_obj = RT::User->new($RT::SystemUser);
+ $user_obj->Load($RTIR_TEST_USER);
+ if ($user_obj->Id) {
+ $user_obj->SetPassword($RTIR_TEST_PASS);
+ } else {
+ $user_obj->Create(Name => $RTIR_TEST_USER,
+ Password => $RTIR_TEST_PASS,
+ EmailAddress => "$RTIR_TEST_USER\@example.com",
+ RealName => "$RTIR_TEST_USER Smith",
+ Privileged => 1);
+ }
+
+ ok($user_obj->Id > 0, "Successfully found the user");
+
+ my $group_obj = RT::Group->new($RT::SystemUser);
+ $group_obj->LoadUserDefinedGroup("DutyTeam");
+ ok($group_obj->Id > 0, "Successfully found the DutyTeam group");
+
+ $group_obj->AddMember($user_obj->Id);
+ ok($group_obj->HasMember($user_obj->PrincipalObj), "user is in the group");
+}
+
+1;
More information about the Rt-commit
mailing list