forked from jayallen/melody
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#481] [#632] Big rearrangement of
t/93-plugins.t
to make it more m…
…anageable and readable
- Loading branch information
Showing
1 changed file
with
99 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,116 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use lib 't/lib', 'lib', 'extlib'; | ||
use lib 't/lib', 'lib', 'extlib', 'addons/Log4MT.plugin/extlib'; | ||
use Data::Dumper; | ||
use Test::Warn; | ||
use Test::More tests => 16; | ||
|
||
use MT; | ||
use MT::Test qw( :app :db ); | ||
use MT::Log::Log4perl qw( l4mtdump ); use Log::Log4perl qw( :resurrect ); | ||
###l4p our $logger = MT::Log::Log4perl->new(); $logger->trace(); | ||
|
||
# get the list of plugins and place them in a hash | ||
my $plugins = (); | ||
our ( $app ); | ||
|
||
my $app = MT->instance(); | ||
my %test_info = ( | ||
'addons/Markdown.plugin/config.yaml' => { | ||
name => 'Markdown and SmartyPants', | ||
base_class => 'MT::Plugin', # <----- DEFAULT | ||
plugin_path => 'addons', # <----- DEFAULT | ||
enabled => 1, # <----- DEFAULT | ||
}, | ||
't/plugins/Awesome/config.yaml' => { name => 'Oh Awesome' }, | ||
'addons/ThemeExport.plugin/config.yaml' => { name => 'Theme Exporter' }, | ||
'addons/ThemeManager.plugin/config.yaml' => { name => 'Theme Manager' }, | ||
'addons/DePoClean.plugin/config.yaml' => { name => 'DePoClean' }, | ||
'addons/WXRImporter.plugin/config.yaml' => { name => 'WXR Importer' }, | ||
'addons/ClassicBlogThemePack.plugin/config.yaml' | ||
=> { name => 'Classic Blog Theme Pack' }, | ||
'addons/SimpleEditor.plugin/config.yaml' | ||
=> { name => 'Six Apart Rich Text Editor' }, | ||
'addons/MelodyFeedback.plugin/config.yaml' | ||
=> { name => 'Open Melody Community Feedback' }, | ||
'addons/MultiBlog.plugin/config.yaml' => { | ||
name => 'MultiBlog', | ||
base_class => 'MultiBlog::Plugin', | ||
}, | ||
'addons/TypePadAntiSpam.plugin/config.yaml' => { | ||
name => 'TypePad AntiSpam', | ||
base_class => 'TypePadAntiSpam::Plugin', | ||
}, | ||
'addons/ConfigAssistant.pack/config.yaml' => { | ||
name => 'Configuration Assistant', | ||
base_class => 'MT::Component', | ||
}, | ||
't/plugins/Rebless/config.yaml' => { | ||
name => 'Rebless Me', | ||
base_class => 'Rebless::Plugin', | ||
}, | ||
't/plugins/stray.pl' => { | ||
message => ': Stray, unloaded perl plugin', | ||
not_loaded => 1, | ||
}, | ||
't/plugins/stray.yaml' => { | ||
message => ': Stray, unloaded yaml plugin', | ||
not_loaded => 1, | ||
}, | ||
't/plugins/subfoldered/subfoldered.pl' => { | ||
name => 'Subfoldered plugin', | ||
} | ||
); | ||
|
||
# The horse left the barn long ago | ||
# my $cfg = $app->config; | ||
# $cfg->PluginPath(['t/plugins', 'plugins']); | ||
$app->init_plugins(); | ||
warnings_like { | ||
use MT::Test qw( :app :db ); | ||
|
||
for my $sig ( keys %MT::Plugins ) { | ||
$app = MT->instance(); | ||
$app->init_plugins(); | ||
} | ||
[ | ||
qr/stray.pl.+not loaded.+plugins.+without.+enclosing folder/, | ||
qr/.+plugin \(subfoldered.pl\).+deprecated plugin file format/ | ||
], | ||
'Deprecation and compatibility break warnings'; | ||
|
||
# print STDERR "Plugin: $sig\n"; | ||
my $profile = $MT::Plugins{$sig}; | ||
if ( my $plugin = $profile->{object} ) { | ||
###l4p $logger->debug("PLUGIN: $_") foreach keys %MT::Plugins; | ||
|
||
# print STDERR " name: " . $plugin->name . "($sig,".ref($profile->{object}).")\n"; | ||
$plugins->{ $plugin->name }++; | ||
my %Test = (); | ||
foreach my $sig ( sort keys %MT::Plugins ) { | ||
my $profile = $MT::Plugins{ $sig }; | ||
my $info = delete $test_info{ $sig }; | ||
$Test{ $sig } = { | ||
enabled => $profile->{enabled} || 0, | ||
plugin => $profile->{object}, | ||
$info ? (info => $info) : (), | ||
} | ||
} | ||
|
||
########################################################### | ||
# Test for the existence of at least these plugins | ||
########################################################### | ||
|
||
# plguins that really exist with the build | ||
ok( exists $plugins->{"MultiBlog"}, "MultiBlog exists" ); | ||
ok( exists $plugins->{"Markdown and SmartyPants"}, "Markdown exists" ); | ||
ok( exists $plugins->{"Configuration Assistant"}, "Config Assistant exists" ); | ||
ok( exists $plugins->{"Theme Exporter"}, "Theme Exporter exists" ); | ||
ok( exists $plugins->{"Theme Manager"}, "Theme Manager exists" ); | ||
ok( exists $plugins->{"Simple Rich Text Editor"}, | ||
"Simple Rich Text Editor exists" ); | ||
ok( exists $plugins->{"DePoClean"}, "DePoClean exists" ); | ||
ok( exists $plugins->{"Open Melody Community Feedback"}, | ||
"Open Melody Community Feedback exists" ); | ||
ok( exists $plugins->{"WXR Importer"}, "WXR Importer exists" ); | ||
ok( exists $plugins->{"TypePad AntiSpam"}, "TypePad AntiSpam exists" ); | ||
|
||
ok( exists $plugins->{"Rebless Me"}, "Rebless Me Test Plugin exists" ); | ||
is( ref( $MT::Plugins{'Rebless/config.yaml'}->{'object'} ), | ||
'Rebless::Plugin', 'Rebless Plugin is Rebless::Plugin' ); | ||
is( ref( $MT::Plugins{'ConfigAssistant.pack/config.yaml'}->{'object'} ), | ||
'MT::Component', 'Config Assistant is MT::Component' ); | ||
is( ref( $MT::Plugins{'ThemeManager.plugin/config.yaml'}->{'object'} ), | ||
'MT::Plugin', 'Theme Manager is MT::Plugin' ); | ||
|
||
SKIP: { | ||
foreach my $sig ( sort keys %test_info ) { | ||
$Test{ $sig } = { | ||
info => $test_info{ $sig } | ||
} | ||
} | ||
|
||
# To test these, you need to do one of the following: | ||
# 1) use a custom config file (like the ones we used to have) so you can | ||
# set the PluginPath normally | ||
# 2) bootstrap the app yourself or | ||
# 3) Override/Hook into the init process so you can set the PluginPath | ||
# BEFORE the plugins are initialized, or | ||
# 4) Break up the damn _init_plugins_core method so that it's actually | ||
# testable. | ||
skip "MT::Test dummy plugins skipped", 2 | ||
unless ref( $app->config->PluginPath ) eq 'ARRAY' | ||
and grep {m{(t|..)/plugins$}} @{ $app->config->PluginPath }; | ||
foreach my $sig ( sort keys %Test ) { | ||
my $test = $Test{$sig}; | ||
subtest $sig => sub { | ||
plan tests => 2; | ||
my $info = $test->{info}; | ||
$info->{base_class} ||= 'MT::Plugin'; | ||
$info->{message} ||= " exists"; | ||
my $loaded = $info->{not_loaded} ? 0 : 1; | ||
is( | ||
($sig && exists $MT::Plugins{$sig}) ? 1 : 0, | ||
$loaded, | ||
$sig . $info->{message} | ||
); | ||
SKIP: { | ||
skip "Plugin not loaded", 1 unless $loaded; | ||
is( | ||
ref( $MT::Plugins{$sig}->{'object'} ), | ||
$info->{base_class}, | ||
$info->{name}.' base class is '.$info->{base_class} | ||
); | ||
} | ||
}; | ||
|
||
# test plugins created by MT::Test | ||
ok( exists $plugins->{"Awesome"}, "Awesome exists" ); | ||
ok( exists $plugins->{"testplug.pl"}, "testplug.pl exists" ); | ||
} | ||
|