[Rt-commit] r2253 - in rtfm/branches/2.1-TESTING: . bin lib/RT/FM t
jesse at bestpractical.com
jesse at bestpractical.com
Wed Feb 23 04:00:16 EST 2005
Author: jesse
Date: Wed Feb 23 04:00:16 2005
New Revision: 2253
Added:
rtfm/branches/2.1-TESTING/t/ArticleCollection_Overlay.pm.t
rtfm/branches/2.1-TESTING/t/Article_Overlay.pm.t
rtfm/branches/2.1-TESTING/t/Class_Overlay.pm.t
rtfm/branches/2.1-TESTING/t/System.pm.t
Removed:
rtfm/branches/2.1-TESTING/bin/rtfm
rtfm/branches/2.1-TESTING/lib/RT/FM/CurrentUser.pm
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/lib/RT/FM/Class_Overlay.pm
rtfm/branches/2.1-TESTING/lib/RT/FM/System.pm
rtfm/branches/2.1-TESTING/t/00smoke.t
Log:
r5762 at hualien: jesse | 2005-02-23 03:57:39 -0500
Refactored testing infrastructure. now RTFM 2.1 fails 10% of its tests. Better than not running any. also, basic custom field api support works
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 Feb 23 04:00:16 2005
@@ -19,6 +19,7 @@
use strict;
package RT::FM::ArticleCollection;
+
no warnings qw/redefine/;
=head2 Next
@@ -82,18 +83,6 @@
Find all articles with Name fields which satisfy OPERATOR for VALUE
-=begin testing
-
-my $arts =RT::FM::ArticleCollection->new($RT::SystemUser);
-$arts->LimitName (VALUE => 'testing');
-is($arts->Count, 0, 'Found no artlcles with summaries matching the word "testing"');
-
-my $arts2 =RT::FM::ArticleCollection->new($RT::SystemUser);
-#$arts2->LimitName (VALUE => 'test');
-#is($arts2->Count, 3, 'Found 3 artlcles with summaries matching the word "test"');
-
-=end testing
-
=cut
sub LimitName {
@@ -115,18 +104,6 @@
Find all articles with summary fields which satisfy OPERATOR for VALUE
-=begin testing
-
-my $arts =RT::FM::ArticleCollection->new($RT::SystemUser);
-$arts->LimitSummary (VALUE => 'testing');
-is($arts->Count, 0, 'Found no artlcles with summaries matching the word "testing"');
-
-my $arts2 =RT::FM::ArticleCollection->new($RT::SystemUser);
-$arts2->LimitSummary (VALUE => 'test');
-is($arts2->Count, 3, 'Found 3 artlcles with summaries matching the word "test"');
-
-=end testing
-
=cut
sub LimitSummary {
@@ -219,9 +196,9 @@
}
# }}}
-# {{{ LimitToCustomFieldValue
+# {{{ LimitCustomField
-=item LimitToCustomFieldValue HASH
+=item LimitCustomField HASH
Limit the result set to articles which have or do not have the custom field
value listed, using a left join to catch things where no rows match.
@@ -232,51 +209,9 @@
OPERATOR ('=', 'LIKE', '!=', 'NOT LIKE')
VALUE ( a single scalar value or a list of possible values to be concatenated with ENTRYAGGREGATOR)
-=begin testing
-
-my $new_art = RT::FM::Article->new($RT::SystemUser);
-$new_art->Create (Class => 1,
- Name => 'CFSearchTest1',
- CustomField-1 => 'testing' );
-
-
-ok( $new_art->Id, " Created a testable article");
-
-my $arts = RT::FM::ArticleCollection->new($RT::SystemUser);
-ok($arts->isa('RT::FM::ArticleCollection'), "Got an article collection");
-$arts->LimitToCustomFieldValue( 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->LimitToCustomFieldValue( 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->LimitToCustomFieldValue( 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->LimitToCustomFieldValue( 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->LimitToCustomFieldValue( OPERATOR => 'NOT LIKE', VALUE => 'est', FIELD => '1');
-ok ($arts->Count == 6, "Found 6 cf values matching 'est' for CF 6 -" . $arts->Count);
-
-
-=end testing
-
-
=cut
-*LimitToCustomFieldValue = \&LimitCustomField;
-
sub LimitCustomField {
my $self = shift;
my %args = (
@@ -300,11 +235,12 @@
ALIAS1 => 'main',
FIELD1 => 'id',
TABLE2 => 'ObjectCustomFieldValues',
- FIELD2 => 'Article'
+ FIELD2 => 'ObjectId'
);
+ $self->Limit( ALIAS=> $ObjectValuesAlias, FIELD => 'ObjectType', VALUE => 'RT::FM::Article');
if ( $args{'FIELD'} ) {
- $self->SUPER::Limit(
+ $self->Limit(
ALIAS => $ObjectValuesAlias,
FIELD => 'CustomField',
VALUE => $args{'FIELD'},
@@ -405,20 +341,6 @@
Limit the result set to only articles which are referred to by the URI passed in.
-=begin testing
-
-use RT::FM::ArticleCollection;
-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);
-
-=end testing
-
-
-
=cut
sub LimitRefersTo {
@@ -449,20 +371,6 @@
Limit the result set to only articles which are referred to by the URI passed in.
-=begin testing
-
-use RT::FM::ArticleCollection;
-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->LimitReferredToBy('http://dead.link'));
-ok ($ac->Count == 0);
-
-=end testing
-
-
-
=cut
sub LimitReferredToBy {
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 Feb 23 04:00:16 2005
@@ -50,40 +50,6 @@
-=begin testing
-
-use_ok(RT::FM::Article);
-use_ok(RT::FM::Class);
-
-my $user = RT::CurrentUser->new('root');
-
-my $class = RT::FM::Class->new($user);
-
-
-my ($id, $msg) = $class->Create(Name =>'ArticleTest');
-ok ($id, $msg);
-
-
-
-my $article = RT::FM::Article->new($user);
-ok (UNIVERSAL::isa($article, 'RT::FM::Article'));
-ok (UNIVERSAL::isa($article, 'RT::FM::Record'));
-ok (UNIVERSAL::isa($article, 'RT::Record'));
-ok (UNIVERSAL::isa($article, 'DBIx::SearchBuilder::Record') , "It's a searchbuilder record!");
-
-
-($id, $msg) = $article->Create( Class => 'ArticleTest', Summary => "ArticleTest");
-ok ($id, $msg);
-$article->Load($id);
-is ($article->Summary, 'ArticleTest', "The summary is set correct");
-my $at = RT::FM::Article->new($RT::SystemUser);
-$at->Load($id);
-is ($at->id , $id);
-is ($at->Summary, $article->Summary);
-
-
-=end testing
-
=cut
@@ -213,35 +179,6 @@
Empty names are permitted.
-=begin testing
-
-my $a1 = RT::FM::Article->new($RT::SystemUser);
-my ($id, $msg) = $a1->Create(Class => 1, Name => 'ValidateNameTest');
-ok ($id, $msg);
-
-
-
-my $a2 = RT::FM::Article->new($RT::SystemUser);
-($id, $msg) = $a2->Create(Class => 1, Name => 'ValidateNameTest');
-ok (!$id, $msg);
-
-my $a3 = RT::FM::Article->new($RT::SystemUser);
-($id, $msg) = $a3->Create(Class => 1, Name => 'ValidateNameTest2');
-ok ($id, $msg);
-($id, $msg) =$a3->SetName('ValidateNameTest');
-
-ok (!$id, $msg);
-
-($id, $msg) =$a3->SetName('ValidateNametest2');
-
-ok ($id, $msg);
-
-
-
-
-=end testing
-
-
=cut
sub ValidateName {
@@ -273,28 +210,6 @@
Delete all its relationships
Delete this article.
-=begin testing
-
-my $newart = RT::FM::Article->new($RT::SystemUser);
-$newart->Create(Name => 'DeleteTest', Class => '1');
-my $id = $newart->Id;
-
-ok($id, "New article has an id");
-
-
-my $article = RT::FM::Article->new($RT::SystemUser);
-$article->Load($id);
-ok ($article->Id, "Found the article");
-my ($val, $msg) = $article->Delete();
-ok ($val, "Article Deleted: $msg");
-
-my $a2 = RT::FM::Article->new($RT::SystemUser);
-$a2->Load($id);
-ok (!$a2->Id, "Did not find the article");
-
-
-=end testing
-
=cut
sub Delete {
@@ -392,392 +307,45 @@
Takes a paramhash of Type and one of Base or Target. Adds that link to this tick
et.
-=begin testing
-
-=end testing
-
+=cut
-=cut
-sub AddLink {
+sub DeleteLink {
my $self = shift;
- my %args = ( Target => '',
- Base => '',
- Type => 'RefersTo',
- RecordTransaction => 1,
- @_ );
+ my %args = (
+ Target => '',
+ Base => '',
+ Type => '',
+ Silent => undef,
+ @_
+ );
unless ( $self->CurrentUserHasRight('ModifyArticle') ) {
return ( 0, $self->loc("Permission Denied") );
}
- my ( $link_type, $link_pointer );
-
- if ( $args{'Base'} and $args{'Target'} ) {
- $RT::Logger->debug(
- "$self tried to delete a link. both base and target were specified"
- );
- return ( 0, $self->loc("Can't specifiy both base and target") );
- }
- elsif ( $args{'Base'} ) {
- $args{'Target'} = $self->URI();
- $link_type = "ReferredToBy";
- $link_pointer = $args{'Base'};
- }
- elsif ( $args{'Target'} ) {
- $args{'Base'} = $self->URI();
- $link_type = "RefersTo";
- $link_pointer = $args{'Target'};
- }
- else {
- return ( 0, $self->loc('Either base or target must be specified') );
- }
-
- # {{{ We don't want references to ourself
- if ( $args{'Base'} eq $args{'Target'} ) {
- $RT::Logger->debug(
- "Trying to link " . $args{'Base'} . " to " . $args{'Target'} );
- return ( 0, $self->loc("Can't link a ticket to itself") );
- }
-
- # }}}
-
- # If the base isn't a URI, make it a URI.
- # If the target isn't a URI, make it a URI.
-
- # {{{ Check if the link already exists - we don't want duplicates
- my $old_link = new RT::Link( $self->CurrentUser );
- $old_link->LoadByParams( Base => $args{'Base'},
- Type => $args{'Type'},
- Target => $args{'Target'} );
- if ( $old_link->Id ) {
- $RT::Logger->debug("$self Somebody tried to duplicate a link");
- return ( $old_link->id, $self->loc("Link already exists"), 0 );
- }
-
- # }}}
-
- # Storing the link in the DB.
- my $link = RT::Link->new( $self->CurrentUser );
- my ($linkid) = $link->Create( Target => $args{Target},
- Base => $args{Base},
- Type => $args{Type} );
-
- unless ($linkid) {
- return ( 0, $self->loc("Link could not be created") );
- }
-
- my $TransString = "$args{'Base'} $args{Type} $args{'Target'}";
-
- # Don't write the transaction if we're doing this on create
- if ( $args{'RecordTransaction'} ) {
-
- #Write the transaction
- my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
- Type => 'Link',
- Field => $link_type,
- NewContent => $link_pointer
- );
- return ( $Trans, $self->loc( "Link created ([_1])", $TransString ) );
- }
- else {
- return ( 1, $self->loc( "Link created ([_1])", $TransString ) );
- }
+ $self->_DeleteLink(%args);
}
-# }}}
-
-# {{{ Links
-
-=head2 Links
-
-The following routines deal with links and relationships between articles and
-RT tickets.
-
-
-=begin testing
-
-my ($id, $msg);
-
-$RT::Handle->SimpleQuery("DELETE FROM Links");
-
-my $article_a = RT::FM::Article->new($RT::SystemUser);
-($id, $msg) = $article_a->Create( Class => 'ArticleTest', Summary => "ArticleTestlink1");
-ok($id,$msg);
-
-my $article_b = RT::FM::Article->new($RT::SystemUser);
-($id, $msg) = $article_b->Create( Class => 'ArticleTest', Summary => "ArticleTestlink2");
-ok($id,$msg);
-
-# Create a link between two articles
-($id, $msg) = $article_a->AddLink( Type => 'RefersTo', Target => $article_b->URI);
-ok($id,$msg);
-
-# Make sure that Article B's "ReferredToBy" links object refers to to this article"
-my $refers_to_b = $article_b->ReferredToBy;
-ok($refers_to_b->Count == 1, "Found one thing referring to b");
-my $first = $refers_to_b->First;
-ok ($first->isa(RT::Link), "IT's an RT link - ref ".ref($first) );
-ok ($first->TargetObj->Id == $article_b->Id, "Its target is B");
-
-ok($refers_to_b->First->BaseObj->isa('RT::FM::Article'), "Yep. its an article");
-
-
-# Make sure that Article A's "RefersTo" links object refers to this article"
-my $referred_To_by_a = $article_a->RefersTo;
-ok($referred_To_by_a->Count == 1, "Found one thing referring to b ".$referred_To_by_a->Count. "-".$referred_To_by_a->First->id . " - ".$referred_To_by_a->Last->id);
-my $first = $referred_To_by_a->First;
-ok ($first->isa(RT::Link), "IT's an RT link - ref ".ref($first) );
-ok ($first->TargetObj->Id == $article_b->Id, "Its target is B - " . $first->TargetObj->Id);
-ok ($first->BaseObj->Id == $article_a->Id, "Its base is A");
-
-ok($referred_To_by_a->First->BaseObj->isa('RT::FM::Article'), "Yep. its an article");
-
-# Delete the link
-($id, $msg) = $article_a->DeleteLink(Type => 'RefersTo', Target => $article_b->URI);
-ok($id,$msg);
-
-
-# Create an Article A RefersTo Ticket 1 from the RTFM side
-use RT::Ticket;
-
-
-my $tick = RT::Ticket->new($RT::SystemUser);
-$tick->Create(Subject => "Article link test ", Queue => 'General');
-$tick->Load($tick->Id);
-ok ($tick->Id, "Found ticket ".$tick->id);
-($id, $msg) = $article_a->AddLink(Type => 'RefersTo', Target => $tick->URI);
-ok($id,$msg);
-
-# Find all tickets whhich refer to Article A
-
-use RT::Tickets;
-use RT::Links;
-
-my $tix = RT::Tickets->new($RT::SystemUser);
-ok ($tix, "Got an RT::Tickets object");
-ok ($tix->LimitReferredToBy($article_a->URI));
-ok ($tix->Count == 1, "Found one ticket linked to that article");
-ok ($tix->First->Id == $tick->id, "It's even the right one");
-
-
-
-# Find all articles which refer to Ticket 1
-use RT::FM::ArticleCollection;
-
-my $articles = RT::FM::ArticleCollection->new($RT::SystemUser);
-ok($articles->isa('RT::FM::ArticleCollection'), "Created an article collection");
-ok($articles->isa('RT::FM::SearchBuilder'), "Created an article collection");
-ok($articles->isa('RT::SearchBuilder'), "Created an article collection");
-ok($articles->isa('DBIx::SearchBuilder'), "Created an article collection");
-ok($tick->URI, "The ticket does still have a URI");
-$articles->LimitRefersTo($tick->URI);
-
-is($articles->Count(), 1);
-is ($articles->First->Id, $article_a->Id);
-is ($articles->First->URI, $article_a->URI);
-
-
-
-# Find all things which refer to ticket 1 using the RT API.
-
-my $tix2 = RT::Links->new($RT::SystemUser);
-ok ($tix2->isa('RT::Links'));
-ok($tix2->LimitRefersTo($tick->URI));
-ok ($tix2->Count == 1);
-is ($tix2->First->BaseObj->URI ,$article_a->URI);
-
-
-# Delete the link from the RT side.
-my $t2 = RT::Ticket->new($RT::SystemUser);
-$t2->Load($tick->Id);
-($id, $msg)= $t2->DeleteLink( Base => $article_a->URI, Type => 'RefersTo');
-ok ($id, $msg . " - $id - $msg");
-
-# it's actually deleted
-my $tix3 = RT::Links->new($RT::SystemUser);
-$tix3->LimitReferredToBy($tick->URI);
-ok ($tix3->Count == 0);
-
-# Recreate the link from teh RT site
-($id, $msg) = $t2->AddLink( Base => $article_a->URI, Type => 'RefersTo');
-ok ($id, $msg);
-
-# Find all tickets whhich refer to Article A
-
-# Find all articles which refer to Ticket 1
-
-
-=end testing
-
-
-
-=cut
-
-# {{{ sub DeleteLink
-
-=head2 DeleteLink
-
-Delete a link. takes a paramhash of Base, Target and Type.
-Either Base or Target must be null. The null value will
-be replaced with this ticket\'s id
-
-=cut
-
-sub DeleteLink {
+sub AddLink {
my $self = shift;
- my %args = ( Base => undef,
- Target => undef,
- Type => undef,
- @_ );
+ my %args = (
+ Target => '',
+ Base => '',
+ Type => '',
+ Silent => undef,
+ @_
+ );
- #check acls
unless ( $self->CurrentUserHasRight('ModifyArticle') ) {
- return ( 0, $self->loc('Permission Denied') );
- }
-
- #we want one of base and target. we don't care which
- #but we only want _one_
- my ( $link_type, $link_pointer );
- if ( $args{'Base'} and $args{'Target'} ) {
- $RT::Logger->debug("$self ->_DeleteLink. got both Base and Target\n");
- return ( 0, $self->loc("Can't specifiy both base and target") );
- }
- elsif ( $args{'Base'} ) {
- $args{'Target'} = $self->URI();
- $link_type = "ReferredToBy";
- $link_pointer = $args{'Base'};
- }
- elsif ( $args{'Target'} ) {
- $args{'Base'} = $self->URI();
- $link_type = "RefersTo";
- $link_pointer = $args{'Target'};
- }
- else {
- $RT::Logger->debug("$self: Base or Target must be specified\n");
- return ( 0, $self->loc('Either base or target must be specified') );
- }
-
- my $link = new RT::Link( $self->CurrentUser );
- $RT::Logger->debug( "Trying to load link: "
- . $args{'Base'} . " "
- . $args{'Type'} . " "
- . $args{'Target'}
- . "\n" );
- $link->LoadByParams( Base => $args{'Base'},
- Type => $args{'Type'},
- Target => $args{'Target'} );
-
- #it's a real link.
- if ( $link->id ) {
- my $linkid = $link->Id;
- $RT::Logger->debug( "We're going to delete link " . $link->id . "\n" );
- $link->Delete();
-
- my $TransString =
- "Ticket $args{'Base'} no longer $args{Type} ticket $args{'Target'}.";
- my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
- Type => 'Link',
- Field => $link_type,
- OldContent => $link_pointer
- );
-
- return ( $linkid,
- $self->loc( "Link deleted ([_1])",
- $args{'Base'} . " "
- . $args{'Type'} . " "
- . $args{'Target'} ) );
- }
-
- #if it's not a link we can find
- else {
- $RT::Logger->debug("Couldn't find that link\n");
- return ( 0, $self->loc("Link not found") );
+ return ( 0, $self->loc("Permission Denied") );
}
-}
-
-# }}}
-
-# {{{ sub RefersTo
-
-=head2 RefersTo
-
-Return an RT::Links object which contains pointers to all the things
-which this article refers to
-
-=cut
-
-sub RefersTo {
- my $self = shift;
- return $self->_Links( Field => 'Base', Type => 'RefersTo' );
-
-}
-
-# }}}
-
-# {{{ sub ReferredToBy
-
-=head2 ReferredToBy
-
-Return an RT::Links object which contains pointers to all the things
-which refer to this article.
-
-=cut
-
-sub ReferredToBy {
- my $self = shift;
- return $self->_Links( Field => 'Target', Type => 'RefersTo' );
+ $self->_AddLink(%args);
}
-# }}}
-
-# {{{ sub _Links
-
-sub _Links {
- my $self = shift;
- my %args = ( Field => undef,
- Type => undef,
- @_ );
-
- my $search = new RT::Links( $self->CurrentUser );
- if ( $self->CurrentUserHasRight('ShowArticle') ) {
-
- $search->Limit( FIELD => $args{'Field'}, VALUE => $self->URI );
- $search->Limit( FIELD => 'Type', VALUE => $args{'Type'} )
- if ( $args{'Type'} );
- }
- return ($search);
-}
-
-# }}}
-
-# }}}
-
-# {{{ sub URI
-
-=head2 URI
-
-Returns this article's URI
-
-
-=begin testing
-
-my ($id,$msg);
-my $art = RT::FM::Article->new($RT::SystemUser);
-($id, $msg) = $art->Create (Class => 'ArticleTest');
-ok ($id,$msg);
-
-ok($art->URI);
-ok($art->__Value('URI') eq $art->URI, "The uri in the db is set correctly");
-
-
-=end testing
-
-
-=cut
sub URI {
my $self = shift;
@@ -799,20 +367,6 @@
Returns this article's URI
-=begin testing
-
-my ($id,$msg);
-my $art = RT::FM::Article->new($RT::SystemUser);
-($id, $msg) = $art->Create (Class => 'ArticleTest');
-ok ($id,$msg);
-
-ok($art->URIObj);
-ok($art->__Value('URI') eq $art->URIObj->URI, "The uri in the db is set correctly");
-
-
-=end testing
-
-
=cut
sub URIObj {
@@ -922,25 +476,6 @@
Internal helper method to record a transaction as we update some core field of the article
-=begin testing
-
-my $art = RT::FM::Article->new($RT::SystemUser);
-$art->Load(1);
-ok ($art->Id == 1, "Loaded article 1");
-my $s =$art->Summary;
-my ($val, $msg) = $art->SetSummary("testFoo");
-ok ($val, $msg);
-ok ($art->Summary eq 'testFoo', "The Summary was set to foo");
-my $t = $art->Transactions();
-my $trans = $t->Last;
-ok ($trans->Type eq 'Core', "It's a core transaction");
-ok ($trans->Field eq 'Summary', "it's about setting the Summary");
-ok ($trans->NewContent eq 'testFoo', "The new content is 'foo'");
-ok ($trans->OldContent, "There was some old value");
-
-
-=end testing
-
=cut
sub _Set {
@@ -992,4 +527,6 @@
return $self->ClassObj->id;
}
+
+
1;
Modified: rtfm/branches/2.1-TESTING/lib/RT/FM/Class_Overlay.pm
==============================================================================
--- rtfm/branches/2.1-TESTING/lib/RT/FM/Class_Overlay.pm (original)
+++ rtfm/branches/2.1-TESTING/lib/RT/FM/Class_Overlay.pm Wed Feb 23 04:00:16 2005
@@ -98,59 +98,6 @@
varchar(255) 'Description'.
int(11) 'SortOrder'.
-=begin testing
-
-use_ok(RT::FM::Class);
-
-my $root = RT::CurrentUser->new('root');
-ok ($root->Id, "Loaded root");
-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');
-
-ok ($id, $msg);
-
-# no duplicate class names should be allowed
-($id, $msg) = $cl->Create(Name => 'Test', Description => 'A test class');
-
-ok (!$id, $msg);
-
-#class name should be required
-
-($id, $msg) = $cl->Create(Name => '', Description => 'A test class');
-
-ok (!$id, $msg);
-
-
-
-$cl->Load('Test');
-ok($cl->id, "Loaded the class we want");
-
-
-
-# Create a new user. make sure they can't create a class
-
-my $u= RT::User->new($RT::SystemUser);
-$u->Create(Name => "RTFMTest".time, Privileged => 1);
-ok ($u->Id, "Created a new user");
-
-# Make sure you can't create a group with no acls
-my $cl = RT::FM::Class->new($u);
-ok (UNIVERSAL::isa($cl, 'RT::FM::Class'), "the new class is a class");
-
-my ($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);
-my ($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");
-
-
-=end testing
-
-
=cut
sub Create {
Modified: rtfm/branches/2.1-TESTING/lib/RT/FM/System.pm
==============================================================================
--- rtfm/branches/2.1-TESTING/lib/RT/FM/System.pm (original)
+++ rtfm/branches/2.1-TESTING/lib/RT/FM/System.pm Wed Feb 23 04:00:16 2005
@@ -97,16 +97,6 @@
Returns RT::FM::System's id. It's 1.
-=begin testing
-
-use RT::FM::System;
-my $sys = RT::FM::System->new();
-is( $sys->Id, 1);
-is ($sys->id, 1);
-
-=end testing
-
-
=cut
*Id = \&id;
Modified: rtfm/branches/2.1-TESTING/t/00smoke.t
==============================================================================
--- rtfm/branches/2.1-TESTING/t/00smoke.t (original)
+++ rtfm/branches/2.1-TESTING/t/00smoke.t Wed Feb 23 04:00:16 2005
@@ -9,6 +9,6 @@
use File::Find;
File::Find::find({wanted => \&wanted}, '.');
-sub wanted { /^*\.pm\z/s && ok(require $_, "Requiring '$_'"); }
+sub wanted { /^*\.pm\z/s && $_ !~ /Overlay/ && ok(require $_, "Requiring '$_'"); }
Added: rtfm/branches/2.1-TESTING/t/ArticleCollection_Overlay.pm.t
==============================================================================
--- (empty file)
+++ rtfm/branches/2.1-TESTING/t/ArticleCollection_Overlay.pm.t Wed Feb 23 04:00:16 2005
@@ -0,0 +1,75 @@
+#!/usr/bin/perl -w
+
+use Test::More qw/no_plan/;
+use_ok(RT);
+RT::LoadConfig();
+RT::Init();
+use_ok( RT::FM::ArticleCollection);
+my $arts =RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitName (VALUE => 'testing');
+is($arts->Count, 0, 'Found no artlcles with summaries matching the word "testing"');
+
+my $arts2 =RT::FM::ArticleCollection->new($RT::SystemUser);
+#$arts2->LimitName (VALUE => 'test');
+#is($arts2->Count, 3, 'Found 3 artlcles with summaries matching the word "test"');
+
+
+ $arts =RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts->LimitSummary (VALUE => 'testing');
+is($arts->Count, 0, 'Found no artlcles with summaries matching the word "testing"');
+
+ $arts2 =RT::FM::ArticleCollection->new($RT::SystemUser);
+$arts2->LimitSummary (VALUE => 'test');
+is($arts2->Count, 3, 'Found 3 artlcles with summaries matching the word "test"');
+
+
+my $new_art = RT::FM::Article->new($RT::SystemUser);
+$new_art->Create (Class => 1,
+ Name => 'CFSearchTest1',
+ CustomField-1 => 'testing' );
+
+
+ok( $new_art->Id, " 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);
+
+
+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);
+
+
+$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);
+
Added: rtfm/branches/2.1-TESTING/t/Article_Overlay.pm.t
==============================================================================
--- (empty file)
+++ rtfm/branches/2.1-TESTING/t/Article_Overlay.pm.t Wed Feb 23 04:00:16 2005
@@ -0,0 +1,230 @@
+#!/usr/bin/perl -w
+
+use Test::More 'no_plan';
+
+use_ok(RT);
+RT::LoadConfig();
+RT::Init();
+
+use_ok(RT::FM::Article);
+use_ok(RT::FM::ArticleCollection);
+use_ok(RT::FM::Class);
+
+my $user = RT::CurrentUser->new('root');
+
+my $class = RT::FM::Class->new($user);
+
+
+my ($id, $msg) = $class->Create(Name =>'ArticleTest');
+ok ($id, $msg);
+
+
+
+my $article = RT::FM::Article->new($user);
+ok (UNIVERSAL::isa($article, 'RT::FM::Article'));
+ok (UNIVERSAL::isa($article, 'RT::FM::Record'));
+ok (UNIVERSAL::isa($article, 'RT::Record'));
+ok (UNIVERSAL::isa($article, 'DBIx::SearchBuilder::Record') , "It's a searchbuilder record!");
+
+
+($id, $msg) = $article->Create( Class => 'ArticleTest', Summary => "ArticleTest");
+ok ($id, $msg);
+$article->Load($id);
+is ($article->Summary, 'ArticleTest', "The summary is set correct");
+my $at = RT::FM::Article->new($RT::SystemUser);
+$at->Load($id);
+is ($at->id , $id);
+is ($at->Summary, $article->Summary);
+
+
+
+
+my $a1 = RT::FM::Article->new($RT::SystemUser);
+ ($id, $msg) = $a1->Create(Class => 1, Name => 'ValidateNameTest');
+ok ($id, $msg);
+
+
+
+my $a2 = RT::FM::Article->new($RT::SystemUser);
+($id, $msg) = $a2->Create(Class => 1, Name => 'ValidateNameTest');
+ok (!$id, $msg);
+
+my $a3 = RT::FM::Article->new($RT::SystemUser);
+($id, $msg) = $a3->Create(Class => 1, Name => 'ValidateNameTest2');
+ok ($id, $msg);
+($id, $msg) =$a3->SetName('ValidateNameTest');
+
+ok (!$id, $msg);
+
+($id, $msg) =$a3->SetName('ValidateNametest2');
+
+ok ($id, $msg);
+
+
+
+
+
+my $newart = RT::FM::Article->new($RT::SystemUser);
+$newart->Create(Name => 'DeleteTest', Class => '1');
+$id = $newart->Id;
+
+ok($id, "New article has an id");
+
+
+ $article = RT::FM::Article->new($RT::SystemUser);
+$article->Load($id);
+ok ($article->Id, "Found the article");
+my $val;
+ ($val, $msg) = $article->Delete();
+ok ($val, "Article Deleted: $msg");
+
+ $a2 = RT::FM::Article->new($RT::SystemUser);
+$a2->Load($id);
+ok (!$a2->Id, "Did not find the article");
+
+
+$RT::Handle->SimpleQuery("DELETE FROM Links");
+
+my $article_a = RT::FM::Article->new($RT::SystemUser);
+($id, $msg) = $article_a->Create( Class => 'ArticleTest', Summary => "ArticleTestlink1");
+ok($id,$msg);
+
+my $article_b = RT::FM::Article->new($RT::SystemUser);
+($id, $msg) = $article_b->Create( Class => 'ArticleTest', Summary => "ArticleTestlink2");
+ok($id,$msg);
+
+# Create a link between two articles
+($id, $msg) = $article_a->AddLink( Type => 'RefersTo', Target => $article_b->URI);
+ok($id,$msg);
+
+# Make sure that Article B's "ReferredToBy" links object refers to to this article"
+my $refers_to_b = $article_b->ReferredToBy;
+ok($refers_to_b->Count == 1, "Found one thing referring to b");
+my $first = $refers_to_b->First;
+ok ($first->isa(RT::Link), "IT's an RT link - ref ".ref($first) );
+ok ($first->TargetObj->Id == $article_b->Id, "Its target is B");
+
+ok($refers_to_b->First->BaseObj->isa('RT::FM::Article'), "Yep. its an article");
+
+
+# Make sure that Article A's "RefersTo" links object refers to this article"
+my $referred_To_by_a = $article_a->RefersTo;
+ok($referred_To_by_a->Count == 1, "Found one thing referring to b ".$referred_To_by_a->Count. "-".$referred_To_by_a->First->id . " - ".$referred_To_by_a->Last->id);
+ $first = $referred_To_by_a->First;
+ok ($first->isa(RT::Link), "IT's an RT link - ref ".ref($first) );
+ok ($first->TargetObj->Id == $article_b->Id, "Its target is B - " . $first->TargetObj->Id);
+ok ($first->BaseObj->Id == $article_a->Id, "Its base is A");
+
+ok($referred_To_by_a->First->BaseObj->isa('RT::FM::Article'), "Yep. its an article");
+
+# Delete the link
+($id, $msg) = $article_a->DeleteLink(Type => 'RefersTo', Target => $article_b->URI);
+ok($id,$msg);
+
+
+# Create an Article A RefersTo Ticket 1 from the RTFM side
+use RT::Ticket;
+
+
+my $tick = RT::Ticket->new($RT::SystemUser);
+$tick->Create(Subject => "Article link test ", Queue => 'General');
+$tick->Load($tick->Id);
+ok ($tick->Id, "Found ticket ".$tick->id);
+($id, $msg) = $article_a->AddLink(Type => 'RefersTo', Target => $tick->URI);
+ok($id,$msg);
+
+# Find all tickets whhich refer to Article A
+
+use RT::Tickets;
+use RT::Links;
+
+my $tix = RT::Tickets->new($RT::SystemUser);
+ok ($tix, "Got an RT::Tickets object");
+ok ($tix->LimitReferredToBy($article_a->URI));
+ok ($tix->Count == 1, "Found one ticket linked to that article");
+ok ($tix->First->Id == $tick->id, "It's even the right one");
+
+
+
+# Find all articles which refer to Ticket 1
+use RT::FM::ArticleCollection;
+
+my $articles = RT::FM::ArticleCollection->new($RT::SystemUser);
+ok($articles->isa('RT::FM::ArticleCollection'), "Created an article collection");
+ok($articles->isa('RT::FM::SearchBuilder'), "Created an article collection");
+ok($articles->isa('RT::SearchBuilder'), "Created an article collection");
+ok($articles->isa('DBIx::SearchBuilder'), "Created an article collection");
+ok($tick->URI, "The ticket does still have a URI");
+$articles->LimitRefersTo($tick->URI);
+
+is($articles->Count(), 1);
+is ($articles->First->Id, $article_a->Id);
+is ($articles->First->URI, $article_a->URI);
+
+
+
+# Find all things which refer to ticket 1 using the RT API.
+
+my $tix2 = RT::Links->new($RT::SystemUser);
+ok ($tix2->isa('RT::Links'));
+ok($tix2->LimitRefersTo($tick->URI));
+ok ($tix2->Count == 1);
+is ($tix2->First->BaseObj->URI ,$article_a->URI);
+
+
+
+# Delete the link from the RT side.
+my $t2 = RT::Ticket->new($RT::SystemUser);
+$t2->Load($tick->Id);
+($id, $msg)= $t2->DeleteLink( Base => $article_a->URI, Type => 'RefersTo');
+ok ($id, $msg . " - $id - $msg");
+
+# it is actually deleted
+my $tix3 = RT::Links->new($RT::SystemUser);
+$tix3->LimitReferredToBy($tick->URI);
+ok ($tix3->Count == 0);
+
+# Recreate the link from teh RT site
+($id, $msg) = $t2->AddLink( Base => $article_a->URI, Type => 'RefersTo');
+ok ($id, $msg);
+
+# Find all tickets whhich refer to Article A
+
+# Find all articles which refer to Ticket 1
+
+
+
+
+my $art = RT::FM::Article->new($RT::SystemUser);
+($id, $msg) = $art->Create (Class => 'ArticleTest');
+ok ($id,$msg);
+
+ok($art->URI);
+ok($art->__Value('URI') eq $art->URI, "The uri in the db is set correctly");
+
+
+
+
+ $art = RT::FM::Article->new($RT::SystemUser);
+($id, $msg) = $art->Create (Class => 'ArticleTest');
+ok ($id,$msg);
+
+ok($art->URIObj);
+ok($art->__Value('URI') eq $art->URIObj->URI, "The uri in the db is set correctly");
+
+
+
+$art = RT::FM::Article->new($RT::SystemUser);
+$art->Load(1);
+ok ($art->Id == 1, "Loaded article 1");
+my $s =$art->Summary;
+($val, $msg) = $art->SetSummary("testFoo");
+ok ($val, $msg);
+ok ($art->Summary eq 'testFoo', "The Summary was set to foo");
+my $t = $art->Transactions();
+my $trans = $t->Last;
+ok ($trans->Type eq 'Core', "It's a core transaction");
+ok ($trans->Field eq 'Summary', "it is about setting the Summary");
+ok ($trans->NewContent eq 'testFoo', "The new content is 'foo'");
+ok ($trans->OldContent, "There was some old value");
+
Added: rtfm/branches/2.1-TESTING/t/Class_Overlay.pm.t
==============================================================================
--- (empty file)
+++ rtfm/branches/2.1-TESTING/t/Class_Overlay.pm.t Wed Feb 23 04:00:16 2005
@@ -0,0 +1,53 @@
+#!/usr/bin/perl -w
+
+use Test::More 'no_plan';
+
+use_ok('RT');
+RT::LoadConfig();
+RT::Init();
+use_ok(RT::FM::Class);
+
+my $root = RT::CurrentUser->new('root');
+ok ($root->Id, "Loaded root");
+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');
+
+ok ($id, $msg);
+
+# no duplicate class names should be allowed
+($id, $msg) = $cl->Create(Name => 'Test', Description => 'A test class');
+
+ok (!$id, $msg);
+
+#class name should be required
+
+($id, $msg) = $cl->Create(Name => '', Description => 'A test class');
+
+ok (!$id, $msg);
+
+
+
+$cl->Load('Test');
+ok($cl->id, "Loaded the class we want");
+
+
+
+# Create a new user. make sure they can't create a class
+
+my $u= RT::User->new($RT::SystemUser);
+$u->Create(Name => "RTFMTest".time, Privileged => 1);
+ok ($u->Id, "Created a new user");
+
+# Make sure you can't create a group with no acls
+$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');
+
+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');
+
+ok ($id, $msg. "- Can create classes as a random new user after ACL grant");
Added: rtfm/branches/2.1-TESTING/t/System.pm.t
==============================================================================
--- (empty file)
+++ rtfm/branches/2.1-TESTING/t/System.pm.t Wed Feb 23 04:00:16 2005
@@ -0,0 +1,9 @@
+#!/usr/bin/perl -w
+
+use Test::More 'no_plan';
+
+use_ok( 'RT::FM::System');
+my $sys = RT::FM::System->new();
+is( $sys->Id, 1);
+is ($sys->id, 1);
+
More information about the Rt-commit
mailing list