[Rt-commit] r8488 - in rtir/branches/2.3-EXPERIMENTAL: . html/RTIR html/RTIR/Incident/Elements

ruz at bestpractical.com ruz at bestpractical.com
Thu Aug 9 22:51:05 EDT 2007


Author: ruz
Date: Thu Aug  9 22:51:05 2007
New Revision: 8488

Added:
   rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-reject.t
Modified:
   rtir/branches/2.3-EXPERIMENTAL/META.yml
   rtir/branches/2.3-EXPERIMENTAL/Makefile.PL
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Create.html
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Incident/Elements/Create
   rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t
   rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-no.t

Log:
* tests + implementation + fixes

Modified: rtir/branches/2.3-EXPERIMENTAL/META.yml
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/META.yml	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/META.yml	Thu Aug  9 22:51:05 2007
@@ -27,4 +27,5 @@
   RT::FM: 0
   Regexp::Common: 0
   Regexp::Common::net::CIDR: 0
+tests: t/*.t t/*/*.t
 version: 2.3.4

Modified: rtir/branches/2.3-EXPERIMENTAL/Makefile.PL
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/Makefile.PL	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/Makefile.PL	Thu Aug  9 22:51:05 2007
@@ -49,4 +49,6 @@
     'etc/add_constituency',
 );
 
+tests("t/*.t t/*/*.t");
+
 WriteAll();

Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Create.html
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Create.html	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Create.html	Thu Aug  9 22:51:05 2007
@@ -157,6 +157,7 @@
 % #TODO: hacks, we need way to define CF value on Create, but don't allow user to change it
 %   my $cf = RT::CustomField->new( $RT::SystemUser );
 %   $cf->LoadByNameAndQueue( Name => '_RTIR_Constituency', Queue => $Queue );
+      <input type="hidden" class="hidden" name="Constituency" value="Object-RT::Ticket--CustomField-<% $cf->id %>-Values" />
       <input type="hidden" class="hidden" name="Object-RT::Ticket--CustomField-<% $cf->id %>-Values-Magic" value="1" />
       <input type="hidden" class="hidden" name="Object-RT::Ticket--CustomField-<% $cf->id %>-Values" value="<% $IncidentObj->FirstCustomFieldValue('_RTIR_Constituency') %>" />
       <& /RTIR/Elements/ShowRTIRField, Ticket => $IncidentObj, Name => 'Constituency' &>
@@ -371,20 +372,28 @@
     unless ( $IncidentObj->id ) {
         push @results, loc("Couldn't load incident #[_1]", $Incident );
         ($checks_failure, $IncidentObj, $Incident) = (1, undef, undef);
-    } elsif ( $IncidentObj->QueueObj->Name ne 'Incidents' ) {
+    }
+    elsif ( $IncidentObj->QueueObj->Name ne 'Incidents' ) {
         push @results, loc('Ticket #[_1] is not an Incident', $Incident );
         ($checks_failure, $IncidentObj, $Incident) = (1, undef, undef);
-    } else {
-        $Incident = $ARGS{'Incident'} = $IncidentObj->id;
+    }
+    elsif ( RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject'
+        && $ARGS{$ARGS{'Constituency'}} ne $IncidentObj->FirstCustomFieldValue('_RTIR_Constituency') )
+    {
+        push @results, loc('Incident #[_1] has constituency [_1], choose the same value for a new ticket or use another Incident', $Incident, $IncidentObj->FirstCustomFieldValue('_RTIR_Constituency') );
+        $checks_failure = 1;
+    }
+    else {
         $Subject ||= $IncidentObj->Subject;
     }
 }
