Config test
[scpubgit/App-SCS.git] / t / 03config.t
1 use strictures 1;
2 use Test::More;
3 use App::SCS;
4 use IO::All;
5
6 my $app = App::SCS->new(
7   config => { root_dir => 't/data' }
8 );
9
10 my $config1 = $app->pages->get({ path => 'config/1' });
11
12 ok($config1, 'Got a page object');
13
14 is(
15   $config1->html,
16   io->file('t/data/share/pages/config/1.html')->all,
17   "Correct file loaded"
18 );
19
20 my @page_plugins = @{$config1->_page_plugins};
21
22 is(scalar(@page_plugins), 3, 'Three plugins applied');
23
24 my ($tp, $pdp, $tp2) = @page_plugins;
25
26 ok(
27   $tp->isa('App::SCS::Plugin::Core::PagePlugin::Template'),
28   'Template plugin'
29 );
30
31 is($tp->name, 'layout', 'Template name');
32
33 ok(
34   $pdp->isa('App::SCS::Plugin::Core::PagePlugin::PageData'),
35   'PageData plugin'
36 );
37
38 ok(
39   $tp2->isa('App::SCS::Plugin::Core::PagePlugin::Template'),
40   'Alternate template plugin plugin'
41 );
42
43 is ($tp2->name, 'alternate', 'alternate template');
44
45 like(
46   $config1->_html_zoom->to_html,
47   qr{<h1>Alternate layout</h1>.*<h2>A different layout should be used\.</h2>}s,
48   'Layout woven correctly'
49 );
50
51 my $config2 = $app->pages->get({ path => 'config/2' });
52
53 ok($config2, 'Got a page object');
54
55 is(
56   $config2->html,
57   io->file('t/data/share/pages/config/2.html')->all,
58   "Correct file loaded"
59 );
60
61 @page_plugins = @{$config2->_page_plugins};
62
63 is(scalar(@page_plugins), 4, 'Four plugins applied');
64
65 my $tp3;
66
67 ($tp, $pdp, $tp2, $tp3) = @page_plugins;
68
69 ok(
70   $tp->isa('App::SCS::Plugin::Core::PagePlugin::Template'),
71   'Template plugin'
72 );
73
74 is($tp->name, 'layout', 'Template name');
75
76 ok(
77   $pdp->isa('App::SCS::Plugin::Core::PagePlugin::PageData'),
78   'PageData plugin'
79 );
80
81 ok(
82   $tp2->isa('App::SCS::Plugin::Core::PagePlugin::Template'),
83   'Plugin from metadata'
84 );
85
86 is ($tp2->name, 'third', 'plugin from metadata');
87
88 ok(
89   $tp3->isa('App::SCS::Plugin::Core::PagePlugin::Template'),
90   'plugin from config'
91 );
92
93 is ($tp3->name, 'alternate', 'plugin from config');
94
95 like(
96   $config2->_html_zoom->to_html,
97   qr{<h1>Alternate layout</h1>.*<h3>A third layout</h3>}s,
98   'Layout woven correctly'
99 );
100
101 my $config3 = $app->pages->get({ path => 'config2/1' });
102
103 ok($config3, 'Got a page object');
104
105 is(
106   $config3->html,
107   io->file('t/data/share/pages/config2/1.html')->all,
108   "Correct file loaded"
109 );
110
111 @page_plugins = @{$config3->_page_plugins};
112
113 is(scalar(@page_plugins), 3, 'Three plugins applied');
114
115 ($tp, $pdp, $tp2) = @page_plugins;
116
117 ok(
118   $tp->isa('App::SCS::Plugin::Core::PagePlugin::Template'),
119   'Template plugin'
120 );
121
122 is($tp->name, 'layout', 'Template name');
123
124 ok(
125   $pdp->isa('App::SCS::Plugin::Core::PagePlugin::PageData'),
126   'PageData plugin'
127 );
128
129 ok(
130   $tp2->isa('App::SCS::Plugin::Core::PagePlugin::Template'),
131   'Alternate template plugin plugin'
132 );
133
134 is ($tp2->name, 'third', 'metadata template');
135
136 like ($config3->_html_zoom->to_html,
137   qr{<h3>A third layout</h3>.*<p>Only the third layout should be used</p>}s,
138   'Layout woven correctly'
139 );
140
141 done_testing;