Config test
Errietta Kostala [Wed, 27 Aug 2014 11:02:19 +0000 (12:02 +0100)]
t/03config.t [new file with mode: 0644]
t/data/share/pages/config.conf [new file with mode: 0644]
t/data/share/pages/config/1.html [new file with mode: 0644]
t/data/share/pages/config/2.html [new file with mode: 0644]
t/data/share/templates/alternate.html [new file with mode: 0644]
t/data/share/templates/layout.html
t/data/share/templates/third.html [new file with mode: 0644]

diff --git a/t/03config.t b/t/03config.t
new file mode 100644 (file)
index 0000000..21a4306
--- /dev/null
@@ -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{<h1>Alternate layout</h1>.*<h2>A different layout should be used\.</h2>}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{<h1>Alternate layout</h1>.*<h3>A third layout</h3>}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{<h3>A third layout</h3>.*<p>Only the third layout should be used</p>}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 (file)
index 0000000..1aadd6c
--- /dev/null
@@ -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 (file)
index 0000000..b1dcf40
--- /dev/null
@@ -0,0 +1,9 @@
+<html >
+  <head>
+    <title>Config 1</title>
+  </head>
+  <body>
+    <h1>Test</h1>
+    <h2>A different layout should be used.</h2>
+  </body>
+</html>
diff --git a/t/data/share/pages/config/2.html b/t/data/share/pages/config/2.html
new file mode 100644 (file)
index 0000000..4ca9e34
--- /dev/null
@@ -0,0 +1,10 @@
+<html >
+  <head>
+    <title>Config 2</title>
+    <meta name="plugins" content="Template, { name: third }" />
+  </head>
+  <body>
+    <h1>Test</h1>
+    <h2>A different layout should be used.</h2>
+  </body>
+  </html>
diff --git a/t/data/share/templates/alternate.html b/t/data/share/templates/alternate.html
new file mode 100644 (file)
index 0000000..9a313bf
--- /dev/null
@@ -0,0 +1,11 @@
+<html data-wrap="html">
+  <head data-wrap="head">
+    <title class="page title" />
+  </head>
+  <body>
+      <div id="content">
+        <h1>Alternate layout</h1>
+        <div data-replace="content-of:body"></div>
+      </div>
+  </body>
+</html>
index 27c4dd5..d1845bd 100644 (file)
@@ -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 (file)
index 0000000..9e6bda3
--- /dev/null
@@ -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>