[Rt-commit] r5839 - in rt/branches/3.7-EXPERIMENTAL: . lib/t/regression

ruz at bestpractical.com ruz at bestpractical.com
Thu Aug 31 22:14:02 EDT 2006


Author: ruz
Date: Thu Aug 31 22:14:01 2006
New Revision: 5839

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm
   rt/branches/3.7-EXPERIMENTAL/lib/t/regression/01ticket_link_searching.t

Log:
 r3676 at cubic-pc:  cubic | 2006-09-01 03:07:26 +0400
 * implement "Linked = xxx" ticket SQL query
 * "Linked != xxx" dnd "Linked IS [NOT] NULL" don't work yet


Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm	Thu Aug 31 22:14:01 2006
@@ -419,7 +419,8 @@
     }
     else {
         my $linkalias = $sb->NewAlias('Links');
-        $sb->_OpenParen();
+        $sb->_OpenParen;
+
         $sb->_SQLLimit(
             @rest,
             ALIAS    => $linkalias,
@@ -427,22 +428,59 @@
             OPERATOR => '=',
             VALUE    => $meta->[2],
         ) if $meta->[2];
-        $sb->_SQLLimit(
-            ALIAS           => $linkalias,
-            FIELD           => 'Local' . $linkfield,
-            OPERATOR        => '=',
-            VALUE           => 'main.id',
-            QUOTEVALUE      => 0,
-            ENTRYAGGREGATOR => 'AND',
-        );
-        $sb->_SQLLimit(
-            ALIAS           => $linkalias,
-            FIELD           => $matchfield,
-            OPERATOR        => $op,
-            VALUE           => $value,
-            ENTRYAGGREGATOR => 'AND',
-        );
-        $sb->_CloseParen();
+
+        $sb->_OpenParen;
+        if ( $direction ) {
+            $sb->_SQLLimit(
+                ALIAS           => $linkalias,
+                FIELD           => 'Local' . $linkfield,
+                OPERATOR        => '=',
+                VALUE           => 'main.id',
+                QUOTEVALUE      => 0,
+                ENTRYAGGREGATOR => 'AND',
+            );
+            $sb->_SQLLimit(
+                ALIAS           => $linkalias,
+                FIELD           => $matchfield,
+                OPERATOR        => '=',
+                VALUE           => $value,
+                ENTRYAGGREGATOR => 'AND',
+            );
+        } else {
+            $sb->_OpenParen;
+            $sb->_SQLLimit(
+                ALIAS           => $linkalias,
+                FIELD           => 'LocalBase',
+                VALUE           => 'main.id',
+                QUOTEVALUE      => 0,
+                ENTRYAGGREGATOR => 'AND',
+            );
+            $sb->_SQLLimit(
+                ALIAS           => $linkalias,
+                FIELD           => $matchfield .'Target',
+                VALUE           => $value,
+                ENTRYAGGREGATOR => 'AND',
+            );
+            $sb->_CloseParen;
+
+            $sb->_OpenParen;
+            $sb->_SQLLimit(
+                ALIAS           => $linkalias,
+                FIELD           => 'LocalTarget',
+                VALUE           => 'main.id',
+                QUOTEVALUE      => 0,
+                ENTRYAGGREGATOR => 'OR',
+            );
+            $sb->_SQLLimit(
+                ALIAS           => $linkalias,
+                FIELD           => $matchfield .'Base',
+                VALUE           => $value,
+                ENTRYAGGREGATOR => 'AND',
+            );
+            $sb->_CloseParen;
+        }
+        $sb->_CloseParen;
+        $sb->_CloseParen;
     }
 }
 

Modified: rt/branches/3.7-EXPERIMENTAL/lib/t/regression/01ticket_link_searching.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/t/regression/01ticket_link_searching.t	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/t/regression/01ticket_link_searching.t	Thu Aug 31 22:14:01 2006
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-use Test::More tests => 53;
+use Test::More tests => 63;
 use strict;
 use RT;
 
@@ -164,6 +164,13 @@
 );
 ok($childid, "We created a grand child ticket");
 
+my $unlinked_ticket = new RT::Ticket( $CurrentUser );
+my ($unlinked_id) = $child_ticket->Create(
+    Subject => 'test unlinked',
+    Queue   => $queue->Id,
+);
+ok($unlinked_id, "We created a grand child ticket");
+
 $Collection = RT::Tickets->new($CurrentUser);
 $Collection->FromSQL( "LinkedTo = $childid" );
 is($Collection->Count,1, "We found only one result");
@@ -184,6 +191,7 @@
     ++$has{$t->id};
 }
 ok( $has{$parentid}, "parent is in collection");
+ok( $has{$unlinked_id}, "unlinked is in collection");
 ok( !$has{$childid}, "child is NOT in collection");
 ok( !$has{$grand_childid}, "grand child too is not in collection");
 
@@ -195,6 +203,7 @@
     ++$has{$t->id};
 }
 ok( !$has{$parentid}, "The collection has no our parent - $parentid");
+ok( !$has{$unlinked_id}, "unlinked is not in collection");
 ok( $has{$childid}, "The collection have our child - $childid");
 ok( $has{$grand_childid}, "The collection have our grand child - $grand_childid");
 
@@ -208,6 +217,7 @@
 ok( !$has{$parentid}, "parent is NOT in collection");
 ok( !$has{$childid}, "child is NOT in collection");
 ok( $has{$grand_childid}, "grand child is in collection");
+ok( $has{$unlinked_id}, "unlinked is in collection");
 
 $Collection = RT::Tickets->new($CurrentUser);
 $Collection->FromSQL( "LinkedFrom IS NOT NULL" );
@@ -219,5 +229,19 @@
 ok( $has{$parentid}, "The collection has our parent - $parentid");
 ok( $has{$childid}, "The collection have our child - $childid");
 ok( !$has{$grand_childid}, "The collection have no our grand child - $grand_childid");
+ok( !$has{$unlinked_id}, "unlinked is not in collection");
+
+$Collection = RT::Tickets->new($CurrentUser);
+$Collection->FromSQL( "Linked = $childid" );
+is($Collection->Count, 2, "We found two tickets: parent and child");
+%has = ();
+while (my $t = $Collection->Next) {
+    ++$has{$t->id};
+}
+ok( !$has{$childid}, "Ticket is not linked to itself");
+ok( $has{$parentid}, "The collection has our parent");
+ok( $has{$grand_childid}, "The collection have our child");
+ok( !$has{$unlinked_id}, "unlinked is not in collection");
+
 
 1;


More information about the Rt-commit mailing list