[Rt-commit] r4899 - in rtir/branches/1.9-EXPERIMENTAL: lib/t
glasser at bestpractical.com
glasser at bestpractical.com
Wed Mar 29 18:56:48 EST 2006
Author: glasser
Date: Wed Mar 29 18:56:47 2006
New Revision: 4899
Added:
rtir/branches/1.9-EXPERIMENTAL/t/
- copied from r3953, /rtir/branches/1.9-EXPERIMENTAL/lib/t/
Removed:
rtir/branches/1.9-EXPERIMENTAL/lib/t/
Modified:
rtir/branches/1.9-EXPERIMENTAL/t/02regression.t
Log:
Revive RTIR test suite.
Modified: rtir/branches/1.9-EXPERIMENTAL/t/02regression.t
==============================================================================
--- /rtir/branches/1.9-EXPERIMENTAL/lib/t/02regression.t (original)
+++ rtir/branches/1.9-EXPERIMENTAL/t/02regression.t Wed Mar 29 18:56:47 2006
@@ -1,21 +1,44 @@
#!/usr/bin/perl
-use Test::More qw(no_plan);
+# 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 WWW::Mechanize;
+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");
+
# set things up
-my $BASEURL = "http://localhost";
-my $agent = WWW::Mechanize->new();
+my $RTIR_TEST_USER = "rtir_test_user";
+my $RTIR_TEST_PASS = "rtir_test_pass";
+
+create_user();
+my $agent = Test::WWW::Mechanize->new();
+$agent->cookie_jar(HTTP::Cookies->new);
+
# Create a report
my $report = CreateReport(Subject => "foo", Content => "bar baz");
# Create a new Incident from that report
-NewIncidentFromChild(id => $report);
+my $first_incident_id = NewIncidentFromChild(id => $report);
# TODO: make sure subject and content come from Report
@@ -24,10 +47,10 @@
# TODO: make sure all fields are set properly in DB
# create a new incident
-my $incident = CreateIncident(Subject => "foo Incident", Content => "bar baz quux");
+my $second_incident_id = CreateIncident(Subject => "foo Incident", Content => "bar baz quux");
# link our report to that incident
-LinkChildToIncident(id => $report, incident => $incident);
+LinkChildToIncident(id => $report, incident => $second_incident_id);
# TODO: verify in DB that report has 1 parent, and the right parent
@@ -41,24 +64,24 @@
DisplayTicket($id);
# Select the "New" link from the Display page
- $agent->follow_link(text => "[New]", n => "1");
- is ($agent->status, 200, "Followed 'New (Incident)' link");
+ $agent->follow_link_ok({text => "[New]"}, "Followed 'New (Incident)' link");
$agent->form_number(2);
$agent->field("Subject", $subject) if $subject;
$agent->field("Content", $content) if $content;
- # TODO: this should not be hardcoded
- SetFunction("IncidentCoord");
-
- $agent->submit();
-
+ set_custom_field(Function => "IncidentCoord");
+
+ $agent->click("CreateIncident");
+
is ($agent->status, 200, "Attempting to create new incident linked to child $id");
ok ($agent->content =~ /.*Ticket (\d+) created in queue*/g, "Incident created from child $id.");
+ my $incident_id = $1;
- return;
+ diag("incident ID is $incident_id");
+ return $incident_id;
}
sub LinkChildToIncident {
@@ -70,19 +93,18 @@
DisplayTicket($id);
# Select the "Link" link from the Display page
- $agent->follow_link(text => "[Link]", n => "1");
- is ($agent->status, 200, "Followed 'Link(to Incident)' link");
+ $agent->follow_link_ok({text => "[Link]", n => "1"}, "Followed 'Link(to Incident)' link");
# TODO: Make sure desired incident appears on page
# Choose the incident and submit
$agent->form_number(2);
$agent->field("SelectedTicket", $incident);
- $agent->submit();
+ $agent->click("LinkChild");
is ($agent->status, 200, "Attempting to link child $id to Incident $incident");
- ok ($agent->content =~ /.*Ticket (\d+): Transaction Created.*/g, "Incident $incident linked successfully.");
+ ok ($agent->content =~ /Ticket $id: Link created/g, "Incident $incident linked successfully.");
return;
}
@@ -90,16 +112,13 @@
sub CreateReport {
my %args = ( @_ );
- $agent->get($BASEURL . "/RTIR/index.html");
- is ($agent->status, 200, "Loaded a page");
+ $agent->get_ok("$RT::WebURL/RTIR/index.html", "loaded front page");
LoginIfNecessary();
- $agent->follow_link(text => "Incident Reports", n => "1");
- is ($agent->status, 200, "Followed 'Incident Reports' link");
+ $agent->follow_link_ok({text => "Incident Reports", n => "1"}, "Followed 'Incident Reports' link");
- $agent->follow_link(text => "New Report", n => "1");
- is ($agent->status, 200, "Followed 'New Report' link");
+ $agent->follow_link_ok({text => "New Report", n => "1"}, "Followed 'New Report' link");
# set the form
$agent->form_number(2);
@@ -111,7 +130,7 @@
$agent->field("Content", $args{'Content'});
# Create it!
- $agent->submit();
+ $agent->click("Create");
is ($agent->status, 200, "Attempted to create the ticket");
@@ -122,7 +141,7 @@
$id = $1;
}
- ok ($id > 1, "Ticket $id created successfully.");
+ ok ($id > 0, "Ticket $id created successfully.");
return $id;
}
@@ -130,16 +149,13 @@
sub CreateIncident {
my %args = ( @_ );
- $agent->get($BASEURL . "/RTIR/index.html");
- is ($agent->status, 200, "Loaded a page");
+ $agent->get_ok("$RT::WebURL/RTIR/index.html", "Loaded home page");
LoginIfNecessary();
- $agent->follow_link(text => "Incidents", n => "1");
- is ($agent->status, 200, "Followed 'Incidents' link");
+ $agent->follow_link_ok({text => "Incidents", n => "1"}, "Followed 'Incidents' link");
- $agent->follow_link(text => "New Incident", n => "1");
- is ($agent->status, 200, "Followed 'New Incident' link");
+ $agent->follow_link_ok({text => "New Incident", n => "1"}, "Followed 'New Incident' link");
# set the form
$agent->form_number(2);
@@ -150,12 +166,10 @@
# set the content
$agent->field("Content", $args{'Content'});
- # TODO: this should not be hardcoded
- SetFunction("IncidentCoord");
+ set_custom_field(Function => "IncidentCoord");
# Create it!
- $agent->submit();
-
+ $agent->click("CreateIncident");
is ($agent->status, 200, "Attempted to create the Incident");
# Now see if we succeeded
@@ -169,51 +183,52 @@
return $id;
}
-
-sub SetReporterType {
- my $type = shift;
-
- $agent->field("CustomField-11-Values", $type);
-}
-
-sub SetHowReported {
- my $how = shift;
-
- $agent->field("CustomField-10-Values", $how);
+
+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 SetSLA {
- my $sla = shift;
+sub LoginIfNecessary {
- $agent->field("CustomField-7-Values", $sla);
-}
-
-sub SetConstituency {
- my $cons = shift;
-
- $agent->field("CustomField-2-Values", $cons);
+ 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 SetFunction {
- my $function = shift;
+sub DisplayTicket {
+ my $id = shift;
- $agent->field("CustomField-8-Values", $function);
+ $agent->get_ok("$RT::WebURL/RTIR/Display.html?id=$id", "Loaded Display page");
}
-sub LoginIfNecessary {
-
- if ($agent->title eq 'Login') {
- $agent->form_number(1);
- $agent->field("user", "root");
- $agent->field("pass", "password");
- $agent->submit_form(form_number => "1");
+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);
}
-
-}
-sub DisplayTicket {
- my $id = shift;
+ 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");
- $agent->get($BASEURL . "/RTIR/Display.html?id=$id");
- is ($agent->status, 200, "Loaded Display page");
+ $group_obj->AddMember($user_obj->Id);
+ ok($group_obj->HasMember($user_obj->PrincipalObj), "user is in the group");
}
More information about the Rt-commit
mailing list