From ee2e0ad48df61163a03099bd606ea87c266b2286 Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Tue, 25 Nov 2008 07:50:50 +0000 Subject: [PATCH] Added Matrix tests, fixed some bugs --- lib/WebGUI/Asset/Wobject/Matrix.pm | 10 ++++---- t/Asset/Wobject/Matrix.t | 38 +++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index b97d4924c..c932bb907 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -415,8 +415,8 @@ purges it's data. sub purge { my $self = shift; - #purge your wobject-specific data here. This does not include fields - # you create for your Matrix asset/wobject table. + + $self->session->db->write("delete from Matrix_attribute where assetId=?",[$self->getId]); return $self->SUPER::purge; } @@ -894,7 +894,7 @@ sub www_getCompareFormData { my $self = shift; my $session = $self->session; my $form = $session->form; - my $sort = $session->scratch->get('sort') || $self->get('defaultSort'); + my $sort = shift || $session->scratch->get('matrixSort') || $self->get('defaultSort'); my $sortDirection = ' asc'; if ( WebGUI::Utility::isIn($sort, qw(revisionDate score)) ) { @@ -1179,7 +1179,7 @@ sub www_setSort { my $self = shift; if(my $sort = $self->session->form->process("sort")){ - $self->session->scratch->set('sort',$sort); + $self->session->scratch->set('matrixSort',$sort); } return undef; } @@ -1188,7 +1188,7 @@ sub www_setSort { =head2 www_setStickied ( ) -Sets the sort scratch variable. +Sets the stickied scratch variable. =cut diff --git a/t/Asset/Wobject/Matrix.t b/t/Asset/Wobject/Matrix.t index 4fc36012b..eaa90cee4 100644 --- a/t/Asset/Wobject/Matrix.t +++ b/t/Asset/Wobject/Matrix.t @@ -17,8 +17,9 @@ use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 10; # increment this value for each test you create +use Test::More tests => 12; # increment this value for each test you create use Test::Deep; +use JSON; use WebGUI::Asset::Wobject::Matrix; my $session = WebGUI::Test->session; @@ -91,8 +92,43 @@ is($newAttribute->{attributeId},undef,"The new attribute was successfully delete # TODO: test deleting of listing data for attribute +# add a listing + +my $matrixListing = $matrix->addChild({className=>'WebGUI::Asset::MatrixListing'}); + +my $secondVersionTag = WebGUI::VersionTag->new($session,$matrixListing->get("tagId")); +$secondVersionTag->commit; + +# Test for sane object type +isa_ok($matrixListing, 'WebGUI::Asset::MatrixListing'); + +# Test getting compareFormData including the newly added listing + +$session->user({userId => 3}); +my $json = $matrix->www_getCompareFormData('score'); + +my $compareFormData = JSON->new->utf8->decode($json); + +cmp_deeply( + $compareFormData, + {ResultSet=>{ + Result=>[{ + views=>"0", + lastUpdated=>$matrixListing->get('revisionDate'), + clicks=>"0", + compares=>"0", + assetId=>$matrixListing->getId, + url=>'/'.$matrixListing->get('url'), + title=>$matrixListing->get('title') + }] + } + }, + 'Getting compareFormData as JSON: www_getCompareFormData returns correct data as JSON.' + ); + END { # Clean up after thy self $versionTag->rollback(); + $secondVersionTag->rollback(); }