Permalink
Browse files

Start testing `books/list` template output

  • Loading branch information...
theory committed Nov 9, 2009
1 parent b171bfb commit 3ece89d196a3688650572285f60c3cf3d5802cbc
Showing with 15 additions and 4 deletions.
  1. +3 −3 lib/MyApp/Templates/HTML/Books.pm
  2. +12 −1 t/view_HTML.t
@@ -11,9 +11,9 @@ template list => sub {
wrapper {
table {
row {
- th { 'Title' };
- th { 'Rating' };
- th { 'Author' };
+ th { 'Title' };
+ th { 'Rating' };
+ th { 'Authors' };
};
my $sth = $args->{books};
while (my $book = $sth->fetchrow_hashref) {
View
@@ -28,12 +28,23 @@ ok my $output = $view->render($c, 'books/list', {
title => 'Book List',
books => $sth,
}), 'Render the "books/list" template';
-diag $output;
+#diag $output;
# Test output using Test::XPath.
my $tx = Test::XPath->new( xml => $output, is_html => 1);
test_basics($tx, 'Book List');
+$tx->ok('/html/body/div[@id="bodyblock"]/div[@id="content"]/table', sub {
+ $_->is('count(./tr)', 6, 'Should have six rows' );
+ $_->ok('./tr[1]', sub {
+ $_->is('count(./th)', 3, 'Should have three table headers');
+ $_->is('./th[1]', 'Title', '... first is "Title"');
+ $_->is('./th[2]', 'Rating', '... second is "Rating"');
+ $_->is('./th[3]', 'Authors', '... third is "Authors"');
+ }, 'Should have first table row')
+}, 'Should have a table');
+
+
# Call this function for every request to make sure that they all
# have the same basic structure.
sub test_basics {

0 comments on commit 3ece89d

Please sign in to comment.