[Rt-commit] rt branch, new-style-templates, updated. rt-3.8.8-180-g3471978

Shawn Moore sartak at bestpractical.com
Mon Jul 19 19:07:16 EDT 2010


The branch, new-style-templates has been updated
       via  34719789f315646ce8ad3c1adb26c0a8ec13d80b (commit)
      from  853b27898ad04239c3e26df2c7b390b62b9b1a42 (commit)

Summary of changes:
 t/api/template-simple.t |  160 ++++++++++++++---------------------------------
 1 files changed, 48 insertions(+), 112 deletions(-)

- Log -----------------------------------------------------------------
commit 34719789f315646ce8ad3c1adb26c0a8ec13d80b
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Mon Jul 19 19:04:52 2010 -0400

    Refactor the tests to be less repetitive

diff --git a/t/api/template-simple.t b/t/api/template-simple.t
index 4ee8cc9..f96f3f9 100644
--- a/t/api/template-simple.t
+++ b/t/api/template-simple.t
@@ -6,136 +6,72 @@ use RT::Test tests => 37;
 my $ticket = RT::Ticket->new($RT::SystemUser);
 my ($id, $msg) = $ticket->Create(
     Subject   => "template testing",
-    Queue     => 'General',
-    Requestor => ['dom at example.com'],
+    Queue     => "General",
+    Requestor => ["dom\@example.com"],
 );
-ok($id, 'Created ticket');
+ok($id, "Created ticket");
 
-# no interpolation
-{
-    my $t = RT::Template->new($RT::SystemUser);
-    $t->Create(
-        Name => "Foo",
-        Content => "\ntest",
-    );
-    ok($t->id, "Created template");
-    is($t->Name, "Foo");
-    is($t->Content, "\ntest");
-    TODO: {
-        local $TODO = "template types not settled";
-        is($t->Type, "Full");
-    }
-
-    my ($ok, $msg) = $t->Parse(TicketObj => $ticket);
-    ok($ok, $msg);
-    is($t->MIMEObj->stringify_body, "test");
-}
+TemplateTest(
+    Type    => "Full",
+    Content => "\ntest",
+    Output  => "test",
+);
 
-# code interpolation
-{
-    my $t = RT::Template->new($RT::SystemUser);
-    $t->Create(
-        Name => "Foo",
-        Content => "\ntest { 5 * 5 }",
-    );
-    ok($t->id, "Created template");
-    is($t->Name, "Foo");
-    is($t->Content, "\ntest { 5 * 5 }");
-    TODO: {
-        local $TODO = "template types not settled";
-        is($t->Type, "Full");
-    }
+TemplateTest(
+    Type    => "Full",
+    Content => "\ntest { 5 * 5 }",
+    Output  => "test 25",
+);
 
-    my ($ok, $msg) = $t->Parse(TicketObj => $ticket);
-    ok($ok, $msg);
-    is($t->MIMEObj->stringify_body, "test 25");
-}
+TemplateTest(
+    Type    => "Full",
+    Content => "\ntest { \$Requestor }",
+    Output  => "test dom\@example.com",
+);
 
-# variable interpolation
-{
-    my $t = RT::Template->new($RT::SystemUser);
-    $t->Create(
-        Name => "Foo",
-        Content => "\ntest { \$Requestor }",
-    );
-    ok($t->id, "Created template");
-    is($t->Name, "Foo");
-    is($t->Content, "\ntest { \$Requestor }");
-    TODO: {
-        local $TODO = "template types not settled";
-        is($t->Type, "Full");
-    }
+TemplateTest(
+    Type    => "Simple",
+    Content => "\ntest",
+    Output  => "test",
+);
 
-    my ($ok, $msg) = $t->Parse(TicketObj => $ticket);
-    ok($ok, $msg);
-    is($t->MIMEObj->stringify_body, "test dom\@example.com");
-}
+TemplateTest(
+    Type    => "Simple",
+    Content => "\ntest { 5 * 5 }",
+    Output  => "test { 5 * 5 }",
+);
 
-# no interpolation
-{
-    my $t = RT::Template->new($RT::SystemUser);
-    $t->Create(
-        Name    => "Foo",
-        Content => "\ntest",
-        Type    => "Simple",
-    );
-    ok($t->id, "Created template");
-    is($t->Name, "Foo");
-    is($t->Content, "\ntest");
-    TODO: {
-        local $TODO = "template types not settled";
-        is($t->Type, "Simple");
-    }
+TemplateTest(
+    Type    => "Simple",
+    Content => "\ntest { \$Requestor }",
+    Output  => "test dom\@example.com",
+);
 
-    my ($ok, $msg) = $t->Parse(TicketObj => $ticket);
-    ok($ok, $msg);
-    is($t->MIMEObj->stringify_body, "test");
-}
+my $counter = 0;
+sub TemplateTest {
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
 
-# code interpolation
-{
-    my $t = RT::Template->new($RT::SystemUser);
-    $t->Create(
-        Name => "Foo",
-        Content => "\ntest { 5 * 5 }",
-        Type => "Simple",
+    my %args = (
+        Name => "Test-" . ++$counter,
+        Type => "Full",
+        @_,
     );
-    ok($t->id, "Created template");
-    is($t->Name, "Foo");
-    is($t->Content, "\ntest { 5 * 5 }");
-    TODO: {
-        local $TODO = "template types not settled";
-        is($t->Type, "Simple");
-    }
 
-    my ($ok, $msg) = $t->Parse(TicketObj => $ticket);
-    ok($ok, $msg);
-
-    TODO: {
-        local $TODO = "simple templates not yet implemented";
-        is($t->MIMEObj->stringify_body, "test { 5 * 5 }");
-    }
-}
-
-# variable interpolation
-{
     my $t = RT::Template->new($RT::SystemUser);
     $t->Create(
-        Name => "Foo",
-        Content => "\ntest { \$Requestor }",
-        Type => "Simple",
+        Name    => $args{Name},
+        Type    => $args{Type},
+        Content => $args{Content},
     );
+
     ok($t->id, "Created template");
-    is($t->Name, "Foo");
-    is($t->Content, "\ntest { \$Requestor }");
-    TODO: {
-        local $TODO = "template types not settled";
-        is($t->Type, "Simple");
-    }
+    is($t->Name, $args{Name}, "template name");
+    is($t->Content, $args{Content}, "content");
+    is($t->Type, $args{Type}, "template type");
 
     my ($ok, $msg) = $t->Parse(TicketObj => $ticket);
     ok($ok, $msg);
-    is($t->MIMEObj->stringify_body, "test dom\@example.com");
+    is($t->MIMEObj->stringify_body, $args{Output}, "template's output");
 }
 
 1;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list