[Rt-commit] r2272 - in rtfm/branches/2.1-TESTING: . lib/RT/FM t

jesse at bestpractical.com jesse at bestpractical.com
Wed Mar 2 02:17:44 EST 2005


Author: jesse
Date: Wed Mar  2 02:17:43 2005
New Revision: 2272

Modified:
   rtfm/branches/2.1-TESTING/   (props changed)
   rtfm/branches/2.1-TESTING/lib/RT/FM/ArticleCollection_Overlay.pm
   rtfm/branches/2.1-TESTING/lib/RT/FM/Article_Overlay.pm
   rtfm/branches/2.1-TESTING/t/ArticleCollection_Overlay.pm.t
   rtfm/branches/2.1-TESTING/t/Class_Overlay.pm.t
Log:
 r6169 at hualien:  jesse | 2005-03-02 02:14:24 -0500
 All tests pass. need more tests


Modified: rtfm/branches/2.1-TESTING/lib/RT/FM/ArticleCollection_Overlay.pm
==============================================================================
--- rtfm/branches/2.1-TESTING/lib/RT/FM/ArticleCollection_Overlay.pm	(original)
+++ rtfm/branches/2.1-TESTING/lib/RT/FM/ArticleCollection_Overlay.pm	Wed Mar  2 02:17:43 2005
@@ -223,12 +223,8 @@
         @_
     );
 
-    #lets get all those values in an array. regardless of # of entries
-    #we'll use this for adding and deleting keywords from this object.
-    my @values =
-      ref( $args{'VALUE'} ) ? @{ $args{'VALUE'} } : ( $args{'VALUE'} );
 
-    foreach my $value (@values) {
+        my $value = $args{'VALUE'};
         next unless $value;    #strip out total blank wildcards
         my $ObjectValuesAlias = $self->Join(
             TYPE   => 'left',
@@ -237,26 +233,39 @@
             TABLE2 => 'ObjectCustomFieldValues',
             FIELD2 => 'ObjectId'
         );
-        $self->Limit( ALIAS=> $ObjectValuesAlias, FIELD => 'ObjectType', VALUE => 'RT::FM::Article');
 
         if ( $args{'FIELD'} ) {
+
+            my $field_id;
+
+            if (UNIVERSAL::isa($args{'FIELD'} ,'RT::CustomField')) {
+                    $field_id = $args{'FIELD'}->id;
+            } elsif($args{'FIELD'} =~ /^\d+$/) {
+                    $field_id = $args{'FIELD'};
+            }
+            if ($field_id) {
+            $self->Limit( LEFTJOIN           => $ObjectValuesAlias, FIELD           => 'CustomField', VALUE           => $args{'FIELD'}, ENTRYAGGREGATOR => 'OR');
+            # Could convert the above to a non-left join and also enable the thing below
+            #$self->SUPER::Limit( ALIAS           => $ObjectValuesAlias, FIELD           => 'CustomField', OPERATOR        => 'IS', VALUE           => 'NULL', QUOTEVALUE      => 0, ENTRYAGGREGATOR => 'OR',);
+        } else {
+            # Search for things by name if the cf was specced by name.
+            my $fields = $self->NewAlias('CustomFields');
+            $self->Join( TYPE => 'left',
+                        ALIAS1 => $ObjectValuesAlias , FIELD1 => 'CustomField',
+                          ALIAS2 => $fields, FIELD2=> 'id');
+            $self->Limit(ALIAS => $fields,
+                        FIELD => 'Name',
+                        VALUE => $args{'FIELD'},
+                        ENTRYAGGREGATOR  => 'OR');
             $self->Limit(
-                ALIAS           => $ObjectValuesAlias,
-                FIELD           => 'CustomField',
-                VALUE           => $args{'FIELD'},
-                ENTRYAGGREGATOR => 'OR'
+                ALIAS => $fields,
+                FIELD => 'LookupType',
+                VALUE =>
+                  RT::FM::Article->new($RT::SystemUser)->CustomFieldLookupType()
             );
 
-            $self->SUPER::Limit(
-                ALIAS           => $ObjectValuesAlias,
-                FIELD           => 'CustomField',
-                OPERATOR        => 'IS',
-                VALUE           => 'NULL',
-                QUOTEVALUE      => 0,
-                ENTRYAGGREGATOR => 'OR',
-            );
         }
-
+    }
       #If we're trying to find articles where a custom field value doesn't match
       # something, be sure to find  things where it's null
 
@@ -283,12 +292,12 @@
                 ENTRYAGGREGATOR => $args{'ENTRYAGGREGATOR'},
             );
             $self->SUPER::Limit(
-                ALIAS           => $ObjectValuesAlias,
+                ALIAS        => $ObjectValuesAlias,
                 FIELD           => 'Content',
                 OPERATOR        => 'IS',
                 VALUE           => 'NULL',
                 QUOTEVALUE      => 0,
-                ENTRYAGGREGATOR => 'OR',
+                ENTRYAGGREGATOR => 'AND',
             );
         }
         else {
@@ -301,7 +310,6 @@
                 ENTRYAGGREGATOR => $args{'ENTRYAGGREGATOR'},
             );
         }
