]> git.decadent.org.uk Git - maypole.git/blob - t/01basics.t
Change author acknowledge to explicit copyright statement.
[maypole.git] / t / 01basics.t
1 # vim:ft=perl
2 use Test::More;
3 use lib 'ex'; # Where BeerDB should live
4 BEGIN {
5     eval { require BeerDB };
6     Test::More->import( skip_all =>
7         "SQLite not working or BeerDB module could not be loaded: $@"
8     ) if $@;
9
10     plan tests => 15;
11 }
12 use Maypole::CLI qw(BeerDB);
13 use Maypole::Constants;
14 $ENV{MAYPOLE_TEMPLATES} = "t/templates";
15
16 isa_ok( (bless {},"BeerDB") , "Maypole");
17
18 # Test the effect of trailing slash on config->uri_base and request URI
19 (my $uri_base = BeerDB->config->uri_base) =~ s:/$::;
20 BeerDB->config->uri_base($uri_base);
21 like(BeerDB->call_url("http://localhost/beerdb/"), qr/frontpage/,
22      "Got frontpage, trailing '/' on request but not uri_base");
23 like(BeerDB->call_url("http://localhost/beerdb"), qr/frontpage/,
24      "Got frontpage, no trailing '/' on request or uri_base");
25 BeerDB->config->uri_base($uri_base . '/');
26 like(BeerDB->call_url("http://localhost/beerdb/"), qr/frontpage/,
27      "Got frontpage, trailing '/' on uri_base and request");
28 like(BeerDB->call_url("http://localhost/beerdb"), qr/frontpage/,
29      "Got frontpage, trailing '/' on uri_base but not request");
30
31 like(BeerDB->call_url("http://localhost/beerdb/beer/list"), qr/Organic Best/, "Found a beer in the list");
32 my (%classdata)=split /\n/, BeerDB->call_url("http://localhost/beerdb/beer/classdata");
33 is ($classdata{plural},'beers','classdata.plural');
34 is ($classdata{moniker},'beer','classdata.moniker');
35 like ($classdata{cgi},qr/^HTML::Element/,'classdata.cgi');
36 is ($classdata{table},'beer','classdata.table');
37 is ($classdata{name},'BeerDB::Beer','classdata.name');
38 is ($classdata{colnames},'Abv','classdata.colnames');
39 is($classdata{columns}, 'abv brewery id name notes price score style url',
40    'classdata.columns');
41 is($classdata{list_columns}, 'score name price style brewery url',
42    'classdata.list_columns');
43 is ($classdata{related_accessors},'pubs','classdata.related_accessors');
44