Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

TESTS!!!1!

  • Loading branch information...
commit c1c29c02423b9fed97317e5a3aba21666c848186 1 parent df448ac
David Raynes rayners authored
6 t/plugins/SphinxSearch/00-compile.t
View
@@ -0,0 +1,6 @@
+
+use Test::More tests => 1;
+
+# plugin assumes this, thanks to MT
+use lib 'plugins/SphinxSearch/lib';
+require_ok( 'plugins/SphinxSearch/sphinx-search.pl');
52 t/plugins/SphinxSearch/01-indexes.t
View
@@ -0,0 +1,52 @@
+
+use File::Spec;
+BEGIN {
+ my $mt_home = $ENV{MT_HOME} || '';
+ unshift @INC, File::Spec->catdir ($mt_home, 'lib'), File::Spec->catdir ($mt_home, 'extlib');
+}
+
+use Test::More tests => 11;
+use Test::Deep;
+
+use strict;
+use warnings;
+
+# use lib 'plugins/SphinxSearch/lib';
+#
+# require 'plugins/SphinxSearch/sphinx-search.pl';
+#
+use MT;
+my $mt = MT->instance or die MT->errstr;
+
+my $plugin = MT::Plugin::SphinxSearch->instance;
+ok ($plugin, "Unable to load the plugin instance");
+
+my %indexes = $plugin->sphinx_indexes;
+
+ok (exists $indexes{entry}, "Unable to find entry index information");
+
+is (scalar $plugin->which_indexes, 0, "No parameters to which_indexes should return empty list");
+
+my @all_indexer_indexes = $plugin->which_indexes (Indexer => 'all');
+cmp_bag (\@all_indexer_indexes, [ qw( entry_index entry_delta_index comment_index comment_delta_index ) ], "All indexer indexes");
+
+my @main_indexer_indexes = $plugin->which_indexes (Indexer => 'main');
+cmp_bag (\@main_indexer_indexes, [ qw( comment_index entry_index ) ], "Main indexer indexes");
+
+my @delta_indexer_indexes = $plugin->which_indexes (Indexer => 'delta');
+cmp_bag (\@delta_indexer_indexes, [ qw( entry_delta_index comment_delta_index ) ], "Delta indexer indexes");
+
+my @unknown_indexer_indexes = $plugin->which_indexes (Indexer => 'unknown');
+ok (!@unknown_indexer_indexes, "Unknown indexer indexes");
+
+my @entry_indexes = $plugin->which_indexes (Source => 'entry');
+cmp_bag (\@entry_indexes, [ qw( entry_index entry_delta_index ) ], "Entry source indexes");
+
+my @entry_class_indexes = $plugin->which_indexes (Source => 'MT::Entry');
+cmp_bag (\@entry_class_indexes, [ qw( entry_index entry_delta_index ) ], "Entry class source indexes");
+
+my @entry_array_indexes = $plugin->which_indexes (Source => [ 'entry' ]);
+cmp_bag (\@entry_array_indexes, [ qw( entry_index entry_delta_index ) ], "Entry array source indexes");
+
+my @entry_and_comment_indexes = $plugin->which_indexes (Source => [ qw( entry comment ) ]);
+cmp_bag (\@entry_and_comment_indexes, [ qw( entry_index entry_delta_index comment_index comment_delta_index ) ], "Entry and comment source indexes");
76 t/plugins/SphinxSearch/tasks.t
View
@@ -0,0 +1,76 @@
+use File::Spec;
+BEGIN {
+ my $mt_home = $ENV{MT_HOME} || '';
+ unshift @INC, File::Spec->catdir ($mt_home, 'lib'), File::Spec->catdir ($mt_home, 'extlib');
+}
+
+use Test::More tests => 13;
+use Test::Exception;
+use Test::Deep;
+
+use Sub::Install;
+
+use Data::Dumper;
+
+use strict;
+use warnings;
+
+my $fail = 1;
+my @args;
+
+use MT;
+my $mt = MT->instance or die MT->errstr;
+
+
+{
+ local $SIG{__WARN__} = sub {};
+ *MT::Plugin::SphinxSearch::run_cmd = sub {
+ @args = @_;
+ shift @args; # don't need the first one
+ return $fail ? $fail : $_[0]->error ("Testing!");
+ };
+}
+
+my $plugin = MT::Plugin::SphinxSearch->instance;
+ok ($plugin, "Unable to load the plugin instance");
+
+# first, let's test start_indexer
+ok ( $plugin->start_indexer, 'start_indexer should return true if launching succeeds' );
+
+$fail = 0;
+ok (!$plugin->start_indexer, 'start_indexer should return false if launching fails');
+
+$fail = 1;
+
+$plugin->start_indexer;
+my @indexes = grep { /_index/ } split (/\s+/, join (' ' , @args));
+cmp_bag (\@indexes, [qw( entry_index comment_index )], "Entry and comment indexes present for unspecified indexer");
+
+$plugin->start_indexer ('delta');
+@indexes = grep { /_index/ } split (/\s+/, join (' ' , @args));
+cmp_bag (\@indexes, [qw( entry_delta_index comment_delta_index )], "Entry and comment delta indexes present");
+
+$plugin->start_indexer ('all');
+@indexes = grep { /_index/ } split (/\s+/, join (' ' , @args));
+cmp_bag (\@indexes, [ qw( entry_index entry_delta_index comment_index comment_delta_index )], "All indexes being indexed");
+
+ok (!$plugin->start_indexer ('gobbledeegook'), "start_indexer with garbage argument should return false");
+
+$fail = 0;
+throws_ok { $plugin->sphinx_indexer_task ('main') } qr/Error starting [^:]*: Testing!/;
+
+$fail = 1;
+lives_ok { $plugin->sphinx_indexer_task ('main') } 'sphinx_indexer_task should live if launching succeeds';
+
+@indexes = grep { /_index/ } split (/\s+/, join (' ' , @args));
+cmp_bag (\@indexes, [qw( entry_index comment_index )], "Entry and comment indexes present for sphinx_indexer_task");
+
+$fail = 0;
+throws_ok { $plugin->sphinx_indexer_task ('delta') } qr/Error starting [^:]*: Testing!/;
+
+$fail = 1;
+lives_ok { $plugin->sphinx_indexer_task ('delta') } 'delta_indexer_task should live if launching succeeds';
+
+
+@indexes = grep { /_index/ } split (/\s+/, join (' ' , @args));
+cmp_bag (\@indexes, [qw( entry_delta_index comment_delta_index )], "Entry and comment delta indexes not present");
Please sign in to comment.
Something went wrong with that request. Please try again.