aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/t
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/t')
-rwxr-xr-xperllib/t/Cobrand.t33
-rw-r--r--perllib/t/Cobrands/Mysite/Util.pm28
-rw-r--r--perllib/t/MockQuery.pm28
-rwxr-xr-xperllib/t/Page.t49
-rw-r--r--perllib/t/templates/mysite/test-header1
5 files changed, 133 insertions, 6 deletions
diff --git a/perllib/t/Cobrand.t b/perllib/t/Cobrand.t
new file mode 100755
index 000000000..36ec9fefa
--- /dev/null
+++ b/perllib/t/Cobrand.t
@@ -0,0 +1,33 @@
+#!/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-26 16:52:14 louise Exp $
+#
+
+use strict;
+use warnings;
+use Test::More tests => 2;
+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');
+ my ($html, $params) = Cobrand::cobrand_page($q);
+ like($html, qr/A cobrand produced page/, 'cobrand_page returns output from cobrand module');
+ return 1;
+}
+
+
+ok(test_cobrand_page() == 1, 'Ran all tests for the cobrand_page function');
diff --git a/perllib/t/Cobrands/Mysite/Util.pm b/perllib/t/Cobrands/Mysite/Util.pm
new file mode 100644
index 000000000..61f6fd831
--- /dev/null
+++ b/perllib/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-26 16:52:15 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/perllib/t/MockQuery.pm b/perllib/t/MockQuery.pm
new file mode 100644
index 000000000..a6cd3ff78
--- /dev/null
+++ b/perllib/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-26 16:52:14 louise Exp $
+#
+
+
+package MockQuery;
+
+sub new{
+ my $class = shift;
+ my $self = {
+ site => shift,
+ };
+ bless $self, $class;
+ return $self;
+}
+
+sub header{
+
+}
+
+1;
diff --git a/perllib/t/Page.t b/perllib/t/Page.t
index fc01697ed..2890dda1e 100755
--- a/perllib/t/Page.t
+++ b/perllib/t/Page.t
@@ -6,16 +6,53 @@
# 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-25 10:28:50 louise Exp $
+# $Id: Page.t,v 1.2 2009-08-26 16:52:14 louise Exp $
#
use strict;
use warnings;
-
-use Test::More tests => 1;
+use Test::More tests => 4;
+use Test::Exception;
use FindBin;
-use lib "$FindBin::Bin/..";
-use lib "$FindBin::Bin/../../../perllib";
+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;
+}
-BEGIN { use_ok('Page'); } \ No newline at end of file
+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/perllib/t/templates/mysite/test-header b/perllib/t/templates/mysite/test-header
new file mode 100644
index 000000000..83d959d3d
--- /dev/null
+++ b/perllib/t/templates/mysite/test-header
@@ -0,0 +1 @@
+My test header template