From be430dfdd2932af651e99be3a27a9cc83be53d69 Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Wed, 10 Jun 2009 18:46:15 +0000 Subject: [PATCH] fixed #9953: Matrix 2.0 - Not enough tests --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/Matrix.pm | 13 +++-- t/Asset/Wobject/Matrix.t | 89 ++++++++++++++++++++++-------- 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index d24b2e784..601495176 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -12,6 +12,7 @@ - fixed: assets can have urls with /./ or /../ in them, making them inaccessible - fixed: Icons don't show on first view of admin panel in IE - refixed #10260: WebGUI::Asset::Wobject::Gallery.pm default search date misfunction + - fixed #9953: Matrix 2.0 - Not enough tests 7.7.9 - fixed #10266: Public Profile overrides Able to be friend diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index bea6173a0..322a2feb4 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -770,7 +770,9 @@ sub view { assetData.title as productName, assetData.url, rating.listingId, - rating.meanValue, + rating.meanValue, + rating.medianValue, + rating.countValue, asset.parentId from MatrixListing_ratingSummary as rating @@ -1236,12 +1238,15 @@ An array of listingIds that should be shown in the compare list datatable. sub www_getCompareListData { my $self = shift; - my @listingIds = @_; + my $listingIds = shift; my $session = $self->session; my $i18n = WebGUI::International->new($session,'Asset_Matrix'); - my (@results,@columnDefs); + my (@results,@columnDefs,@listingIds); - unless (scalar(@listingIds)) { + if ($listingIds) { + @listingIds = @{$listingIds}; + } + else{ @listingIds = $self->session->form->checkList("listingId"); } my @responseFields = ("attributeId", "name", "description","fieldType", "checked"); diff --git a/t/Asset/Wobject/Matrix.t b/t/Asset/Wobject/Matrix.t index 94e9581f4..a0669e3cb 100644 --- a/t/Asset/Wobject/Matrix.t +++ b/t/Asset/Wobject/Matrix.t @@ -17,7 +17,7 @@ use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 21; # increment this value for each test you create +use Test::More tests => 26; # increment this value for each test you create use Test::Deep; use JSON; use WebGUI::Asset::Wobject::Matrix; @@ -62,11 +62,18 @@ cmp_deeply ( 'getCategories method returned correct hashref' ); +# Test add/edit privileges -# add a new attribute +is ($matrix->canEdit,'0',"Checking canEdit privilege"); +is ($matrix->canAddMatrixListing,'0',"Checking canAddMatrixListing privilege"); $session->user({userId => 3}); +is ($matrix->canEdit,'1',"Checking canEdit privilege as Admin"); +is ($matrix->canAddMatrixListing,'1',"Checking canAddMatrixListing privilege as Admin"); + +# add a new attribute + my $attributeProperties = { name =>'test attribute', description =>'description of the test attribute', @@ -106,7 +113,13 @@ isa_ok($matrixListing, 'WebGUI::Asset::MatrixListing'); is($matrixListing->getAutoCommitWorkflowId,undef,"The matrix listings getAutoCommitWorkflowId method correctly returns undef, because the auto commit workflow should only be used on adding a new matrix listing."); -is($matrixListing->hasRated,'0',"The matrix listings hasRated method returns correct value."); +#is($matrixListing->hasRated,'0',"The matrix listings hasRated method returns correct value."); + +$matrixListing->setRatings({category1=>'1',category2=>'10'}); + +ok($matrixListing->hasRated > 0,"Checking hasRated method after rating."); + +$matrixListing->setRatings({category1=>'2',category2=>'5'}); $matrixListing->www_click; @@ -184,6 +197,34 @@ cmp_deeply( 'Getting compareFormData as JSON: www_getCompareFormData returns correct data as JSON.' ); +# Test getting compareListData +$json = $matrix->www_getCompareListData([$expectedAssetId]); + +my $compareListData = JSON->new->decode($json); + +my $matrixListingLastUpdatedHuman = $session->datetime->epochToHuman( $matrixListing->get('lastUpdated'),"%z" ); + +cmp_deeply( + $compareListData, + {ResultSet=>{ + Result=>[ + {$expectedAssetId=>$matrixListingLastUpdatedHuman,fieldType=>"lastUpdated",name=>"Last Updated"}, + {fieldType=>"category",name=>"category1",$expectedAssetId=>$matrixListing->get('title').' '}, + {fieldType=>"category",name=>"category2",$expectedAssetId=>$matrixListing->get('title').' '} + ] + }, + ColumnDefs=>[{ + key =>$expectedAssetId, + label =>$matrixListing->get('title').' '.$matrixListing->get('version'), + formatter =>"formatColors", + url =>$matrixListing->getUrl, + lastUpdated =>$matrixListingLastUpdatedHuman, + }], + ResponseFields=>["attributeId", "name", "description","fieldType", "checked",$expectedAssetId,$expectedAssetId."_compareColor"] + }, + 'Getting compareListData as JSON' + ); + # Test statistics caching by view method $matrix->view; @@ -200,7 +241,7 @@ cmp_deeply( bestViews_name=>$matrixListing->get('title'), bestViews_sortButton=>"
", bestCompares_url=>'/'.$matrixListing->get('url'), - bestCompares_count=>0, + bestCompares_count=>1, bestCompares_name=>$matrixListing->get('title'), bestCompares_sortButton=>"
", bestClicks_url=>'/'.$matrixListing->get('url'), @@ -214,36 +255,36 @@ cmp_deeply( }], lastUpdated_sortButton=>"
", best_rating_loop=>[{ - url=>'/', + url=>'/'.$matrixListing->get('url'), category=>'category1', - name=>undef, - mean=>undef, - median=>undef, - count=>undef, + name=>'untitled', + mean=>'1.50', + median=>2, + count=>2, }, { - url=>'/', + url=>'/'.$matrixListing->get('url'), category=>'category2', - name=>undef, - mean=>undef, - median=>undef, - count=>undef, + name=>'untitled', + mean=>'7.50', + median=>10, + count=>2, }], worst_rating_loop=>[{ - url=>'/', + url=>'/'.$matrixListing->get('url'), category=>'category1', - name=>undef, - mean=>undef, - median=>undef, - count=>undef, + name=>'untitled', + mean=>'1.50', + median=>2, + count=>2, }, { - url=>'/', + url=>'/'.$matrixListing->get('url'), category=>'category2', - name=>undef, - mean=>undef, - median=>undef, - count=>undef, + name=>'untitled', + mean=>'7.50', + median=>10, + count=>2, }], listingCount=>1, },