Revert "Separating Thing object from Thingy"

This reverts commit 3d88789659.
This commit is contained in:
Colin Kuskie 2009-11-17 12:12:08 -08:00
parent c99315aa0c
commit a37f69cc04
4 changed files with 263 additions and 542 deletions

View file

@ -16,7 +16,7 @@ use lib "$FindBin::Bin/../../lib";
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 32; # increment this value for each test you create
use Test::More tests => 28; # increment this value for each test you create
use Test::Deep;
use JSON;
use WebGUI::Asset::Wobject::Thingy;
@ -82,10 +82,6 @@ my $isValidId = $session->id->valid($thingId);
is($isValidId,1,"addThing returned a valid id: ".$thingId);
# Test for a sane object type
my $thing = WebGUI::Asset::Wobject::Thingy::Thing->new($session,$thingId);
isa_ok($thing, 'WebGUI::Asset::Wobject::Thingy::Thing');
my $thingTableName = "Thingy_".$thingId;
my ($thingTableNameCheck) = $session->db->quickArray("show tables like ".$session->db->quote($thingTableName));
@ -131,9 +127,6 @@ cmp_deeply(
field_loop=>[],
exportMetaData=>undef,
maxEntriesPerUser=>undef,
dateCreated=>$thing->get('dateCreated'),
lastUpdated=>$thing->get('lastUpdated'),
sequenceNumber=>$thing->get('sequenceNumber'),
},
'Getting newly added thing as JSON: www_getThingViaAjax returns correct data as JSON.'
);
@ -144,7 +137,9 @@ cmp_deeply(
$json = $thingy->www_getThingsViaAjax();
$dataFromJSON = JSON->new->decode($json);
my $thingPropertiesHashRef = {
cmp_deeply(
$dataFromJSON,
[{
assetId=>$thingy->getId,
thingId=>$thingId,
label=>$i18n->get('assetName'),
@ -175,19 +170,10 @@ my $thingPropertiesHashRef = {
canSearch=>1,
exportMetaData=>undef,
maxEntriesPerUser=>undef,
dateCreated=>$thing->get('dateCreated'),
lastUpdated=>$thing->get('lastUpdated'),
sequenceNumber=>$thing->get('sequenceNumber'),
};
cmp_deeply(
$dataFromJSON,
[$thingPropertiesHashRef
],
}],
'Getting all things in Thingy as JSON: www_getThingsViaAjax returns correct data as JSON.'
);
# Test adding a field
@ -214,62 +200,18 @@ my ($fieldLabel, $columnType, $Null, $Key, $Default, $Extra) = $session->db->qui
is($fieldLabel,"field_".$fieldId,"A column for the new field Field_$fieldId exists.");
is($columnType,"longtext","The columns is the right type");
# Test export function
# Test duplicating a Thing
my $exportData = $thingy->exportAssetData;
my $copyThingId = $thingy->duplicateThing($thingId);
delete $exportData->{properties};
delete $exportData->{storage};
$isValidId = $session->id->valid($copyThingId);
my $thingDatabasePropertiesHashRef = $thingPropertiesHashRef;
delete $thingDatabasePropertiesHashRef->{canAdd};
delete $thingDatabasePropertiesHashRef->{canEdit};
delete $thingDatabasePropertiesHashRef->{canSearch};
my $field = $session->db->quickHashRef('select * from Thingy_fields where fieldId=?',[$fieldId]);
cmp_deeply(
$exportData,
{
things=>[
$thingDatabasePropertiesHashRef
],
fields=>[
$field
]
},
'Export returns correct data.'
);
# Test duplicating and deleting a Thing
my $duplicateThingId = $thingy->duplicateThing($thingId);
$isValidId = $session->id->valid($duplicateThingId);
is($isValidId,1,"duplicating a Thing: duplicateThing returned a valid id: ".$duplicateThingId);
my $duplicateThing = WebGUI::Asset::Wobject::Thingy::Thing->new($session, $duplicateThingId);
if (defined $duplicateThing) {
$duplicateThing->delete;
}
my @things = @{ WebGUI::Asset::Wobject::Thingy::Thing->getAllIds($session,{constraints => [
{"assetId=?" => $thingy->getId},
]}) };
is(scalar @things,1,'Duplicated thing was deleted succesfully');
my ($thingTableCheck) = $session->db->quickArray("show tables like ?",['Thingy_'.$duplicateThingId]);
is($thingTableCheck,undef,"New table for duplicate Thing was deleted.");
ok($isValidId, "duplicating a Thing: duplicateThing returned a valid id: ".$copyThingId);
# Test adding, editing, getting and deleting thing data
is($thing->hasEnteredMaxPerUser,0,"hasEnteredMaxPerUser returns 0 before adding a record");
my ($newThingDataId,$errors) = $thingy->editThingDataSave($thingId,'new',{"field_".$fieldId => 'test value'});
ok( ! $thing->hasEnteredMaxPerUser, 'hasEnteredMaxPerUser: returns false when maxEntriesPerUser=0 and 1 entry added');
ok( ! $thingy->hasEnteredMaxPerUser($thingId), 'hasEnteredMaxPerUser: returns false when maxEntriesPerUser=0 and 1 entry added');
my $isValidThingDataId = $session->id->valid($newThingDataId);
@ -372,12 +314,11 @@ cmp_deeply(
my %otherThingProperties = %thingProperties;
$otherThingProperties{maxEntriesPerUser} = 1;
$otherThingProperties{editTemplateId } = $templateId;
my $otherThingId = $thingy->addThing(\%otherThingProperties, 0);
my $otherThing = WebGUI::Asset::Wobject::Thingy::Thing->new($session,$otherThingId);
my $otherThingId = $thingy->addThing(\%otherThingProperties, 0);
my %otherFieldProperties = %fieldProperties;
$otherFieldProperties{thingId} = $otherThingId;
my $otherFieldId = $thingy->addField(\%otherFieldProperties, 0);
ok( ! $otherThing->hasEnteredMaxPerUser($otherThingId), 'hasEnteredMaxPerUser: returns false with no data entered');
ok( ! $thingy->hasEnteredMaxPerUser($otherThingId), 'hasEnteredMaxPerUser: returns false with no data entered');
my @edit_thing_form_fields = qw/form_start form_end form_submit field_loop/;
@ -399,7 +340,7 @@ my @edit_thing_form_fields = qw/form_start form_end form_submit field_loop/;
}
$thingy->editThingDataSave($otherThingId, 'new', {"field_".$otherFieldId => 'other test value'} );
ok( $otherThing->hasEnteredMaxPerUser($otherThingId), 'hasEnteredMaxPerUser returns true with one row entered, and maxEntriesPerUser=1');
ok( $thingy->hasEnteredMaxPerUser($otherThingId), 'hasEnteredMaxPerUser returns true with one row entered, and maxEntriesPerUser=1');
{
WebGUI::Test->mockAssetId($templateId, $templateMock);
@ -422,7 +363,7 @@ ok( $otherThing->hasEnteredMaxPerUser($otherThingId), 'hasEnteredMaxPerUser retu
#
#################################################################
$otherThing->delete;
$thingy->deleteThing($otherThingId);
my $count;
$count = $session->db->quickScalar('select count(*) from Thingy_things where thingId=?',[$otherThingId]);
is($count, 0, 'deleteThing: clears thing from Thingy_things');