From: Errietta Kostala Date: Wed, 27 Aug 2014 11:02:19 +0000 (+0100) Subject: Config test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9a9eda29fb1808440febcc954eed93ab59dee3ae;p=scpubgit%2FApp-SCS.git Config test --- diff --git a/t/03config.t b/t/03config.t new file mode 100644 index 0000000..21a4306 --- /dev/null +++ b/t/03config.t @@ -0,0 +1,141 @@ +use strictures 1; +use Test::More; +use App::SCS; +use IO::All; + +my $app = App::SCS->new( + config => { root_dir => 't/data' } +); + +my $config1 = $app->pages->get({ path => 'config/1' }); + +ok($config1, 'Got a page object'); + +is( + $config1->html, + io->file('t/data/share/pages/config/1.html')->all, + "Correct file loaded" +); + +my @page_plugins = @{$config1->_page_plugins}; + +is(scalar(@page_plugins), 3, 'Three plugins applied'); + +my ($tp, $pdp, $tp2) = @page_plugins; + +ok( + $tp->isa('App::SCS::Plugin::Core::PagePlugin::Template'), + 'Template plugin' +); + +is($tp->name, 'layout', 'Template name'); + +ok( + $pdp->isa('App::SCS::Plugin::Core::PagePlugin::PageData'), + 'PageData plugin' +); + +ok( + $tp2->isa('App::SCS::Plugin::Core::PagePlugin::Template'), + 'Alternate template plugin plugin' +); + +is ($tp2->name, 'alternate', 'alternate template'); + +like( + $config1->_html_zoom->to_html, + qr{

Alternate layout

.*

A different layout should be used\.

}s, + 'Layout woven correctly' +); + +my $config2 = $app->pages->get({ path => 'config/2' }); + +ok($config2, 'Got a page object'); + +is( + $config2->html, + io->file('t/data/share/pages/config/2.html')->all, + "Correct file loaded" +); + +@page_plugins = @{$config2->_page_plugins}; + +is(scalar(@page_plugins), 4, 'Four plugins applied'); + +my $tp3; + +($tp, $pdp, $tp2, $tp3) = @page_plugins; + +ok( + $tp->isa('App::SCS::Plugin::Core::PagePlugin::Template'), + 'Template plugin' +); + +is($tp->name, 'layout', 'Template name'); + +ok( + $pdp->isa('App::SCS::Plugin::Core::PagePlugin::PageData'), + 'PageData plugin' +); + +ok( + $tp2->isa('App::SCS::Plugin::Core::PagePlugin::Template'), + 'Plugin from metadata' +); + +is ($tp2->name, 'third', 'plugin from metadata'); + +ok( + $tp3->isa('App::SCS::Plugin::Core::PagePlugin::Template'), + 'plugin from config' +); + +is ($tp3->name, 'alternate', 'plugin from config'); + +like( + $config2->_html_zoom->to_html, + qr{

Alternate layout

.*

A third layout

}s, + 'Layout woven correctly' +); + +my $config3 = $app->pages->get({ path => 'config2/1' }); + +ok($config3, 'Got a page object'); + +is( + $config3->html, + io->file('t/data/share/pages/config2/1.html')->all, + "Correct file loaded" +); + +@page_plugins = @{$config3->_page_plugins}; + +is(scalar(@page_plugins), 3, 'Three plugins applied'); + +($tp, $pdp, $tp2) = @page_plugins; + +ok( + $tp->isa('App::SCS::Plugin::Core::PagePlugin::Template'), + 'Template plugin' +); + +is($tp->name, 'layout', 'Template name'); + +ok( + $pdp->isa('App::SCS::Plugin::Core::PagePlugin::PageData'), + 'PageData plugin' +); + +ok( + $tp2->isa('App::SCS::Plugin::Core::PagePlugin::Template'), + 'Alternate template plugin plugin' +); + +is ($tp2->name, 'third', 'metadata template'); + +like ($config3->_html_zoom->to_html, + qr{

A third layout

.*

Only the third layout should be used

}s, + 'Layout woven correctly' +); + +done_testing; diff --git a/t/data/share/pages/config.conf b/t/data/share/pages/config.conf new file mode 100644 index 0000000..1aadd6c --- /dev/null +++ b/t/data/share/pages/config.conf @@ -0,0 +1,4 @@ +[ + "Template", + { "name":"alternate" } +] diff --git a/t/data/share/pages/config/1.html b/t/data/share/pages/config/1.html new file mode 100644 index 0000000..b1dcf40 --- /dev/null +++ b/t/data/share/pages/config/1.html @@ -0,0 +1,9 @@ + + + Config 1 + + +

Test

+

A different layout should be used.

+ + diff --git a/t/data/share/pages/config/2.html b/t/data/share/pages/config/2.html new file mode 100644 index 0000000..4ca9e34 --- /dev/null +++ b/t/data/share/pages/config/2.html @@ -0,0 +1,10 @@ + + + Config 2 + + + +

Test

+

A different layout should be used.

+ + diff --git a/t/data/share/templates/alternate.html b/t/data/share/templates/alternate.html new file mode 100644 index 0000000..9a313bf --- /dev/null +++ b/t/data/share/templates/alternate.html @@ -0,0 +1,11 @@ + + + + </head> + <body> + <div id="content"> + <h1>Alternate layout</h1> + <div data-replace="content-of:body"></div> + </div> + </body> +</html> diff --git a/t/data/share/templates/layout.html b/t/data/share/templates/layout.html index 27c4dd5..d1845bd 100644 --- a/t/data/share/templates/layout.html +++ b/t/data/share/templates/layout.html @@ -4,7 +4,7 @@ </head> <body> <div id="content"> - <div data-replace="h1" /> + <div data-replace="content-of:body" /> </div> </body> </html> diff --git a/t/data/share/templates/third.html b/t/data/share/templates/third.html new file mode 100644 index 0000000..9e6bda3 --- /dev/null +++ b/t/data/share/templates/third.html @@ -0,0 +1,9 @@ +<html data-wrap="html"> + <head data-wrap="head"> + <title class="page title" /> + </head> + <body> + <h3>A third layout</h3> + <div data-replace="content-of:#content" /> + </body> +</html>