]> git.decadent.org.uk Git - maypole.git/blob - t/01basics.t
added preprocess_location method
[maypole.git] / t / 01basics.t
1 #!/usr/bin/perl -w
2 use Test::More;
3 use lib 'examples'; # Where BeerDB should live
4 BEGIN {
5     $ENV{BEERDB_DEBUG} = 0;
6
7     eval { require BeerDB };
8     Test::More->import( skip_all =>
9         "SQLite not working or BeerDB module could not be loaded: $@"
10     ) if $@;
11
12     plan tests => 18;
13     
14 }
15 use Maypole::CLI qw(BeerDB);
16 use Maypole::Constants;
17 $ENV{MAYPOLE_TEMPLATES} = "t/templates";
18
19 isa_ok( (bless {},"BeerDB") , "Maypole");
20
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");
33
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 tasted url',
43    'classdata.columns');
44 is($classdata{list_columns}, 'score name price style brewery url',
45    'classdata.list_columns');
46 is ($classdata{related_accessors},'pubs','classdata.related_accessors');
47
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
52 is_deeply( [@BeerDB::Beer::ISA], [qw/Class::DBI::SQLite  Maypole::Model::CDBI BeerDB::Base/] );