Trog-Renderer-Base.t 1002 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env perl
  2. use 5.040;
  3. use re '/aasx';
  4. use warnings FATAL => 'all';
  5. use Test::More;
  6. use Test::Fatal qw{exception};
  7. use FindBin::libs;
  8. require_ok('Trog::Renderer::Base') or BAIL_OUT("Can't find SUT");
  9. subtest 'render' => sub {
  10. my %options = ( template => 'manual.tx', contenttype => 'text/html', component => 1 );
  11. like(
  12. exception { Trog::Renderer::Base::render( %options, data => {} ) },
  13. qr/disallowed[ ]key[ ]'content'/,
  14. 'a variable that the template reads and data lacks is fatal, and named'
  15. );
  16. my $out;
  17. is( exception { $out = Trog::Renderer::Base::render( %options, data => { content => undef } ) }, undef, 'but one that data has as undef is not' );
  18. like( $out, qr{<div[ ]id="backoffice">\s*</div>}, 'and renders as nothing' );
  19. my %data = ( content => 'x' );
  20. Trog::Renderer::Base::render( %options, data => \%data );
  21. $data{later} = 1;
  22. is( $data{later}, 1, "and the caller's data is not left locked" );
  23. };
  24. done_testing();