From: Marcus Ramberg Date: Tue, 19 Oct 2004 20:07:30 +0000 (+0000) Subject: added test cases for classmetadata. X-Git-Tag: 2.10~121 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=8f6d0577a304bb99d072c9eaf707ab278927bb09;p=maypole.git added test cases for classmetadata. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@241 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/ex/BeerDB.pm b/ex/BeerDB.pm index 3ff1165..26f8e94 100644 --- a/ex/BeerDB.pm +++ b/ex/BeerDB.pm @@ -1,20 +1,21 @@ package BeerDB; -use base 'Maypole::Application'; +use Maypole::Application; use Class::DBI::Loader::Relationship; +BEGIN { # This is the sample application. Change this to the path to your # database. (or use mysql or something) BeerDB->setup("dbi:SQLite:t/beerdb.db"); -#BeerDB->setup("dbi:mysql:beerdb"); +} # Give it a name. -BeerDB->config->{application_name} = 'The Beer Database'; +BeerDB->config->application_name('The Beer Database'); # Change this to the root of the web space. -BeerDB->config->{uri_base} = "http://localhost/beerdb/"; +BeerDB->config->uri_base("http://localhost/beerdb/"); #BeerDB->config->{uri_base} = "http://neo.trinity-house.org.uk/beerdb/"; -BeerDB->config->{rows_per_page} = 10; +BeerDB->config->rows_per_page(10); # Handpumps should not show up. BeerDB->config->{display_tables} = [qw[beer brewery pub style]]; @@ -29,4 +30,13 @@ BeerDB->config->{loader}->relationship($_) for ( "a brewery produces beers", "a style defines beers", "a pub has beers on handpumps"); + +#package BeerDB::Beer; +#our %remember; +#sub MODIFY_CODE_ATTRIBUTES { $remember{ $_[1] } = $_[2]; () } +#sub FETCH_CODE_ATTRIBUTES { $remember{ $_[1] } } + +sub BeerDB::Beer::classdata :Exported {}; +sub BeerDB::Beer::list_columns { return qw/score name price style brewery url/}; + 1; diff --git a/t/01basics.t b/t/01basics.t index 3aaa0e9..9c3d4b9 100644 --- a/t/01basics.t +++ b/t/01basics.t @@ -2,7 +2,7 @@ use Test::More; use lib 'ex'; # Where BeerDB should live BEGIN { if (eval { require BeerDB }) { - plan tests => 3; + plan tests => 12; } else { Test::More->import(skip_all =>"SQLite not working or BeerDB module could not be loaded: $@") } } use Maypole::CLI qw(BeerDB); @@ -13,3 +13,16 @@ isa_ok( (bless {},"BeerDB") , "Maypole"); like(BeerDB->call_url("http://localhost/beerdb/"), qr/frontpage/, "Got the front page"); like(BeerDB->call_url("http://localhost/beerdb/beer/list"), qr/Organic Best/, "Found a beer in the list"); +my (%classdata)=split /\n/, BeerDB->call_url("http://localhost/beerdb/beer/classdata"); +is ($classdata{plural},'beers','classdata.plural'); +is ($classdata{moniker},'beer','classdata.moniker'); +like ($classdata{cgi},qr/^HTML::Element/,'classdata.cgi'); +is ($classdata{table},'beer','classdata.table'); +is ($classdata{name},'BeerDB::Beer','classdata.name'); +is ($classdata{colnames},'Abv','classdata.colnames'); +is($classdata{columns}, 'abv brewery id name notes price score style url', + 'classdata.columns'); +is($classdata{list_columns}, 'score name price style brewery url', + 'classdata.list_columns'); +is ($classdata{related_accessors},'pubs','classdata.related_accessors'); + diff --git a/t/templates/custom/classdata b/t/templates/custom/classdata new file mode 100644 index 0000000..d5f60cc --- /dev/null +++ b/t/templates/custom/classdata @@ -0,0 +1,18 @@ +name +[% classmetadata.name %] +table +[% classmetadata.table %] +columns +[% classmetadata.columns.join(' ')%] +list_columns +[% classmetadata.list_columns.join(' ') %] +colnames +[% classmetadata.colnames.abv %] +related_accessors +[% classmetadata.related_accessors.join(' ') %] +moniker +[% classmetadata.moniker %] +plural +[% classmetadata.plural %] +cgi +[% classmetadata.cgi.abv%]