-    }
 }
 
 # }}}

Modified: rtfm/branches/2.1-TESTING/lib/RT/FM/Article_Overlay.pm
==============================================================================
--- rtfm/branches/2.1-TESTING/lib/RT/FM/Article_Overlay.pm	(original)
+++ rtfm/branches/2.1-TESTING/lib/RT/FM/Article_Overlay.pm	Wed Mar  2 02:17:43 2005
@@ -94,7 +94,7 @@
 
             my ( $cfid, $cfmsg ) = $self->_AddCustomFieldValue(
                                                           Field   => $1,
-                                                          Content => $val,
+                                                          Value => $val,
                                                           RecordTransaction => 0
             );
 

Modified: rtfm/branches/2.1-TESTING/t/ArticleCollection_Overlay.pm.t
==============================================================================
--- rtfm/branches/2.1-TESTING/t/ArticleCollection_Overlay.pm.t	(original)
+++ rtfm/branches/2.1-TESTING/t/ArticleCollection_Overlay.pm.t	Wed Mar  2 02:17:43 2005
@@ -5,87 +5,135 @@
 RT::LoadConfig();
 RT::Init();
 
-use_ok( RT::FM::ArticleCollection);
-use_ok( RT::FM::ClassCollection);
+use_ok(RT::FM::ArticleCollection);
+use_ok(RT::FM::ClassCollection);
 
 my $class = RT::FM::Class->new($RT::SystemUser);
-my ($id,$msg) = $class->Create(Name => 'CollectionTest-'.$$);
+my ( $id, $msg ) = $class->Create( Name => 'CollectionTest-' . $$ );
+ok( $id, $msg );
+
+# Add a custom field to our class
+use_ok('RT::CustomField');
+my $cf = RT::CustomField->new($RT::SystemUser);
+isa_ok($cf, 'RT::CustomField');
+
+($id,$msg) = $cf->Create( Name => 'FM::Sample-'.$$,
+             Description => 'Test text cf',
+             LookupType => RT::FM::Article->CustomFieldLookupType,
+             Type => 'Freeform'
+             );
+
+
+
 ok($id,$msg);
 
+
+($id,$msg) = $cf->AddToObject($class);
+ok ($id,$msg);
+
+
+
 my $art = RT::FM::Article->new($RT::SystemUser);
-($id,$msg) = $art->Create( Class => $class->id,
-            Name => 'Collection-1-'.$$,
-             Summary => 'Coll-1-'.$$);
+( $id, $msg ) = $art->Create(
+    Class   => $class->id,
+    Name    => 'Collection-1-' . $$,
+    Summary => 'Coll-1-' . $$,
+    'CustomField-'.$cf->Name => 'Test-'.$$
+);
 
-ok($id,$msg);
+ok( $id, $msg );
 
-my $arts =RT::FM::ArticleCollection->new($RT::SystemUser);
-$arts->LimitName (VALUE => 'Collection-1-'.$$.'fake');
-is($arts->Count, 0, "Found no artlcles with names matching something that is not there");
 
-my $arts2 =RT::FM::ArticleCollection->new($RT::SystemUser);
-$arts2->LimitName (VALUE => 'Collection-1-'.$$);
-is($arts2->Count, 1, 'Found one with names matching the word "test"');
 
 
 
