--- /dev/null
+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;