|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use Test::Deep; |
| 5 | +use RT::Test::Shredder tests => undef; |
| 6 | +use MIME::Entity; |
| 7 | + |
| 8 | +my $test = "RT::Test::Shredder"; |
| 9 | + |
| 10 | +my @ARGS = sort qw(limit files_only file longer); |
| 11 | + |
| 12 | +use_ok('RT::Shredder::Plugin::Attachments'); |
| 13 | +{ |
| 14 | + my $plugin = RT::Shredder::Plugin::Attachments->new; |
| 15 | + isa_ok( $plugin, 'RT::Shredder::Plugin::Attachments' ); |
| 16 | + |
| 17 | + is( lc $plugin->Type, 'search', 'correct type' ); |
| 18 | + |
| 19 | + my @args = sort $plugin->SupportArgs; |
| 20 | + cmp_deeply( \@args, \@ARGS, "support all args" ); |
| 21 | +} |
| 22 | + |
| 23 | +{ |
| 24 | + my $ticket = RT::Ticket->new( RT->SystemUser ); |
| 25 | + my $mime = MIME::Entity->build( |
| 26 | + From => 'test@example.com', |
| 27 | + Type => 'text/html', |
| 28 | + Data => ['test attachment'], |
| 29 | + ); |
| 30 | + |
| 31 | + $mime->attach( |
| 32 | + Path => 'share/static/images/bpslogo.png', |
| 33 | + Type => 'image/png', |
| 34 | + ); |
| 35 | + |
| 36 | + RT::Test->create_ticket( MIMEObj => $mime, Queue => 'General', Subject => 'test attachment' ); |
| 37 | + my $attachments = RT::Attachments->new( RT->SystemUser ); |
| 38 | + $attachments->Limit( FIELD => 'Filename', VALUE => 'bpslogo.png' ); |
| 39 | + is( $attachments->Count, 1, 'created the attachment' ); |
| 40 | + |
| 41 | + my $plugin = RT::Shredder::Plugin::Attachments->new; |
| 42 | + my ( $status, $msg ) = $plugin->TestArgs( name => 'bpslogo.png', longer => '1k' ); |
| 43 | + ok( $status, "plugin arguments are ok" ) or diag "error: $msg"; |
| 44 | + |
| 45 | + ( $status, my @objects ) = $plugin->Run; |
| 46 | + ok( $status, "executed plugin successfully" ) or diag "error: @objects"; |
| 47 | + is( scalar @objects, 1, 'found 1 attachment' ); |
| 48 | + |
| 49 | + my $shredder = $test->shredder_new(); |
| 50 | + $shredder->PutObjects( Objects => \@objects ); |
| 51 | + $shredder->WipeoutAll; |
| 52 | + |
| 53 | + $attachments = RT::Attachments->new( RT->SystemUser ); |
| 54 | + $attachments->Limit( FIELD => 'Filename', VALUE => 'bpslogo.png' ); |
| 55 | + is( $attachments->Count, 0, 'shredded the attachment' ); |
| 56 | +} |
| 57 | + |
| 58 | +done_testing; |
0 commit comments