diff --git a/plugins/Order/t/20-pin.t b/plugins/Order/t/20-pin.t new file mode 100644 index 0000000..75027f6 --- /dev/null +++ b/plugins/Order/t/20-pin.t @@ -0,0 +1,106 @@ +use lib qw( lib extlib plugins/Order/lib ); + +use strict; +use warnings; + +use MT; +use MT::Template::Context; +use MT::Builder; +use MT::App; + +use Test::More tests => 4; + +use Order::Plugin; + +my $cms = MT::App->new; +my $t; + + +sub build { + my ($template, $data) = @_; + my $ctx = MT::Template::Context->new; + my $b = MT::Builder->new; + my $tokens = $b->compile($ctx, $template); + + $ctx->{__stash} = $data; + my $ret = $b->build($ctx, $tokens); + die $b->errstr if !defined $ret; + + return $ret; +} + + +$t = < + + bar + bar + + + 1234 + 1234 + + + foo + foo + + +EOF +like(build($t), qr{ \A \s* 1234 \s+ foo \s+ bar \s* \z }xms, "Pinning an item to 0 puts it in front"); + +$t = < + + bar + bar + + + 1234 + 1234 + + + foo + foo + + +EOF +like(build($t), qr{ \A \s* foo \s+ 1234 \s+ bar \s* \z }xms, "Pinning an item to 1 puts it second"); + +$t = < + + bar + bar + + + 1234 + 1234 + + + foo + foo + + +EOF +like(build($t), qr{ \A \s* foo \s+ 1234 \s+ bar \s* \z }xms, "Pinning an item to -1 puts it last"); + +$t = < + + bar + bar + + + 1234 + 1234 + + + foo + foo + + +EOF +like(build($t), qr{ \A \s* foo \s+ bar \s+ 1234 \s* \z }xms, "Pinning all the items sorts them normally"); + + +1;