added testing for DataTable form and asset
This commit is contained in:
parent
d8f28d1379
commit
ac80e166a4
2 changed files with 274 additions and 0 deletions
146
t/Asset/Wobject/DataTable.t
Normal file
146
t/Asset/Wobject/DataTable.t
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2008 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# This tests the DataTable asset
|
||||
#
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
my $node = WebGUI::Asset->getImportNode( $session );
|
||||
|
||||
my $dt;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 1; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Datatable creation
|
||||
use_ok( "WebGUI::Asset::Wobject::DataTable" );
|
||||
my $dt = $node->addChild( {
|
||||
className => 'WebGUI::Asset::Wobject::DataTable',
|
||||
} );
|
||||
isa_ok( $dt, 'WebGUI::Asset::Wobject::DataTable' );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Value and variables
|
||||
my $value = {
|
||||
columns => [
|
||||
{
|
||||
key => "Col1",
|
||||
formatter => "number",
|
||||
},
|
||||
{
|
||||
key => "Col2",
|
||||
formatter => "text",
|
||||
},
|
||||
],
|
||||
rows => [
|
||||
{
|
||||
Col1 => "1",
|
||||
Col2 => "two",
|
||||
},
|
||||
{
|
||||
Col1 => "2",
|
||||
Col2 => "three",
|
||||
},
|
||||
{
|
||||
Col1 => "3",
|
||||
Col2 => "four",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
$dt->update( {
|
||||
data => JSON->new->encode( $value ),
|
||||
} );
|
||||
|
||||
cmp_deeply(
|
||||
JSON->new->decode( $dt->getDataJson ),
|
||||
hash( $value ),
|
||||
"getDataJson returns JSON data structure",
|
||||
);
|
||||
|
||||
cmp_deeply(
|
||||
JSON->new->decode( $dt->www_ajaxGetData ),
|
||||
hash( $value ),
|
||||
"www_ajaxGetData returns JSON data structure",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# getTemplateVars and getDataTemplateVars
|
||||
cmp_deeply(
|
||||
$dt->getDataTemplateVars,
|
||||
hash( {
|
||||
columns => [
|
||||
subhashof( { key => "Col1", formatter => "number" } ),
|
||||
subhashof( { key => "Col2", formatter => "text" } ),
|
||||
],
|
||||
rows => [
|
||||
{
|
||||
row_columns => [
|
||||
subhashof( { key => "Col1", formatter => "number", value => 1 } ),
|
||||
subhashof( { key => "Col2", formatter => "text", value => "two" } ),
|
||||
],
|
||||
Col1 => "1",
|
||||
Col2 => "two",
|
||||
},
|
||||
{
|
||||
row_columns => [
|
||||
subhashof( { key => "Col1", formatter => "number", value => 2 } ),
|
||||
subhashof( { key => "Col2", formatter => "text", value => "three" } ),
|
||||
],
|
||||
Col1 => "2",
|
||||
Col2 => "three",
|
||||
},
|
||||
{
|
||||
row_columns => [
|
||||
subhashof( { key => "Col1", formatter => "number", value => 3 } ),
|
||||
subhashof( { key => "Col2", formatter => "text", value => "four" } ),
|
||||
],
|
||||
Col1 => "3",
|
||||
Col2 => "four",
|
||||
},
|
||||
],
|
||||
} ),
|
||||
"getDataTemplateVars returns complete and correct data structure",
|
||||
);
|
||||
|
||||
cmp_deeply(
|
||||
$dt->getTemplateVars,
|
||||
hash( {
|
||||
%{ $dt->getTemplateVars },
|
||||
%{ $dt->get },
|
||||
url => $dt->getUrl,
|
||||
dataJson => $dt->getDataJson,
|
||||
dataTable => $dt->getDataTable,
|
||||
} ),
|
||||
"getTemplateVars returns complete and correct data structure",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
$dt->purge;
|
||||
}
|
||||
#vim:ft=perl
|
||||
128
t/Form/DataTable.t
Normal file
128
t/Form/DataTable.t
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2008 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Test the API of the DataTable form control
|
||||
#
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 11; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# DataTable creation
|
||||
use_ok( "WebGUI::Form::DataTable" );
|
||||
my $dt = WebGUI::Form::DataTable->new( $session, { } );
|
||||
isa_ok( $dt, 'WebGUI::Form::DataTable' );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Default value
|
||||
cmp_deeply(
|
||||
JSON->new->decode( $dt->getDefaultValue ),
|
||||
{
|
||||
columns
|
||||
=> bag( {
|
||||
key => "New Column",
|
||||
formatter => "text",
|
||||
} ),
|
||||
rows
|
||||
=> bag( {
|
||||
"New Column" => "Value",
|
||||
} ),
|
||||
},
|
||||
"Default value contains proper data structure and dummy data",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# getValue
|
||||
my $value = {
|
||||
columns => [
|
||||
{
|
||||
key => "Col1",
|
||||
formatter => "number",
|
||||
},
|
||||
{
|
||||
key => "Col2",
|
||||
formatter => "text",
|
||||
},
|
||||
],
|
||||
rows => [
|
||||
{
|
||||
Col1 => "1",
|
||||
Col2 => "two",
|
||||
},
|
||||
{
|
||||
Col1 => "2",
|
||||
Col2 => "three",
|
||||
},
|
||||
{
|
||||
Col1 => "3",
|
||||
Col2 => "four",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
# Passing in JSON
|
||||
is( ref $dt->getValue( $value ), '', 'getValue( $value ) returns scalar' );
|
||||
cmp_deeply(
|
||||
JSON->new->decode( $dt->getValue( $value ) ),
|
||||
hash( $value ),
|
||||
'getValue( $value ) returns proper JSON data structure',
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# getOriginalValue
|
||||
# Set at beginning
|
||||
$dt = WebGUI::Form::DataTable->new( $session, {
|
||||
name => "test",
|
||||
value => JSON->new->encode( $value ),
|
||||
id => "test",
|
||||
} );
|
||||
cmp_deeply(
|
||||
JSON->new->decode( $dt->getOriginalValue ),
|
||||
hash( $value ),
|
||||
'getOriginalValue returns proper JSON data structure',
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# getTableHtml
|
||||
my $html = $dt->getTableHtml( JSON->new->decode( $dt->getOriginalValue ) );
|
||||
like( $html, qr{^<div[^>]*class="yui-skin-sam"}, "getTableHtml contains a div with skin class" );
|
||||
like( $html, qr{^<div[^>]*id="test-container"}, "getTableHtml div has ID" );
|
||||
like( $html, qr{<table.*</table>}, "getTableHtml contains a table" );
|
||||
like( $html, qr{<table[^>]*id="test-container-table"}, "getTableHtml table has ID" );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# toHtml
|
||||
my $html = $dt->toHtml;
|
||||
ok( $dt->get( "showEdit" ), "showEdit gets set by toHtml" );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
|
||||
}
|
||||
#vim:ft=perl
|
||||
Loading…
Add table
Add a link
Reference in a new issue