Permalink
Browse files

nuff web integration tests for now

  • Loading branch information...
1 parent 08e7c6e commit 0391104b193d98c09ec590bf2fc07979e9ac1d4a @memowe memowe committed Apr 8, 2011
Showing with 50 additions and 16 deletions.
  1. +7 −8 bootylite.pl
  2. +43 −8 t/10-web.t
View
@@ -139,11 +139,13 @@
@@ tag.html.ep
% layout 'bootyblack';
% title config('name') . ' - ' . $tag;
+<h1>Tag <%= $tag %></h1>
%= include 'list_articles', single => 0
@@ tags.html.ep
% layout 'bootyblack';
% title config('name') . ' - Tagcloud';
+<h1>All tags</h1>
<div id="tags">
% foreach my $tag (@$tags) {
% my $ratio = config('tag_cloud_scale') * $amount->{$tag} / $sum;
@@ -162,16 +164,13 @@
@@ show_article.html.ep
<div class="article">
-% my $hl_tag = $single ? 'h1' : 'h2';
- <<%= $hl_tag %>>
-% unless ($single) {
- <a href="<%= url_for 'article', article_url => $article->url %>">
-% }
+% if ($single) {
+ <h1><%= $article->meta->{title} %></h1>
+% } else {
+ <h2><a href="<%= url_for 'article', article_url => $article->url %>">
<%= $article->meta->{title} =%>
-% unless ($single) {
- </a>
+ </a></h2>
% }
- </<%= $hl_tag %>>
<div class="meta">
<span class="time"><%= date $article %></span>,
<span class="tags">Tags:
View
@@ -4,7 +4,7 @@ use strict;
use warnings;
use utf8;
-use Test::More tests => 100;
+use Test::More tests => 46;
use Test::Mojo;
use FindBin '$Bin';
@@ -29,13 +29,11 @@ like($t->tx->req->url, qr|/index.html$|, 'got /index.html');
$t->text_is('title' => $t->app->config('name'));
$t->element_exists('div#articles');
my @articles = reverse @{$t->app->booty->articles};
-foreach my $i (1 .. $#articles+1) {
- my $url = $articles[$i-1]->url;
- my $title = $articles[$i-1]->meta->{title} // '';
- $t->text_like(
- "div.article:nth-child($i) h2 a[href\$=article/$url]",
- qr/$title/,
- );
+foreach my $i (0 .. $#articles) {
+ my $url = $articles[$i]->url;
+ my $title = $articles[$i]->meta->{title} // '';
+ my $n = $i + 1;
+ $t->text_like(".article:nth-child($n) a[href\$=article/$url]", qr/$title/);
}
is(
$t->tx->res->dom->at('div.article:first-child .teaser p')->all_text,
@@ -46,4 +44,41 @@ $t->text_is('div.article:nth-child(2) .teaser p', '€');
$t->text_is('div.article:nth-child(3) .teaser p', '');
$t->text_is('div.article:nth-child(4) .teaser p', '');
+# latest article
+my $url = '/article/' . $articles[0]->url;
+$t->get_ok($url)->text_is('h1', 'Test that shit, yo!');
+$t->element_exists('.teaser')->element_exists('#content');
+
+# tag search
+$t->get_ok('/tag/foo')->text_is('h1', 'Tag foo')->element_exists('#articles');
+my $articles = $t->tx->res->dom->at('#articles')->children;
+is(scalar(@$articles), 2, 'found two articles');
+
+# tag cloud
+$t->get_ok('/tags')->text_is('h1', 'All tags')->element_exists('#tags');
+foreach my $tag (qw(foo bar baz)) {
+ $t->text_is("#tags a[href\$=/tag/$tag]", $tag);
+}
+
+# atom feed
+@articles = reverse @{$t->app->booty->articles};
+$t->get_ok('/index.xml')->content_type_like(qr/xml/);
+my $encoding = $t->app->config('encoding');
+like(
+ $t->tx->res->body,
+ qr/<\?xml version="1\.0" encoding="$encoding"\?>/,
+ 'right feed encoding'
+);
+$t->text_is('title', $t->app->config('name'));
+$t->text_is('author name', $t->app->config('author'));
+my $feed_dom = $t->tx->res->dom;
+$articles = $feed_dom->find('feed entry');
+is(scalar(@$articles), scalar(@articles), 'right number of articles in feed');
+foreach my $i (0 .. $#articles) {
+ my $url = $articles[$i]->url;
+ my $title = $articles[$i]->meta->{title} // '';
+ ok(defined($articles->[$i]->at("link[href\$=/article/$url]")), 'right url');
+ is($articles->[$i]->at('title')->text, $title, 'right title');
+}
+
__END__

0 comments on commit 0391104

Please sign in to comment.