App-Templer
view release on metacpan or search on metacpan
t/test-templer-plugin-filecontents.t view on Meta::CPAN
require_ok('Templer::Site');
BEGIN {use_ok('Templer::Site::Page');}
require_ok('Templer::Site::Page');
BEGIN {use_ok('Templer::Plugin::FileContents');}
require_ok('Templer::Plugin::FileContents');
#
# Create a config file
#
my $site = Templer::Site->new();
#
# Instantiate the helper.
#
my $factory = Templer::Plugin::Factory->new();
ok( $factory, "Loaded the factory object." );
isa_ok( $factory, "Templer::Plugin::Factory" );
#
# Create a temporary tree.
#
my $dir = tempdir( CLEANUP => 1 );
#
# Create a page.
#
open( my $handle, ">", $dir . "/input.wgn" );
print $handle <<EOF;
Title: This is my page title.
Password: read_file( "/etc/passwd" )
Foo: read_file(SELF)
----
This is my page content.
EOF
close($handle);
#
# Create the page
#
my $page = Templer::Site::Page->new( file => $dir . "/input.wgn" );
ok( $page, "We created a page object" );
isa_ok( $page, "Templer::Site::Page", "Which has the correct type" );
#
# Get the title to be sure
#
is( $page->field("title"),
"This is my page title.",
"The page has the correct title" );
#
# Get the data, after plugin-expansion
#
my %original = $page->fields();
my $ref = $factory->expand_variables( $site, $page, \%original );
my %updated = %$ref;
ok( %updated, "Fetching the fields of the page succeeded" );
ok( $updated{ 'password' }, "The fields contain a file reference" );
ok( $updated{ 'foo' }, "The fields contain the self-file reference" );
#
# Do the file contents look sane?
#
ok( $updated{ 'password' } =~ /root:/, "The password file looks sane" );
ok( $updated{ 'foo' } =~ /passwd/, "The self-file looks sane" );
( run in 1.315 second using v1.01-cache-2.11-cpan-39bf76dae61 )