Added Matrix tests, fixed some bugs

This commit is contained in:
Yung Han Khoe 2008-11-25 07:50:50 +00:00
parent 31dec565b7
commit ee2e0ad48d
2 changed files with 42 additions and 6 deletions

View file

@ -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

View file

@ -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();
}