Trog-Routes-HTML-icon.t 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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::MockModule qw{strict};
  7. use FindBin::libs;
  8. require_ok('Trog::Routes::HTML') or BAIL_OUT("Can't find SUT");
  9. # A tPSGI that records what it was asked to serve.
  10. my @served;
  11. {
  12. package Fake::TPSGI;
  13. sub new { return bless( {}, shift ) }
  14. sub serve ( $, @args ) { @served = @args; return 'served' }
  15. }
  16. subtest 'icon' => sub {
  17. my $themes = Test::MockModule->new('Trog::Themes');
  18. my $query = { route => '/favicon.ico', tpsgi => Fake::TPSGI->new(), ranges => [] };
  19. $themes->redefine( get_dir => sub { '' } );
  20. is( Trog::Routes::HTML::icon($query), 'served', "the icon is served" );
  21. is_deeply( [ @served[ 0, 1 ] ], [ '/favicon.ico', 'www/img/icon/favicon.ico' ], "with no theme, from the file of the stock icon" );
  22. my $original = Trog::Themes->can('themed');
  23. $themes->redefine( themed => sub ($resource) { $resource eq 'img/icon/favicon.ico' ? "www/themes/spec/$resource" : $original->($resource) } );
  24. Trog::Routes::HTML::icon($query);
  25. is( $served[1], 'www/themes/spec/img/icon/favicon.ico', "and from the theme's file where the theme has one" );
  26. };
  27. done_testing();