diff options
Diffstat (limited to 't')
-rwxr-xr-x | t/Cobrand.t | 40 | ||||
-rw-r--r-- | t/Cobrands/Mysite/Util.pm | 28 | ||||
-rw-r--r-- | t/MockQuery.pm | 28 | ||||
-rwxr-xr-x | t/Page.t | 58 | ||||
-rw-r--r-- | t/templates/mysite/test-header | 1 |
5 files changed, 155 insertions, 0 deletions
diff --git a/t/Cobrand.t b/t/Cobrand.t new file mode 100755 index 000000000..95f3ac73b --- /dev/null +++ b/t/Cobrand.t @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w +# +# Cobrand.t: +# Tests for the cobranding functions +# +# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. +# Email: louise@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: Cobrand.t,v 1.1 2009-08-27 08:42:46 louise Exp $ +# + +use strict; +use warnings; +use Test::More tests => 3; +use Test::Exception; + +use FindBin; +use lib "$FindBin::Bin"; +use lib "$FindBin::Bin/../perllib"; +use lib "$FindBin::Bin/../../perllib"; + +use Cobrand; +use MockQuery; + +sub test_cobrand_page{ + my $q = new MockQuery('mysite'); + # should get the result of the page function in the cobrand module if one exists + my ($html, $params) = Cobrand::cobrand_page($q); + like($html, qr/A cobrand produced page/, 'cobrand_page returns output from cobrand module'); + + # should return 0 if no cobrand module exists + $q = new MockQuery('mynonexistingsite'); + ($html, $params) = Cobrand::cobrand_page($q); + is($html, 0, 'cobrand_page returns 0 if there is no cobrand module'); + return 1; + +} + + +ok(test_cobrand_page() == 1, 'Ran all tests for the cobrand_page function'); diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm new file mode 100644 index 000000000..b37d3cdf3 --- /dev/null +++ b/t/Cobrands/Mysite/Util.pm @@ -0,0 +1,28 @@ +#!/usr/bin/perl -w +# +# Util.pm: +# Test Cobranding for FixMyStreet. +# +# +# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. +# Email: louise@mysociety.org. WWW: http://www.mysociety.org +# +# $Id: Util.pm,v 1.1 2009-08-27 08:42:46 louise Exp $ + +package Cobrands::Mysite::Util; +use Page; +use strict; +use Carp; +use mySociety::Web qw(ent); + +sub new{ + my $class = shift; + return bless {}, $class; +} + +sub page{ + my %params = (); + return ("A cobrand produced page", %params); +} + +1; diff --git a/t/MockQuery.pm b/t/MockQuery.pm new file mode 100644 index 000000000..0574c1ccc --- /dev/null +++ b/t/MockQuery.pm @@ -0,0 +1,28 @@ +#!/usr/bin/perl -w +# +# MockQuery.pm: +# Mock query to support tests for the Page functions +# +# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. +# Email: louise@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: MockQuery.pm,v 1.1 2009-08-27 08:42:46 louise Exp $ +# + + +package MockQuery; + +sub new{ + my $class = shift; + my $self = { + site => shift, + }; + bless $self, $class; + return $self; +} + +sub header{ + +} + +1; diff --git a/t/Page.t b/t/Page.t new file mode 100755 index 000000000..4a79267fc --- /dev/null +++ b/t/Page.t @@ -0,0 +1,58 @@ +#!/usr/bin/perl -w +# +# Page.t: +# Tests for the Page functions +# +# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. +# Email: louise@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: Page.t,v 1.1 2009-08-27 08:42:46 louise Exp $ +# + +use strict; +use warnings; +use Test::More tests => 4; +use Test::Exception; + +use FindBin; +use lib "$FindBin::Bin"; +use lib "$FindBin::Bin/../perllib"; +use lib "$FindBin::Bin/../../perllib"; + +use Page; +use MockQuery; +use mySociety::Locale; + +sub mock_query(){ + my $q = new MockQuery('mysite'); + return $q; +} + +sub test_header(){ + my $q = mock_query(); + my $html; + my %params = (title => 'test title'); + mySociety::Locale::negotiate_language('en-gb,English,en_GB'); + mySociety::Locale::gettext_domain('FixMyStreet'); + mySociety::Locale::change(); + + # Test that param that isn't explicitly allowed raises error + $params{'test-param'} = 'test'; + throws_ok { Page::header($q, %params); } qr/bad parameter/, 'bad parameter caught ok'; + delete $params{'test-param'}; + + # Test that template passed is rendered + $params{'template'} = 'test'; + $html = Page::template_header('My test title', 'test', $q, 'en-gb', '/../t/templates/'); + like ($html, qr/My test header template/, 'named template rendered ok'); + + + return 1; +} + +sub test_footer(){ + return 1; +} + +ok(test_footer() == 1, 'Ran all tests for the footer function'); +ok(test_header() == 1, 'Ran all tests for the header function'); diff --git a/t/templates/mysite/test-header b/t/templates/mysite/test-header new file mode 100644 index 000000000..83d959d3d --- /dev/null +++ b/t/templates/mysite/test-header @@ -0,0 +1 @@ +My test header template |