From: Errietta Kostala Date: Wed, 27 Aug 2014 17:16:21 +0000 (+0100) Subject: Cache test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d25345fd96574aa23f2dd39aad975087f0f113a2;p=scpubgit%2FApp-SCS.git Cache test --- diff --git a/Makefile.PL b/Makefile.PL index 3fa8805..b19ee23 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -18,6 +18,7 @@ WriteMakefile( 'Plack::Middleware::SSI' => '0.12', 'JSON::MaybeXS' => 0, 'Hash::Merge' => 0, - 'JSONY' => 0 + 'JSONY' => 0, + 'File::Tempdir' => 0, } ); diff --git a/t/04cache.t b/t/04cache.t new file mode 100644 index 0000000..4475a84 --- /dev/null +++ b/t/04cache.t @@ -0,0 +1,52 @@ +use warnings; +use strict; +use Test::More; +use App::SCS; +use IO::All; + +use File::Tempdir; + +my $tmpdir = File::Tempdir->new(); +my $dir = io($tmpdir->name); + +$dir->catdir('share/pages/cachetest')->mkpath; +$dir->catdir('share/templates')->mkpath; + +io('t/data/cachetest/share/pages/cachetest/1.html') > io($dir->catfile('share/pages/cachetest/1.html')); +io('t/data/cachetest/share/pages/cachetest.conf') > io($dir->catfile('share/pages/cachetest.conf')); +io('t/data/cachetest/share/templates/layout.html') > io($dir->catfile('share/templates/layout.html')); +io('t/data/cachetest/share/templates/alternate.html') > io($dir->catfile('share/templates/alternate.html')); +io('t/data/cachetest/share/templates/third.html') > io($dir->catfile('share/templates/third.html')); + +my $app = App::SCS->new( + root_dir => $dir +); + +my $cachetest1 = $app->pages->get({ path => 'cachetest/1' }); + +ok($cachetest1, 'Got a page object'); + +is( + $cachetest1->html, + io->file('t/data/cachetest/share/pages/cachetest/1.html')->all, + "Correct file loaded" +); + +like ($cachetest1->_html_zoom->to_html, + qr{.*

Heading 2

.*}s, + 'First layout used' +); + +# We want to make sure our config is newer than the cached version +sleep 1; + +io('t/data/cachetest/share/pages/cachetest2.conf') > io($dir->catfile('share/pages/cachetest.conf')); + +$cachetest1 = $app->pages->get({ path => 'cachetest/1' }); + +like ($cachetest1->_html_zoom->to_html, + qr{.*

Heading 3

.*}s, + 'Changing the config invalidates cache, updates content' +); + +done_testing; diff --git a/t/data/cachetest/share/pages/cachetest.conf b/t/data/cachetest/share/pages/cachetest.conf new file mode 100644 index 0000000..1aadd6c --- /dev/null +++ b/t/data/cachetest/share/pages/cachetest.conf @@ -0,0 +1,4 @@ +[ + "Template", + { "name":"alternate" } +] diff --git a/t/data/cachetest/share/pages/cachetest/1.html b/t/data/cachetest/share/pages/cachetest/1.html new file mode 100644 index 0000000..3bbd9f6 --- /dev/null +++ b/t/data/cachetest/share/pages/cachetest/1.html @@ -0,0 +1,10 @@ + + + Config 1 + + +

Heading 1

+

Heading 2

+

Heading 3

+ + diff --git a/t/data/cachetest/share/pages/cachetest2.conf b/t/data/cachetest/share/pages/cachetest2.conf new file mode 100644 index 0000000..b4549fa --- /dev/null +++ b/t/data/cachetest/share/pages/cachetest2.conf @@ -0,0 +1,4 @@ +[ + "Template", + { "name":"third" } +] diff --git a/t/data/cachetest/share/templates/alternate.html b/t/data/cachetest/share/templates/alternate.html new file mode 100644 index 0000000..4a8cfda --- /dev/null +++ b/t/data/cachetest/share/templates/alternate.html @@ -0,0 +1,8 @@ + + + + </head> + <body> + <div data-replace="h2"></div> + </body> +</html> diff --git a/t/data/cachetest/share/templates/layout.html b/t/data/cachetest/share/templates/layout.html new file mode 100644 index 0000000..18e4ce4 --- /dev/null +++ b/t/data/cachetest/share/templates/layout.html @@ -0,0 +1,10 @@ +<html data-wrap="html"> + <head> + <title class="page title" /> + </head> + <body> + <div id="content"> + <div data-replace="body" /> + </div> + </body> +</html> diff --git a/t/data/cachetest/share/templates/third.html b/t/data/cachetest/share/templates/third.html new file mode 100644 index 0000000..8076ac8 --- /dev/null +++ b/t/data/cachetest/share/templates/third.html @@ -0,0 +1,8 @@ +<html data-wrap="html"> + <head data-wrap="head"> + <title class="page title" /> + </head> + <body> + <div data-replace="h3" /> + </body> +</html>