+$Incident = $ARGS{'Incident'} = $IncidentObj->id if $IncidentObj;
 
 my $parentvalue = '';
 if ( $IncidentObj ) {
     $parentvalue = $IncidentObj->Id;
 } elsif ( $TicketObj ) {
-    my $incidents = new RT::Tickets( $session{'CurrentUser'} );
+    my $incidents = RT::Ticketsi->new( $session{'CurrentUser'} );
     $incidents->FromSQL( "Queue = 'Incidents' AND HasMember = " . $TicketObj->Id );
     while ( my $incident = $incidents->Next ) {
         $parentvalue .= ' ' if $parentvalue;

Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Incident/Elements/Create
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Incident/Elements/Create	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Incident/Elements/Create	Thu Aug  9 22:51:05 2007
@@ -53,6 +53,7 @@
 % #TODO: hacks, we need way to define CF value on Create, but don't allow user to change it
 % my $cf = RT::CustomField->new( $RT::SystemUser );
 % $cf->LoadByNameAndQueue( Name => '_RTIR_Constituency', Queue => 'Incidents' );
+<input type="hidden" class="hidden" name="Constituency" value="Object-RT::Ticket--CustomField-<% $cf->id %>-Values" />
 <input type="hidden" class="hidden" name="Object-RT::Ticket--CustomField-<% $cf->id %>-Values-Magic" value="1" />
 <input type="hidden" class="hidden" name="Object-RT::Ticket--CustomField-<% $cf->id %>-Values" value="<% $ChildObj->FirstCustomFieldValue('_RTIR_Constituency') %>" />
 <& /RTIR/Elements/ShowRTIRField, Ticket => $ChildObj, Name => 'Constituency' &>

Modified: rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t	Thu Aug  9 22:51:05 2007
@@ -69,7 +69,8 @@
     # click [new] near 'incident', set another constituency and create
     $agent->follow_link_ok({text => '[New]'}, "go to 'New Incident' page");
     $agent->form_number(3);
-    ok(!eval{ set_custom_field( $agent, Constituency => 'EDUNET' ) }, "couldn't change value in the form");
+    my $form = $agent->form_number(3);
+    ok $form->find_input( $form->value('Constituency'), 'hidden'), 'constituency field is hidden';
     $agent->click('CreateIncident');
     is $agent->status, 200, "Attempted to create the ticket";
 

Modified: rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-no.t
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-no.t	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-no.t	Thu Aug  9 22:51:05 2007
@@ -9,7 +9,7 @@
 # XXX: we should use new RT::Test features and start server with
 # option we want.
 if ( RT->Config->Get('_RTIR_Constituency_Propagation') eq 'no' ) {
-    plan tests => 178;
+    plan tests => 109;
 } else {
     plan skip_all => 'constituency propagation algorithm is not "no"';
 }

Added: rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-reject.t
==============================================================================
--- (empty file)
+++ rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-reject.t	Thu Aug  9 22:51:05 2007
@@ -0,0 +1,180 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+require "t/rtir-test.pl";
+
+# XXX: we should use new RT::Test features and start server with
+# option we want.
+if ( RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject' ) {
+    plan tests => 105;
+} else {
+    plan skip_all => 'constituency propagation algorithm is not "reject"';
+}
+
+use_ok('RT::IR');
+
+my $cf;
+diag "load the field" if $ENV{'TEST_VERBOSE'};
+{
+    my $cfs = RT::CustomFields->new( $RT::SystemUser );
+    $cfs->Limit( FIELD => 'Name', VALUE => '_RTIR_Constituency' );
+    $cf = $cfs->First;
+    ok $cf, 'have a field';
+    ok $cf->id, 'with some ID';
+}
+
+my $agent = default_agent();
+my $rtir_user = rtir_user();
+
+diag "create an IR with GOVNET constituency and create a new "
+    . "incident for the IR, we want it to inherit by default"
+        if $ENV{'TEST_VERBOSE'};
+{
+    my $ir_id = create_ir(
+        $agent, { Subject => "test" }, { Constituency => 'GOVNET' }
+    );
+    ok $ir_id, "created IR #$ir_id";
+    display_ticket($agent, $ir_id);
+
+    my $inc_id = create_incident_for_ir(
+        $agent, $ir_id, { Subject => "test" },
+    );
+
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $inc_id );
+    ok $ticket->id, 'loaded ticket';
+    is uc $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+        'GOVNET', 'correct value';
+}
+
+diag "create an IR and check that we couldn't change constituency"
+    ." value during creation of new linked incident" if $ENV{'TEST_VERBOSE'};
+{
+    # create an IR
+    my $ir_id = create_ir(
+        $agent, { Subject => "test" }, { Constituency => 'GOVNET' }
+    );
+    ok $ir_id, "created ticket #$ir_id";
+    display_ticket($agent, $ir_id);
+    $agent->content_like( qr/GOVNET/, "value on the page" );
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $ir_id );
+    ok $ticket->id, 'loaded ticket';
+    is $ticket->QueueObj->Name, 'Incident Reports', 'correct value';
+    is $ticket->FirstCustomFieldValue('_RTIR_Constituency'), 'GOVNET', 'correct value';
+
+    # click [new] near 'incident', set another constituency and create
+    $agent->follow_link_ok({text => '[New]'}, "go to 'New Incident' page");
+    my $form = $agent->form_number(3);
+    ok $form->find_input( $form->value('Constituency'), 'hidden'), 'constituency field is hidden';
+    $agent->click('CreateIncident');
+    is $agent->status, 200, "Attempted to create the ticket";
+
+    DBIx::SearchBuilder::Record::Cachable::FlushCache();
+
+    # Incident has the same value 
+    my $inc_id = get_ticket_id( $agent );
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $inc_id );
+    ok $ticket->id, 'loaded ticket';
+    is $ticket->QueueObj->Name, 'Incidents', 'correct value';
+    is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+        'GOVNET', 'correct value';
+
+    # And the report too
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $ir_id );
+    ok $ticket->id, 'loaded ticket';
+    is $ticket->QueueObj->Name, 'Incident Reports', 'correct value';
+    is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+        'GOVNET', 'correct value';
+}
+
+diag "create an incident with EDUNET, then try to create children using"
+    ." Incident input field and different constituency. Should be rejected."
+        if $ENV{'TEST_VERBOSE'};
+{
+    my $incident_id = create_rtir_ticket_ok(
+        $agent, 'Incidents',
+        { Subject => "test" },
+        { Constituency => 'EDUNET' },
+    );
+    {
+        my $ticket = RT::Ticket->new( $RT::SystemUser );
+        $ticket->Load( $incident_id );
+        ok $ticket->id, 'loaded ticket';
+        is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+            'EDUNET', 'correct value';
+    }
+
+    foreach my $queue( 'Incident Reports', 'Investigations', 'Blocks' ) {
+        diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
+
+        my $id = create_rtir_ticket(
+            $agent, $queue,
+            {
+                Subject => "test ip",
+                Incident => $incident_id,
+            },
+            { Constituency => 'GOVNET' },
+        );
+        ok !$id, 'ticket was not created';
+        $agent->content_like(
+            qr/choose the same value for a new ticket or use another Incident/mi,
+            'creation rejected because of not matching constituency'
+        );
+    }
+}
+
+diag "create an incident with EDUNET and check that we can create children"
+    . " with the same constituency and operation is not rejected"
+        if $ENV{'TEST_VERBOSE'};
+{
+    my $incident_id = create_rtir_ticket_ok(
+        $agent, 'Incidents',
+        { Subject => "test" },
+        { Constituency => 'EDUNET' },
+    );
+    {
+        my $ticket = RT::Ticket->new( $RT::SystemUser );
+        $ticket->Load( $incident_id );
+        ok $ticket->id, 'loaded ticket';
+        is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+            'EDUNET', 'correct value';
+    }
+
+    foreach my $queue( 'Incident Reports', 'Investigations', 'Blocks' ) {
+        diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
+
+        my $id = create_rtir_ticket_ok(
+            $agent, $queue,
+            {
+                Subject => "test ip",
+                Incident => $incident_id,
+            },
+            { Constituency => 'EDUNET' },
+        );
+
+        display_ticket($agent, $id);
+        DBIx::SearchBuilder::Record::Cachable::FlushCache();
+        
+        {
+            my $ticket = RT::Ticket->new( $RT::SystemUser );
+            $ticket->Load( $id );
+            ok $ticket->id, 'loaded ticket';
+            is uc $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+                'EDUNET', 'correct value';
+        } {
+            my $ticket = RT::Ticket->new( $RT::SystemUser );
+            $ticket->Load( $incident_id );
+            ok $ticket->id, 'loaded ticket';
+            is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+                'EDUNET', 'incident still has the same value';
+        }
+        ticket_is_linked_to_inc($agent, $id, $incident_id);
+    }
+}
+


More information about the Rt-commit mailing list