[Rt-commit] rt branch 5.0/shred-more-objects created. rt-5.0.3-221-ga1d2ee6981
BPS Git Server
git at git.bestpractical.com
Thu Dec 29 22:09:04 UTC 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 5.0/shred-more-objects has been created
at a1d2ee6981218026b0dd4e50c64fc9f5f395129b (commit)
- Log -----------------------------------------------------------------
commit a1d2ee6981218026b0dd4e50c64fc9f5f395129b
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Dec 30 05:42:12 2022 +0800
Test shredder for class/topic/article objects
diff --git a/t/shredder/02article.t b/t/shredder/02article.t
new file mode 100644
index 0000000000..dc1f9a110d
--- /dev/null
+++ b/t/shredder/02article.t
@@ -0,0 +1,76 @@
+use strict;
+use warnings;
+
+use Test::Deep;
+use RT::Test::Shredder tests => undef;
+my $test = "RT::Test::Shredder";
+
+my $class = RT::Class->new( RT->SystemUser );
+$class->Load('General');
+ok( $class->Id, 'loaded class General' );
+
+diag 'simple article' if $ENV{TEST_VERBOSE};
+{
+ $test->create_savepoint('clean');
+
+ my $article = RT::Article->new( RT->SystemUser );
+ my ( $id, $msg ) = $article->Create( Class => $class->Id, Name => 'test 1' );
+ ok( $id, 'created article' ) or diag "error: $msg";
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $article );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+diag 'article with custom fields' if $ENV{TEST_VERBOSE};
+{
+ my $cf = RT::CustomField->new( RT->SystemUser );
+ my ( $id, $msg ) = $cf->Create(
+ Name => 'article custom field',
+ Type => 'Freeform',
+ LookupType => RT::Article->CustomFieldLookupType,
+ MaxValues => 1,
+ );
+ ok( $id, 'created article custom field' ) or diag "error: $msg";
+
+ # apply the custom fields to the class.
+ ( $id, $msg ) = $cf->AddToObject($class);
+ ok( $id, 'applied cf to class' ) or diag "error: $msg";
+
+ $test->create_savepoint('clean');
+ my $article = RT::Article->new( RT->SystemUser );
+ ( $id, $msg ) = $article->Create( Class => $class->Id, Name => 'test 1', 'CustomField-' . $cf->Id => 'test' );
+ ok( $id, 'created article' ) or diag "error: $msg";
+ is( $article->FirstCustomFieldValue('article custom field'), 'test', 'article cf is set' );
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $article );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+diag 'article with topics' if $ENV{TEST_VERBOSE};
+{
+ my $topic = RT::Topic->new( RT->SystemUser );
+ my ( $id, $msg ) = $topic->Create( ObjectType => 'RT::Class', ObjectId => $class->Id );
+ ok( $id, 'created topic' ) or diag "error: $msg";
+
+ $test->create_savepoint('clean');
+ my $article = RT::Article->new( RT->SystemUser );
+ ( $id, $msg ) = $article->Create( Class => $class->Id, Name => 'test 1', 'Topics' => [ $topic->Id ] );
+ ok( $id, 'created article' ) or diag "error: $msg";
+ is( $article->Topics->First->Id, $topic->Id, 'article topic is set' );
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $article );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+done_testing;
diff --git a/t/shredder/02class.t b/t/shredder/02class.t
new file mode 100644
index 0000000000..1217869c42
--- /dev/null
+++ b/t/shredder/02class.t
@@ -0,0 +1,148 @@
+use strict;
+use warnings;
+
+use Test::Deep;
+use RT::Test::Shredder tests => undef;
+my $test = "RT::Test::Shredder";
+
+diag 'simple class' if $ENV{TEST_VERBOSE};
+{
+ $test->create_savepoint('clean');
+ my $class = RT::Class->new( RT->SystemUser );
+ my ( $id, $msg ) = $class->Create( Name => 'my class' );
+ ok( $id, 'created class' ) or diag "error: $msg";
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $class );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+diag 'class with a right granted' if $ENV{TEST_VERBOSE};
+{
+ $test->create_savepoint('clean');
+ my $class = RT::Class->new( RT->SystemUser );
+ my ( $id, $msg ) = $class->Create( Name => 'my class' );
+ ok( $id, 'created class' ) or diag "error: $msg";
+
+ my $group = RT::Group->new( RT->SystemUser );
+ $group->LoadSystemInternalGroup('Everyone');
+ ok( $group->id, 'loaded group' );
+
+ ( $id, $msg ) = $group->PrincipalObj->GrantRight(
+ Right => 'CreateArticle',
+ Object => $class,
+ );
+ ok( $id, 'granted right' ) or diag "error: $msg";
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $class );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+diag 'class with custom fields' if $ENV{TEST_VERBOSE};
+{
+ my $class_custom_field = RT::CustomField->new( RT->SystemUser );
+ my ( $id, $msg ) = $class_custom_field->Create(
+ Name => 'class custom field',
+ Type => 'Freeform',
+ LookupType => RT::Class->CustomFieldLookupType,
+ MaxValues => 1,
+ );
+ ok( $id, 'created class custom field' ) or diag "error: $msg";
+
+ my $article_custom_field = RT::CustomField->new( RT->SystemUser );
+ ( $id, $msg ) = $article_custom_field->Create(
+ Name => 'article custom field',
+ Type => 'Freeform',
+ LookupType => RT::Article->CustomFieldLookupType,
+ MaxValues => 1,
+ );
+ ok( $id, 'created article custom field' ) or diag "error: $msg";
+
+ # Create an ObjectCustomField for assets with the same ObjectId, to make sure it's not shredded.
+ my $asset_custom_field = RT::CustomField->new( RT->SystemUser );
+ ( $id, $msg ) = $asset_custom_field->Create(
+ Name => 'asset custom field',
+ Type => 'Freeform',
+ LookupType => RT::Asset->CustomFieldLookupType,
+ MaxValues => '1',
+ );
+ ok( $id, 'created asset custom field' ) or diag "error: $msg";
+
+ my $catalog = RT::Catalog->new( RT->SystemUser );
+ ok( $catalog->Create( Name => "catalog 2" ), "created catalog 2" );
+ ( $id, $msg ) = $asset_custom_field->AddToObject($catalog);
+ ok( $id, 'applied asset cf to catalog' ) or diag "error: $msg";
+
+ $test->create_savepoint('clean');
+ my $class = RT::Class->new( RT->SystemUser );
+ ( $id, $msg ) = $class->Create( Name => 'my class' );
+ ok( $id, 'created class' ) or diag "error: $msg";
+
+ # apply the custom fields to the class.
+ ( $id, $msg ) = $class_custom_field->AddToObject($class);
+ ok( $id, 'applied class cf to class' ) or diag "error: $msg";
+
+ # apply the custom fields to the class.
+ ( $id, $msg ) = $article_custom_field->AddToObject($class);
+ ok( $id, 'applied article cf to class' ) or diag "error: $msg";
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $class );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+diag 'class with articles' if $ENV{TEST_VERBOSE};
+{
+
+ my $article = RT::Article->new( RT->SystemUser );
+ my ( $id, $msg ) = $article->Create( Class => 'General', Name => 'test 1' );
+ ok( $id, 'created article' ) or diag "error: $msg";
+
+ $test->create_savepoint('clean');
+ my $class = RT::Class->new( RT->SystemUser );
+ ( $id, $msg ) = $class->Create( Name => 'my class' );
+ ok( $id, 'created class' ) or diag "error: $msg";
+
+ ( $id, $msg ) = $article->Create( Class => $class->Id, Name => 'test 2' );
+ ok( $id, 'created article' ) or diag "error: $msg";
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $class );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+
+diag 'class with topics' if $ENV{TEST_VERBOSE};
+{
+ my $topic = RT::Topic->new( RT->SystemUser );
+ my ( $id, $msg ) = $topic->Create( ObjectType => 'RT::Class', ObjectId => 0 );
+ ok( $id, 'created topic' ) or diag "error: $msg";
+
+ $test->create_savepoint('clean');
+ my $class = RT::Class->new( RT->SystemUser );
+ ( $id, $msg ) = $class->Create( Name => 'my class' );
+ ok( $id, 'created class' ) or diag "error: $msg";
+
+ ( $id, $msg ) = $topic->Create( ObjectType => 'RT::Class', ObjectId => $class->Id );
+ ok( $id, 'created topic' ) or diag "error: $msg";
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $class );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+done_testing;
diff --git a/t/shredder/02topic.t b/t/shredder/02topic.t
new file mode 100644
index 0000000000..4ec47fd5b0
--- /dev/null
+++ b/t/shredder/02topic.t
@@ -0,0 +1,49 @@
+use strict;
+use warnings;
+
+use Test::Deep;
+use RT::Test::Shredder tests => undef;
+my $test = "RT::Test::Shredder";
+
+my $class = RT::Class->new( RT->SystemUser );
+$class->Load('General');
+ok( $class->Id, 'loaded class General' );
+
+diag 'simple topic' if $ENV{TEST_VERBOSE};
+{
+ $test->create_savepoint('clean');
+
+ my $topic = RT::Topic->new( RT->SystemUser );
+ my ( $id, $msg ) = $topic->Create( ObjectType => 'RT::Class', ObjectId => $class->Id );
+ ok( $id, 'created topic' ) or diag "error: $msg";
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $topic );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+diag 'topic with articles' if $ENV{TEST_VERBOSE};
+{
+ my $article = RT::Article->new( RT->SystemUser );
+ my ( $id, $msg ) = $article->Create( Class => 'General', Name => 'test 1' );
+ ok( $id, 'created article' ) or diag "error: $msg";
+
+ $test->create_savepoint('clean');
+ my $topic = RT::Topic->new( RT->SystemUser );
+ ( $id, $msg ) = $topic->Create( ObjectType => 'RT::Class', ObjectId => $class->Id );
+ ok( $id, 'created topic' ) or diag "error: $msg";
+
+ ( $id, $msg ) = $article->AddTopic( Topic => $topic->Id );
+ ok( $id, 'added topic' ) or diag "error: $msg";
+
+ my $shredder = $test->shredder_new();
+ $shredder->PutObjects( Objects => $topic );
+ $shredder->WipeoutAll;
+ $test->db_is_valid;
+
+ cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint" );
+}
+
+done_testing;
commit 2da30214bc10e1b116e9b252052a8a20daf38359
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Dec 30 04:19:12 2022 +0800
Support to shred class/topic/article objects
diff --git a/lib/RT/Article.pm b/lib/RT/Article.pm
index 590b4fb989..dbd2b97683 100644
--- a/lib/RT/Article.pm
+++ b/lib/RT/Article.pm
@@ -899,6 +899,31 @@ sub Load {
}
}
+sub __DependsOn {
+ my $self = shift;
+ my %args = (
+ Shredder => undef,
+ Dependencies => undef,
+ @_,
+ );
+ my $deps = $args{'Dependencies'};
+ my $list = [];
+
+ # ObjectTopics
+ my $objs = RT::ObjectTopics->new( $self->CurrentUser );
+ $objs->LimitToObject($self);
+ push( @$list, $objs );
+
+ $deps->_PushDependencies(
+ BaseObject => $self,
+ Flags => RT::Shredder::Constants::DEPENDS_ON,
+ TargetObjects => $list,
+ Shredder => $args{'Shredder'}
+ );
+
+ return $self->SUPER::__DependsOn(%args);
+}
+
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Class.pm b/lib/RT/Class.pm
index 236d8548d9..1a6f09535d 100644
--- a/lib/RT/Class.pm
+++ b/lib/RT/Class.pm
@@ -596,6 +596,47 @@ sub CustomFieldLookupType {
"RT::Class";
}
+sub __DependsOn {
+ my $self = shift;
+ my %args = (
+ Shredder => undef,
+ Dependencies => undef,
+ @_,
+ );
+ my $deps = $args{'Dependencies'};
+ my $list = [];
+
+ # Articles
+ my $objs = RT::Articles->new( $self->CurrentUser );
+ $objs->FindAllRows;
+ $objs->Limit( FIELD => 'Class', VALUE => $self->Id );
+ push( @$list, $objs );
+
+ # ObjectClasses
+ $objs = RT::ObjectClasses->new( $self->CurrentUser );
+ $objs->LimitToClass( $self->id );
+ push( @$list, $objs );
+
+ # ObjectCustomFields
+ $objs = RT::ObjectCustomFields->new( $self->CurrentUser );
+ $objs->LimitToLookupType($_) for map { $_->CustomFieldLookupType } qw/RT::Class RT::Article/;
+ $objs->LimitToObjectId( $self->id );
+ push( @$list, $objs );
+
+ # Topics
+ $objs = RT::Topics->new( $self->CurrentUser );
+ $objs->LimitToObject($self);
+ push( @$list, $objs );
+
+ $deps->_PushDependencies(
+ BaseObject => $self,
+ Flags => RT::Shredder::Constants::DEPENDS_ON,
+ TargetObjects => $list,
+ Shredder => $args{'Shredder'}
+ );
+ return $self->SUPER::__DependsOn(%args);
+}
+
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/Shredder.pm b/lib/RT/Shredder.pm
index 9a103ee3a3..54989df0dc 100644
--- a/lib/RT/Shredder.pm
+++ b/lib/RT/Shredder.pm
@@ -252,6 +252,9 @@ our @SUPPORTED_OBJECTS = qw(
Ticket
Transaction
User
+ Class
+ Article
+ Topic
);
=head3 GENERIC
diff --git a/lib/RT/Topic.pm b/lib/RT/Topic.pm
index 79edc1511f..2b03489919 100644
--- a/lib/RT/Topic.pm
+++ b/lib/RT/Topic.pm
@@ -362,5 +362,29 @@ sub FindDependencies {
$deps->Add( out => $self->Object );
}
+sub __DependsOn {
+ my $self = shift;
+ my %args = (
+ Shredder => undef,
+ Dependencies => undef,
+ @_,
+ );
+ my $deps = $args{'Dependencies'};
+ my $list = [];
+
+ # Object Topics
+ my $objs = RT::ObjectTopics->new( $self->CurrentUser );
+ $objs->LimitToTopic( $self->Id );
+ push( @$list, $objs );
+
+ $deps->_PushDependencies(
+ BaseObject => $self,
+ Flags => RT::Shredder::Constants::DEPENDS_ON,
+ TargetObjects => $list,
+ Shredder => $args{'Shredder'}
+ );
+ return $self->SUPER::__DependsOn(%args);
+}
+
RT::Base->_ImportOverlays();
1;
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list