From 7e136f6047f6d4bf2e4c31906a8cccdb32ea33e3 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 20 Sep 2010 15:58:05 -0700 Subject: [PATCH] Begin Test::Class suite for Forms --- t/run_forms.t | 14 ++++++ t/tests/My/Test/Class.pm | 40 +++++++++++++++++ t/tests/Test/WebGUI/Form/Control.pm | 66 +++++++++++++++++++++++++++++ t/tests/Test/WebGUI/Form/Text.pm | 19 +++++++++ t/tests/Test/WebGUI/Form/Url.pm | 19 +++++++++ 5 files changed, 158 insertions(+) create mode 100644 t/run_forms.t create mode 100644 t/tests/My/Test/Class.pm create mode 100644 t/tests/Test/WebGUI/Form/Control.pm create mode 100644 t/tests/Test/WebGUI/Form/Text.pm create mode 100644 t/tests/Test/WebGUI/Form/Url.pm diff --git a/t/run_forms.t b/t/run_forms.t new file mode 100644 index 000000000..beb24c100 --- /dev/null +++ b/t/run_forms.t @@ -0,0 +1,14 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use File::Spec::Functions qw( catdir rel2abs ); +use File::Basename qw( dirname ); +use Test::Class::Load rel2abs( catdir ( dirname( __FILE__ ), 'tests' ) ); +Test::Class->runtests; diff --git a/t/tests/My/Test/Class.pm b/t/tests/My/Test/Class.pm new file mode 100644 index 000000000..b9c230caa --- /dev/null +++ b/t/tests/My/Test/Class.pm @@ -0,0 +1,40 @@ +package My::Test::Class; + +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use lib "$FindBin::Bin/lib"; + +use base qw/Test::Class Class::Data::Inheritable/; + +BEGIN { + __PACKAGE__->mk_classdata('class'); + __PACKAGE__->mk_classdata('session'); +} + +use Test::More; +use Test::Deep; +use Test::Exception; + +use WebGUI::Test; + +sub _00_init : Test(startup => 1) { + my $test = shift; + my $session = WebGUI::Test->session; + $test->session($session); + my $class = ref $test; + $class =~ s/^Test:://; + return ($class . ' is not a WebGUI class') unless $class =~ /^WebGUI/; + $test->class($class); + use_ok $class, "loaded module class $class"; +} + +1 diff --git a/t/tests/Test/WebGUI/Form/Control.pm b/t/tests/Test/WebGUI/Form/Control.pm new file mode 100644 index 000000000..c4d844781 --- /dev/null +++ b/t/tests/Test/WebGUI/Form/Control.pm @@ -0,0 +1,66 @@ +package Test::WebGUI::Form::Control; +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use strict; +use warnings; + +use base qw/My::Test::Class/; + +use Test::More; +use Test::Deep; +use Test::Exception; +use WebGUI::Test; +use Data::Dumper; +use List::MoreUtils; + +sub _constructor : Test(2) { + my $test = shift; + my $session = $test->session; + + my $form = $test->class->new($session); + + note "new for ". $test->class; + isa_ok $form, $test->class; + isa_ok $form->session, 'WebGUI::Session'; +} + +sub t_00_get_set : Test(2) { + my $test = shift; + my $session = $test->session; + + my $form = $test->class->new($session); + + lives_ok { $form->set('name', 'form1'); } 'set name'; + is $form->get('name'), 'form1', 'get name'; + +} + +sub t_01_instanced : Test(1) { + my $test = shift; + my $session = $test->session; + + my $form = $test->class->new($session, { + name => 'form1', + }); + + is $form->get('name'), 'form1', 'name set on instanciation'; +} + +sub t_02_method_check : Test(1) { + my $test = shift; + my $session = $test->session; + + my $form = $test->class->new($session); + + can_ok $form, 'headTags'; +} + +1; diff --git a/t/tests/Test/WebGUI/Form/Text.pm b/t/tests/Test/WebGUI/Form/Text.pm new file mode 100644 index 000000000..aaba3e069 --- /dev/null +++ b/t/tests/Test/WebGUI/Form/Text.pm @@ -0,0 +1,19 @@ +package Test::WebGUI::Form::Text; +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use strict; +use warnings; + +use Test::More; + +use base qw/Test::WebGUI::Form::Control/; + +1; diff --git a/t/tests/Test/WebGUI/Form/Url.pm b/t/tests/Test/WebGUI/Form/Url.pm new file mode 100644 index 000000000..262dc4015 --- /dev/null +++ b/t/tests/Test/WebGUI/Form/Url.pm @@ -0,0 +1,19 @@ +package Test::WebGUI::Form::Url; +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use strict; +use warnings; + +use Test::More; + +use base qw/Test::WebGUI::Form::Text/; + +1;