]> git.decadent.org.uk Git - maypole.git/blob - t/01basics.t
fixed tests, fixed syntax error in Apache::MVC
[maypole.git] / t / 01basics.t
1 #!/usr/bin/perl -w
2 use Test::More;
3 use Data::Dumper;
4 use lib 'examples'; # Where BeerDB should live
5 BEGIN {
6     $ENV{BEERDB_DEBUG} = 0;
7
8     eval { require BeerDB };
9     Test::More->import( skip_all =>
10         "SQLite not working or BeerDB module could not be loaded: $@"
11     ) if $@;
12
13     plan tests => 18;
14     
15 }
16 use Maypole::CLI qw(BeerDB);
17 use Maypole::Constants;
18 $ENV{MAYPOLE_TEMPLATES} = "t/templates";
19
20 isa_ok( (bless {},"BeerDB") , "Maypole");
21
22 # Test the effect of trailing slash on config->uri_base and request URI
23 (my $uri_base = BeerDB->config->uri_base) =~ s:/$::;
24 BeerDB->config->uri_base($uri_base);
25 like(BeerDB->call_url("http://localhost/beerdb/"), qr/frontpage/,
26      "Got frontpage, trailing '/' on request but not uri_base");
27 like(BeerDB->call_url("http://localhost/beerdb"), qr/frontpage/,
28      "Got frontpage, no trailing '/' on request or uri_base");
29 BeerDB->config->uri_base($uri_base . '/');
30 like(BeerDB->call_url("http://localhost/beerdb/"), qr/frontpage/,
31      "Got frontpage, trailing '/' on uri_base and request");
32 like(BeerDB->call_url("http://localhost/beerdb"), qr/frontpage/,
33      "Got frontpage, trailing '/' on uri_base but not request");
34
35 like(BeerDB->call_url("http://localhost/beerdb/beer/list"), qr/Organic Best/, "Found a beer in the list");
36
37 my $classdata_page = BeerDB->call_url("http://localhost/beerdb/beer/classdata");
38 my (%classdata)=split /\n+/, $classdata_page;
39 #warn $classdata_page;
40 #warn Dumper(%classdata);
41
42 is ($classdata{plural},'beers','classdata.plural');
43 is ($classdata{moniker},'beer','classdata.moniker');
44 like ($classdata{cgi},qr/^HTML::Element/,'classdata.cgi');
45 is ($classdata{table},'beer','classdata.table');
46 is ($classdata{name},'BeerDB::Beer','classdata.name');
47 is ($classdata{colnames},'Abv','classdata.colnames');
48 is($classdata{columns}, 'abv brewery id name notes price score style tasted url',
49    'classdata.columns');
50 is($classdata{list_columns}, 'score name price style brewery url',
51    'classdata.list_columns');
52 is ($classdata{related_accessors},'pubs','classdata.related_accessors');
53
54 # test Maypole::load_custom_class()
55 can_ok(BeerDB::Beer => 'fooey');     # defined in BeerDB::Beer
56 can_ok(BeerDB::Beer => 'floob');     # defined in BeerDB::Base
57
58 is_deeply( [@BeerDB::Beer::ISA], [qw/Class::DBI::SQLite  Maypole::Model::CDBI BeerDB::Base/] );