1# Base functionality 2 3use Test; 4BEGIN { plan tests => 28 }; 5use HTML::Breadcrumbs qw(breadcrumbs); 6 7# Load result strings 8my $test = 't01'; 9my %result = (); 10$test = "t/$test" if -d "t/$test"; 11die "missing data dir $test" unless -d $test; 12opendir DATADIR, "$test" or die "can't open $test"; 13for (readdir DATADIR) { 14 next if m/^\./; 15 open FILE, "<$test/$_" or die "can't read $test/$_"; 16 $result{$_} = <FILE>; 17 chomp $result{$_}; 18 close FILE; 19} 20close DATADIR; 21 22# Procedural interface 23$ENV{SCRIPT_NAME} = '/foo/bar/bog.html'; 24ok($ENV{SCRIPT_NAME} eq '/foo/bar/bog.html'); 25ok(breadcrumbs() eq $result{bog}); 26delete $ENV{SCRIPT_NAME}; 27ok(! exists $ENV{SCRIPT_NAME}); 28ok(! defined eval { breadcrumbs() }); 29ok(! defined eval { breadcrumbs( foo => 1 ) }); 30ok(! defined eval { breadcrumbs( path => 'foo' ) }); 31ok(breadcrumbs(path => '/foo/bar/bog.html') eq $result{bog}); 32ok(breadcrumbs(path => '/foo/bar/') eq $result{bar}); 33ok(breadcrumbs(path => '/foo/bar') eq $result{bar}); 34ok(breadcrumbs(path => '/foo/') eq $result{foo}); 35ok(breadcrumbs(path => '/foo') eq $result{foo}); 36ok(breadcrumbs(path => '/') eq $result{home}); 37ok(breadcrumbs(path => '/cgi-bin/barBar/bar345/bog.html') eq $result{bog2}); 38ok(breadcrumbs(path => '/Level 1/The Next Level/bar/bog.html') eq $result{bog3}); 39 40# OO interface 41$ENV{SCRIPT_NAME} = '/foo/bar/bog.html'; 42ok($ENV{SCRIPT_NAME} eq '/foo/bar/bog.html'); 43ok(HTML::Breadcrumbs->new()->render() eq $result{bog}); 44delete $ENV{SCRIPT_NAME}; 45ok(! exists $ENV{SCRIPT_NAME}); 46ok(! defined eval { HTML::Breadcrumbs->new()->render() }); 47ok(! defined eval { HTML::Breadcrumbs->new( foo => 1 ) }); 48ok(! defined eval { HTML::Breadcrumbs->new( path => 'foo' )->render() }); 49ok(HTML::Breadcrumbs->new(path => '/foo/bar/bog.html')->render() eq $result{bog}); 50ok(HTML::Breadcrumbs->new(path => '/foo/bar/')->render() eq $result{bar}); 51ok(HTML::Breadcrumbs->new(path => '/foo/bar')->render() eq $result{bar}); 52ok(HTML::Breadcrumbs->new(path => '/foo/')->to_string() eq $result{foo}); 53ok(HTML::Breadcrumbs->new(path => '/foo')->render() eq $result{foo}); 54ok(HTML::Breadcrumbs->new(path => '/')->to_string() eq $result{home}); 55ok(HTML::Breadcrumbs->new(path => '/cgi-bin/barBar/bar345/bog.html')->render() eq $result{bog2}); 56ok(HTML::Breadcrumbs->new(path => '/Level 1/The Next Level/bar/bog.html')->render() eq $result{bog3}); 57