-my $arts =RT::FM::ArticleCollection->new($RT::SystemUser);
-$arts->LimitSummary (VALUE => 'Coll-1-'.$$.'fake');
-is($arts->Count, 0, 'Found no artlcles with summarys matching something that is not there');
 
-my $arts2 =RT::FM::ArticleCollection->new($RT::SystemUser);
-$arts2->LimitSummary (VALUE => 'Coll-1-'.$$);
-is($arts2->Count, 1, 'Found one with summarys matching the word "Coll-1"');
+my $arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitName( VALUE => 'Collection-1-' . $$ . 'fake' );
+is( $arts->Count, 0,
+    "Found no artlcles with names matching something that is not there" );
 
+my $arts2 = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts2->LimitName( VALUE => 'Collection-1-' . $$ );
+is( $arts2->Count, 1, 'Found one with names matching the word "test"' );
 
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitSummary( VALUE => 'Coll-1-' . $$ . 'fake' );
+is( $arts->Count, 0,
+    'Found no artlcles with summarys matching something that is not there' );
 
-my $new_art = RT::FM::Article->new($RT::SystemUser);
-($id,$msg) = $new_art->Create (Class => $class->id,
-                  Name => 'CFSearchTest1'.$$,
-                  CustomField-1 => 'testing'.$$ );
-
-
-ok( $id,$msg . " Created a testable article");
-
- $arts = RT::FM::ArticleCollection->new($RT::SystemUser);
-ok($arts->isa('RT::FM::ArticleCollection'), "Got an article collection");
-$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => 'est');
-is ($arts->Count ,1, "Found 1 cf values matching 'est'");
-
- $arts = RT::FM::ArticleCollection->new($RT::SystemUser);
-ok($arts->isa('RT::FM::ArticleCollection'), "Got an article collection");
-$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => 'est', FIELD => '1');
-is ($arts->Count, 1, "Found 1 cf values matching 'est' for CF1 ");
-
-
- $arts = RT::FM::ArticleCollection->new($RT::SystemUser);
-ok($arts->isa('RT::FM::ArticleCollection'), "Got an article collection");
-$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => 'est', FIELD => '6');
-ok ($arts->Count == '0', "Found no cf values matching 'est' for CF 6  ");
-
- $arts = RT::FM::ArticleCollection->new($RT::SystemUser);
-ok($arts->isa('RT::FM::ArticleCollection'), "Got an article collection");
-$arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'blah', FIELD => '1');
-ok ($arts->Count == 7, "Found 7 articles with custom field values not matching blah-"  . $arts->Count);
-
- $arts = RT::FM::ArticleCollection->new($RT::SystemUser);
-ok($arts->isa('RT::FM::ArticleCollection'), "Got an article collection");
-$arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'est', FIELD => '1');
-ok ($arts->Count == 6, "Found 6 cf values matching 'est' for CF 6  -"  . $arts->Count);
+$arts2 = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts2->LimitSummary( VALUE => 'Coll-1-' . $$ );
+is( $arts2->Count, 1, 'Found one with summarys matching the word "Coll-1"' );
 
+my $new_art = RT::FM::Article->new($RT::SystemUser);
+( $id, $msg ) = $new_art->Create(
+    Class          => $class->id,
+    Name           => 'CFSearchTest1' . $$,
+    'CustomField-'.$cf->Name  => 'testing' . $$
+);
+
+ok( $id, $msg . " Created a second testable article" );
+
+
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => "esting".$$ );
+is( $arts->Count, 1, "Found 1 cf values matching 'esting" . $$ . "' for an unspecified field");
+
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitCustomField( OPERATOR => '=', VALUE => "esting".$$ );
+is( $arts->Count, 0, "Found 0 cf values EXACTLY matching 'esting" . $$ . "' for an unspecified field");
+
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitCustomField( OPERATOR => '=', VALUE => "testing".$$ );
+is( $arts->Count, 1, "Found 0 cf values EXACTLY matching 'testing" . $$ . "' for an unspecified field");
+
+
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$ );
+is( $arts->Count, 2, "Found 1 cf values matching '" . $$ . "' for an unspecified field");
+
+
+# Test searching on named custom fields
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$, FIELD => $cf->Name );
+is( $arts->Count, 2, "Found 1 Article with cf values matching '".$$."' for CF named " .$cf->Name);
+
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$, FIELD => 'NO-SUCH-CF' );
+is( $arts->Count,0, "Found no cf values matching '".$$."' for CF 'NO-SUCH-CF'  " );
+
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->Limit(FIELD =>'Class', VALUE => $class->id);
+        
+$arts->LimitCustomField(
+    OPERATOR => 'NOT LIKE',
+    VALUE    => 'blah',
+    FIELD    => $cf->id
+);
+is(
+    $arts->Count ,2,
+    "Found 1 articles with custom field values not matching blah");
+
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->Limit(FIELD =>'Class', VALUE => $class->id);
+$arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'est', FIELD => $cf->id );
+is( $arts->Count , 0, "Found 0 cf values not matching 'est' for CF  ".$cf->id);
+
+
+$arts = RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->Limit(FIELD =>'Class', VALUE => $class->id);
+$arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'BOGUS', FIELD => $cf->id );
+is( $arts->Count , 2, "Found 2 articles not matching 'BOGUS' for CF  ".$cf->id);
 
 my $ac = RT::FM::ArticleCollection->new($RT::SystemUser);
