3 use lib 'ex'; # Where BeerDB should live
5 #$ENV{BEERDB_DEBUG} = 2;
7 eval { require BeerDB };
8 Test::More->import( skip_all =>
9 "SQLite not working or BeerDB module could not be loaded: $@"
15 use Maypole::CLI qw(BeerDB);
16 use Maypole::Constants;
17 $ENV{MAYPOLE_TEMPLATES} = "t/templates";
19 isa_ok( (bless {},"BeerDB") , "Maypole");
21 # Test the effect of trailing slash on config->uri_base and request URI
22 (my $uri_base = BeerDB->config->uri_base) =~ s:/$::;
23 BeerDB->config->uri_base($uri_base);
24 like(BeerDB->call_url("http://localhost/beerdb/"), qr/frontpage/,
25 "Got frontpage, trailing '/' on request but not uri_base");
26 like(BeerDB->call_url("http://localhost/beerdb"), qr/frontpage/,
27 "Got frontpage, no trailing '/' on request or uri_base");
28 BeerDB->config->uri_base($uri_base . '/');
29 like(BeerDB->call_url("http://localhost/beerdb/"), qr/frontpage/,
30 "Got frontpage, trailing '/' on uri_base and request");
31 like(BeerDB->call_url("http://localhost/beerdb"), qr/frontpage/,
32 "Got frontpage, trailing '/' on uri_base but not request");
34 like(BeerDB->call_url("http://localhost/beerdb/beer/list"), qr/Organic Best/, "Found a beer in the list");
35 my (%classdata)=split /\n/, BeerDB->call_url("http://localhost/beerdb/beer/classdata");
36 is ($classdata{plural},'beers','classdata.plural');
37 is ($classdata{moniker},'beer','classdata.moniker');
38 like ($classdata{cgi},qr/^HTML::Element/,'classdata.cgi');
39 is ($classdata{table},'beer','classdata.table');
40 is ($classdata{name},'BeerDB::Beer','classdata.name');
41 is ($classdata{colnames},'Abv','classdata.colnames');
42 is($classdata{columns}, 'abv brewery id name notes price score style url',
44 is($classdata{list_columns}, 'score name price style brewery url',
45 'classdata.list_columns');
46 is ($classdata{related_accessors},'pubs','classdata.related_accessors');
48 # test Maypole::load_custom_class()
49 can_ok(BeerDB::Beer => 'fooey'); # defined in BeerDB::Beer
50 can_ok(BeerDB::Beer => 'floob'); # defined in BeerDB::Base
51 is_deeply( [@BeerDB::Beer::ISA], [qw/Maypole::Model::CDBI Class::DBI::SQLite BeerDB::Base/] );