Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Commit

Permalink
Test pinning a little
Browse files Browse the repository at this point in the history
  • Loading branch information
markpasc committed Dec 5, 2011
1 parent 02d4d5f commit 74e0227
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions plugins/Order/t/20-pin.t
Original file line number Diff line number Diff line change
@@ -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 = <<EOF;
<mt:Order>
<mt:OrderItem>
<mt:setvarblock name="order_by">bar</mt:setvarblock>
bar
</mt:OrderItem>
<mt:OrderItem pin="0">
<mt:setvarblock name="order_by">1234</mt:setvarblock>
1234
</mt:OrderItem>
<mt:OrderItem>
<mt:setvarblock name="order_by">foo</mt:setvarblock>
foo
</mt:OrderItem>
</mt:Order>
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 = <<EOF;
<mt:Order>
<mt:OrderItem>
<mt:setvarblock name="order_by">bar</mt:setvarblock>
bar
</mt:OrderItem>
<mt:OrderItem pin="1">
<mt:setvarblock name="order_by">1234</mt:setvarblock>
1234
</mt:OrderItem>
<mt:OrderItem>
<mt:setvarblock name="order_by">foo</mt:setvarblock>
foo
</mt:OrderItem>
</mt:Order>
EOF
like(build($t), qr{ \A \s* foo \s+ 1234 \s+ bar \s* \z }xms, "Pinning an item to 1 puts it second");

$t = <<EOF;
<mt:Order>
<mt:OrderItem pin="-1">
<mt:setvarblock name="order_by">bar</mt:setvarblock>
bar
</mt:OrderItem>
<mt:OrderItem>
<mt:setvarblock name="order_by">1234</mt:setvarblock>
1234
</mt:OrderItem>
<mt:OrderItem>
<mt:setvarblock name="order_by">foo</mt:setvarblock>
foo
</mt:OrderItem>
</mt:Order>
EOF
like(build($t), qr{ \A \s* foo \s+ 1234 \s+ bar \s* \z }xms, "Pinning an item to -1 puts it last");

$t = <<EOF;
<mt:Order>
<mt:OrderItem pin="0">
<mt:setvarblock name="order_by">bar</mt:setvarblock>
bar
</mt:OrderItem>
<mt:OrderItem pin="0">
<mt:setvarblock name="order_by">1234</mt:setvarblock>
1234
</mt:OrderItem>
<mt:OrderItem pin="0">
<mt:setvarblock name="order_by">foo</mt:setvarblock>
foo
</mt:OrderItem>
</mt:Order>
EOF
like(build($t), qr{ \A \s* foo \s+ bar \s+ 1234 \s* \z }xms, "Pinning all the items sorts them normally");


1;

0 comments on commit 74e0227

Please sign in to comment.