-ok($ac->isa('RT::FM::ArticleCollection'));
-ok($ac->isa('RT::FM::SearchBuilder'));
-ok ($ac->isa('DBIx::SearchBuilder'));
-ok ($ac->LimitRefersTo('http://dead.link'));
-ok ($ac->Count == 0);
-
+ok( $ac->isa('RT::FM::ArticleCollection') );
+ok( $ac->isa('RT::FM::SearchBuilder') );
+ok( $ac->isa('DBIx::SearchBuilder') );
+ok( $ac->LimitRefersTo('http://dead.link') );
+ok( $ac->Count == 0 );
 
 $ac = RT::FM::ArticleCollection->new($RT::SystemUser);
-ok($ac->isa('RT::FM::ArticleCollection'));
-ok($ac->isa('RT::FM::SearchBuilder'));
-ok ($ac->isa('DBIx::SearchBuilder'));
-ok ($ac->LimitReferredToBy('http://dead.link'));
-ok ($ac->Count == 0);
+ok( $ac->LimitReferredToBy('http://dead.link') );
+ok( $ac->Count == 0 );
 

Modified: rtfm/branches/2.1-TESTING/t/Class_Overlay.pm.t
==============================================================================
--- rtfm/branches/2.1-TESTING/t/Class_Overlay.pm.t	(original)
+++ rtfm/branches/2.1-TESTING/t/Class_Overlay.pm.t	Wed Mar  2 02:17:43 2005
@@ -12,12 +12,12 @@
 my $cl = RT::FM::Class->new($root);
 ok (UNIVERSAL::isa($cl, 'RT::FM::Class'), "the new class is a class");
 
-my ($id, $msg) = $cl->Create(Name => 'Test', Description => 'A test class');
+my ($id, $msg) = $cl->Create(Name => 'Test-'.$$, Description => 'A test class');
 
 ok ($id, $msg);
 
 # no duplicate class names should be allowed
-($id, $msg) = $cl->Create(Name => 'Test', Description => 'A test class');
+($id, $msg) = $cl->Create(Name => 'Test-'.$$, Description => 'A test class');
 
 ok (!$id, $msg);
 
@@ -29,7 +29,7 @@
 
 
 
-$cl->Load('Test');
+$cl->Load('Test-'.$$);
 ok($cl->id, "Loaded the class we want");
 
 
@@ -44,10 +44,10 @@
 $cl = RT::FM::Class->new($u);
 ok (UNIVERSAL::isa($cl, 'RT::FM::Class'), "the new class is a class");
 
-($id, $msg) = $cl->Create(Name => 'Test-nobody', Description => 'A test class');
+($id, $msg) = $cl->Create(Name => 'Test-nobody'.$$, Description => 'A test class');
 
 ok (!$id, $msg. "- Can not create classes as a random new user - " .$u->Id);
 $u->PrincipalObj->GrantRight(Right =>'AdminClass', Object => $RT::FM::System);
-($id, $msg) = $cl->Create(Name => 'Test-nobody', Description => 'A test class');
+($id, $msg) = $cl->Create(Name => 'Test-nobody-'.$$, Description => 'A test class');
 
 ok ($id, $msg. "- Can create classes as a random new user after ACL grant");


More information about the Rt-commit mailing list