Convert AssetCollateral/DataForm/Entry.pm over to use Moose.
This commit is contained in:
parent
acd71a7f7e
commit
c917e6ca6d
3 changed files with 215 additions and 123 deletions
|
|
@ -29,26 +29,85 @@ they relate and function.
|
||||||
|
|
||||||
=head1 METHODS
|
=head1 METHODS
|
||||||
|
|
||||||
This packages is a subclass of L<WebGUI::Crud>. Please refer to that module
|
|
||||||
for a list of base methods that are available.
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
our $VERSION = '0.0.1';
|
our $VERSION = '0.0.1';
|
||||||
|
|
||||||
use Class::InsideOut qw(readonly private public id register);
|
#use Class::InsideOut qw(readonly private public id register);
|
||||||
|
use Moose;
|
||||||
|
use Scalar::Util qw/blessed/;
|
||||||
use WebGUI::Exception;
|
use WebGUI::Exception;
|
||||||
|
use WebGUI::DateTime;
|
||||||
use WebGUI::Asset::Wobject::DataForm;
|
use WebGUI::Asset::Wobject::DataForm;
|
||||||
|
|
||||||
readonly session => my %session;
|
#readonly session => my %session;
|
||||||
private entryData => my %entryData;
|
#readonly assetId => my %assetId;
|
||||||
private entryId => my %entryId;
|
#readonly asset => my %asset;
|
||||||
readonly assetId => my %assetId;
|
|
||||||
readonly asset => my %asset;
|
has session => (
|
||||||
private userId => my %userId;
|
is => 'ro',
|
||||||
readonly username => my %username;
|
required => 1,
|
||||||
public ipAddress => my %ipAddress;
|
);
|
||||||
public submissionDate => my %submissionDate;
|
|
||||||
|
has submissionDate => (
|
||||||
|
isa => 'WebGUI::DateTime',
|
||||||
|
is => 'rw',
|
||||||
|
);
|
||||||
|
|
||||||
|
has [ qw{assetId asset ipAddress} ] => (
|
||||||
|
is => 'rw',
|
||||||
|
);
|
||||||
|
|
||||||
|
has userId => (
|
||||||
|
is => 'rw',
|
||||||
|
builder => '_default_userId',
|
||||||
|
lazy => 1,
|
||||||
|
);
|
||||||
|
sub _default_userId {
|
||||||
|
return shift->session->user->userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
has username => (
|
||||||
|
is => 'rw',
|
||||||
|
builder => '_default_username',
|
||||||
|
lazy => 1,
|
||||||
|
);
|
||||||
|
sub _default_username {
|
||||||
|
return shift->session->user->username;
|
||||||
|
}
|
||||||
|
|
||||||
|
has entryData => (
|
||||||
|
is => 'rw',
|
||||||
|
default => sub { return {}; },
|
||||||
|
traits => ['Hash', 'WebGUI::Definition::Meta::Property::Serialize',],
|
||||||
|
isa => 'WebGUI::Type::JSONHash',
|
||||||
|
coerce => 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
around userId => sub {
|
||||||
|
my $orig = shift;
|
||||||
|
my $self = shift;
|
||||||
|
if (my $userId = $_[0]) {
|
||||||
|
my $user = WebGUI::User->new($self->session, $userId);
|
||||||
|
if (!defined $user) {
|
||||||
|
WebGUI::Error::InvalidParam->throw(error=>$userId . ' is not a valud userId');
|
||||||
|
}
|
||||||
|
$self->username($user->username);
|
||||||
|
}
|
||||||
|
$self->$orig(@_);
|
||||||
|
};
|
||||||
|
|
||||||
|
has entryId => (
|
||||||
|
is => 'ro',
|
||||||
|
writer => '_set_entryId',
|
||||||
|
);
|
||||||
|
|
||||||
|
#private entryData => my %entryData;
|
||||||
|
#private entryId => my %entryId;
|
||||||
|
#private userId => my %userId;
|
||||||
|
#readonly username => my %username;
|
||||||
|
#public ipAddress => my %ipAddress;
|
||||||
|
#public submissionDate => my %submissionDate;
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -61,7 +120,6 @@ Deletes this entry from the database. Returns true.
|
||||||
sub delete {
|
sub delete {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->session->db->deleteRow('DataForm_entry', 'DataForm_entryId', $self->getId);
|
$self->session->db->deleteRow('DataForm_entry', 'DataForm_entryId', $self->getId);
|
||||||
delete $entryId{ id $self };
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,11 +135,11 @@ does not exist. Otherwise, returns the entry for this field after deleting it.
|
||||||
sub deleteField {
|
sub deleteField {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($field) = @_;
|
my ($field) = @_;
|
||||||
my $entryData = $entryData{ id $self };
|
my $entryData = $self->entryData;
|
||||||
if ( !exists $entryData{ $field } ) {
|
if ( !exists $entryData->{ $field } ) {
|
||||||
WebGUI::Error::InvalidParam->throw(error=>"cannot delete field that doesn't exist");
|
WebGUI::Error::InvalidParam->throw(error=>"cannot delete field that doesn't exist");
|
||||||
}
|
}
|
||||||
return delete $entryData{$field};
|
return delete $entryData->{$field};
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -104,7 +162,7 @@ If passed in, this value will be stored in the field.
|
||||||
sub field {
|
sub field {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $fieldName = shift;
|
my $fieldName = shift;
|
||||||
my $entryData = $entryData{ id $self };
|
my $entryData = $self->entryData;
|
||||||
if (@_) {
|
if (@_) {
|
||||||
my $fieldValue = shift;
|
my $fieldValue = shift;
|
||||||
return $entryData->{ $fieldName } = $fieldValue;
|
return $entryData->{ $fieldName } = $fieldValue;
|
||||||
|
|
@ -127,7 +185,7 @@ A hash reference of new data to store in this entry.
|
||||||
|
|
||||||
sub fields {
|
sub fields {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $entryData = $entryData{ id $self };
|
my $entryData = $self->entryData;
|
||||||
if (@_) {
|
if (@_) {
|
||||||
my $newData = shift;
|
my $newData = shift;
|
||||||
@{ $entryData }{ keys %$newData } = values %$newData;
|
@{ $entryData }{ keys %$newData } = values %$newData;
|
||||||
|
|
@ -155,16 +213,15 @@ Gets a hash reference of data for this entry, which looks like this:
|
||||||
|
|
||||||
sub getHash {
|
sub getHash {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $id = id $self;
|
|
||||||
|
|
||||||
my $var = {
|
my $var = {
|
||||||
DataForm_entryId => $entryId{$id},
|
DataForm_entryId => $self->entryId,
|
||||||
userId => $userId{$id},
|
userId => $self->userId,
|
||||||
username => $username{$id},
|
username => $self->username,
|
||||||
ipAddress => $ipAddress{$id},
|
ipAddress => $self->ipAddress,
|
||||||
assetId => $assetId{$id},
|
assetId => $self->assetId,
|
||||||
submissionDate => $submissionDate{$id}->toDatabase,
|
submissionDate => $self->submissionDate->toDatabase,
|
||||||
entryData => $entryData{$id},
|
entryData => $self->entryData,
|
||||||
};
|
};
|
||||||
|
|
||||||
return $var;
|
return $var;
|
||||||
|
|
@ -202,7 +259,7 @@ Returns the GUID for this entry.
|
||||||
|
|
||||||
sub getId {
|
sub getId {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return $entryId{ id $self };
|
return $self->entryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -241,7 +298,7 @@ sub iterateAll {
|
||||||
my $sth = $slave->read($sql, $placeHolders);
|
my $sth = $slave->read($sql, $placeHolders);
|
||||||
my $allRows = $slave->quickScalar('SELECT FOUND_ROWS()');
|
my $allRows = $slave->quickScalar('SELECT FOUND_ROWS()');
|
||||||
my $sub = sub {
|
my $sub = sub {
|
||||||
return $allRows if $_[0] eq 'rowCount';
|
return $allRows if $_[0] && $_[0] eq 'rowCount';
|
||||||
if (defined wantarray) {
|
if (defined wantarray) {
|
||||||
my $properties = $sth->hashRef;
|
my $properties = $sth->hashRef;
|
||||||
if ($properties) {
|
if ($properties) {
|
||||||
|
|
@ -271,42 +328,40 @@ from the database. If C<entryId> is not defined, will create a new entry.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub new {
|
around BUILDARGS => sub {
|
||||||
my ($class, $asset, $entryId) = @_;
|
my $orig = shift;
|
||||||
my $self = register($class);
|
my $class = shift;
|
||||||
my $id = id $self;
|
my ($asset, $entryId) = @_;
|
||||||
my $session;
|
my $session;
|
||||||
if (defined $asset && ref $asset && $asset->isa('WebGUI::Asset::Wobject::DataForm')) {
|
my %properties;
|
||||||
$session = $session{$id} = $asset->session;
|
if (blessed $asset && $asset->isa('WebGUI::Asset::Wobject::DataForm')) {
|
||||||
$assetId{$id} = $asset->getId;
|
$session = $properties{session} = $asset->session;
|
||||||
$asset{$id} = $asset;
|
$properties{assetId} = $asset->getId;
|
||||||
|
$properties{asset} = $asset;
|
||||||
}
|
}
|
||||||
elsif (defined $asset && ref $asset && $asset->isa('WebGUI::Session') && $entryId) {
|
elsif (blessed $asset && $asset->isa('WebGUI::Session') && $entryId) {
|
||||||
$session = $session{$id} = $asset;
|
$session = $properties{session} = $asset;
|
||||||
undef $asset;
|
undef $asset;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
WebGUI::Error::InvalidObject->throw(error=>'need a DataForm object or a session and entryId', got => ref $asset, expected => 'WebGUI::Asset::Wobject::DataForm');
|
WebGUI::Error::InvalidObject->throw(error=>'need a DataForm object or a session and entryId', got => ref $asset, expected => 'WebGUI::Asset::Wobject::DataForm');
|
||||||
}
|
}
|
||||||
if ($entryId) {
|
if ($entryId) {
|
||||||
my $properties = $session->db->getRow('DataForm_entry', 'DataForm_entryId', $entryId);
|
%properties = %{ $session->db->getRow('DataForm_entry', 'DataForm_entryId', $entryId) };
|
||||||
if (! defined $properties->{'DataForm_entryId'}) {
|
if (! defined $properties{'DataForm_entryId'}) {
|
||||||
WebGUI::Error::ObjectNotFound->throw(error => 'no such DataForm_entryId', id => $entryId);
|
WebGUI::Error::ObjectNotFound->throw(error => 'no such DataForm_entryId', id => $entryId);
|
||||||
}
|
}
|
||||||
if (! $assetId{$id}) {
|
$properties{asset} = $asset = eval { WebGUI::Asset->newById($session, $properties{assetId}); };
|
||||||
$assetId{$id} = $properties->{assetId};
|
$properties{submissionDate} = WebGUI::DateTime->new($session, $properties{submissionDate});
|
||||||
$asset{$id} = WebGUI::Asset::Wobject::DataForm->newById($session, $properties->{assetId});
|
|
||||||
}
|
|
||||||
$self->setFromHash($properties);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$self->user($session->user);
|
$properties{user} = ($session->user);
|
||||||
$self->ipAddress($session->request->address);
|
$properties{ipAddress} = ($session->request->address);
|
||||||
$self->submissionDate(WebGUI::DateTime->new($session, time));
|
$properties{submissionDate} = (WebGUI::DateTime->new($session, time));
|
||||||
$entryData{id $self} = {};
|
$properties{entryData} = {};
|
||||||
}
|
}
|
||||||
return $self;
|
return $class->$orig(%properties);
|
||||||
}
|
};
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -323,12 +378,12 @@ sub newFromHash {
|
||||||
my $asset = shift;
|
my $asset = shift;
|
||||||
my $self;
|
my $self;
|
||||||
|
|
||||||
if ( defined $asset && ref $asset && $asset->isa( 'WebGUI::Asset::Wobject::DataForm' ) ) {
|
if ( blessed $asset && $asset->isa( 'WebGUI::Asset::Wobject::DataForm' ) ) {
|
||||||
my $properties = shift;
|
my $properties = shift;
|
||||||
$self = $class->new( $asset );
|
$self = $class->new( $asset );
|
||||||
$self->setFromHash( $properties );
|
$self->setFromHash( $properties );
|
||||||
}
|
}
|
||||||
elsif ( defined $asset && ref $asset && $asset->isa( 'WebGUI::Session' ) ) {
|
elsif ( blessed $asset && $asset->isa( 'WebGUI::Session' ) ) {
|
||||||
my $session = $asset;
|
my $session = $asset;
|
||||||
my $assetId = shift;
|
my $assetId = shift;
|
||||||
my $properties = shift;
|
my $properties = shift;
|
||||||
|
|
@ -379,14 +434,14 @@ The new name of the field.
|
||||||
sub renameField {
|
sub renameField {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($oldField, $newField) = @_;
|
my ($oldField, $newField) = @_;
|
||||||
my $entryData = $entryData{ id $self };
|
my $entryData = $self->entryData;
|
||||||
if ( !exists $entryData{ $oldField } ) {
|
if ( !exists $entryData->{ $oldField } ) {
|
||||||
WebGUI::Error::InvalidParam->throw(error=>"cannot rename field that doesn't exist");
|
WebGUI::Error::InvalidParam->throw(error=>"cannot rename field that doesn't exist");
|
||||||
}
|
}
|
||||||
elsif ( exists $entryData{ $newField } ) {
|
elsif ( exists $entryData->{ $newField } ) {
|
||||||
WebGUI::Error::InvalidParam->throw(error=>'cannot rename field over existing field');
|
WebGUI::Error::InvalidParam->throw(error=>'cannot rename field over existing field');
|
||||||
}
|
}
|
||||||
$entryData->{$newField} = delete $entryData{$oldField};
|
$entryData->{$newField} = delete $entryData->{$oldField};
|
||||||
return $newField;
|
return $newField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -400,21 +455,22 @@ Persists data from this entry into the db.
|
||||||
|
|
||||||
sub save {
|
sub save {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $id = id $self;
|
my $entryData = $self->entryData;
|
||||||
my $entryData = $entryData{ $id };
|
|
||||||
if (!$entryData || ref $entryData ne 'HASH') {
|
if (!$entryData || ref $entryData ne 'HASH') {
|
||||||
$entryData = {};
|
$entryData = {};
|
||||||
}
|
}
|
||||||
my %dbData = (
|
my %dbData = (
|
||||||
DataForm_entryId => $entryId{$id} || 'new',
|
DataForm_entryId => $self->entryId || 'new',
|
||||||
userId => $userId{$id},
|
userId => $self->userId,
|
||||||
username => $username{$id},
|
username => $self->username,
|
||||||
ipAddress => $ipAddress{$id},
|
ipAddress => $self->ipAddress,
|
||||||
assetId => $assetId{$id},
|
assetId => $self->assetId,
|
||||||
submissionDate => $submissionDate{$id}->toDatabase,
|
submissionDate => $self->submissionDate->toDatabase,
|
||||||
entryData => JSON::to_json($entryData),
|
entryData => JSON::to_json($entryData),
|
||||||
);
|
);
|
||||||
return $entryId{$id} = $session{$id}->db->setRow('DataForm_entry', 'DataForm_entryId', \%dbData);
|
my $newId = $self->session->db->setRow('DataForm_entry', 'DataForm_entryId', \%dbData);
|
||||||
|
$self->_set_entryId($newId);
|
||||||
|
return $newId;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -456,29 +512,17 @@ Data, either as JSON or a perl data structure.
|
||||||
|
|
||||||
sub setFromHash {
|
sub setFromHash {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $id = id $self;
|
|
||||||
my $properties = shift;
|
my $properties = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
$entryId{$id} = $properties->{DataForm_entryId}
|
$self->_set_entryId($properties->{DataForm_entryId}) if defined $properties->{DataForm_entryId};
|
||||||
if defined $properties->{DataForm_entryId};
|
$self->userId( $properties->{userId} ) if defined $properties->{userId};
|
||||||
$userId{$id} = $properties->{userId}
|
$self->username( $properties->{username} ) if defined $properties->{username};
|
||||||
if defined $properties->{userId};
|
$self->ipAddress( $properties->{ipAddress} ) if defined $properties->{ipAddress};
|
||||||
$username{$id} = $properties->{username}
|
$self->entryData( $properties->{entryData} ) if defined $properties->{entryData};
|
||||||
if defined $properties->{username};
|
|
||||||
$ipAddress{$id} = $properties->{ipAddress}
|
$self->submissionDate(WebGUI::DateTime->new($session, $properties->{submissionDate}))
|
||||||
if defined $properties->{ipAddress};
|
|
||||||
$submissionDate{$id} = WebGUI::DateTime->new($session, $properties->{submissionDate})
|
|
||||||
if defined $properties->{submissionDate};
|
if defined $properties->{submissionDate};
|
||||||
if (defined $properties->{entryData}) {
|
|
||||||
if (ref $properties->{entryData} && ref $properties->{entryData} eq 'HASH') {
|
|
||||||
$entryData{$id} = $properties->{entryData};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!eval { $entryData{$id} = JSON::from_json($properties->{entryData}); 1 } ) {
|
|
||||||
$session->log->warn('DataForm entry ' . $entryId{$id} . ' has invalid data, ignoring');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -496,46 +540,16 @@ set from it for this entry.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub user {
|
sub user {
|
||||||
my $self = shift;
|
my ($self) = shift;
|
||||||
my $id = id $self;
|
|
||||||
if (@_) {
|
if (@_) {
|
||||||
my $user = shift;
|
my $user = shift;
|
||||||
if (!defined $user || !ref $user || !$user->isa('WebGUI::User')) {
|
if (!(blessed $user && $user->isa('WebGUI::User'))) {
|
||||||
WebGUI::Error::InvalidObject->throw(expected=>'WebGUI::User', got=>(ref $user), error=>'Need a user.');
|
WebGUI::Error::InvalidObject->throw(expected=>'WebGUI::User', got=>(ref $user), error=>'Need a user.');
|
||||||
}
|
}
|
||||||
$userId{$id} = $user->userId;
|
$self->username($user->username);
|
||||||
$username{$id} = $user->username;
|
$self->userId($user->userId);
|
||||||
}
|
}
|
||||||
return $userId{$id};
|
return $self->userId;
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 userId ( [ $user ] )
|
|
||||||
|
|
||||||
Returns the userId of the user who submitted this entry.
|
|
||||||
|
|
||||||
=head3 $user
|
|
||||||
|
|
||||||
An optional WebGUI::User object. If passed, the userId and username will be
|
|
||||||
set from it for this entry.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub userId {
|
|
||||||
my $self = shift;
|
|
||||||
my $id = id $self;
|
|
||||||
if (@_) {
|
|
||||||
my $userId = shift;
|
|
||||||
my $user = WebGUI::User->new($self->session, $userId);
|
|
||||||
if (!defined $user) {
|
|
||||||
WebGUI::Error::InvalidParam->throw(error=>$userId . ' is not a valud userId');
|
|
||||||
}
|
|
||||||
$userId{$id} = $userId;
|
|
||||||
$username{$id} = $user->username;
|
|
||||||
}
|
|
||||||
return $userId{$id};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
|
||||||
78
t/Asset/Wobject/DataForm/addEntry.t
Normal file
78
t/Asset/Wobject/DataForm/addEntry.t
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
# vim:syntax=perl
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
# WebGUI is Copyright 2001-2009 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 viewList and related methods of the DataForm
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
use FindBin;
|
||||||
|
use strict;
|
||||||
|
use lib "$FindBin::Bin/../../../lib";
|
||||||
|
use Test::More;
|
||||||
|
use Test::Deep;
|
||||||
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
|
use WebGUI::Session;
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Init
|
||||||
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
|
my $df = WebGUI::Asset->getImportNode($session)->addChild( {
|
||||||
|
className => 'WebGUI::Asset::Wobject::DataForm',
|
||||||
|
} );
|
||||||
|
|
||||||
|
WebGUI::Test->addToCleanup( WebGUI::VersionTag->getWorking( $session ) );
|
||||||
|
|
||||||
|
# Add fields to the dataform
|
||||||
|
$df->createField( "name", { type => "text", } );
|
||||||
|
$df->createField( "message", { type => "text", } );
|
||||||
|
|
||||||
|
# Add entries to the dataform
|
||||||
|
my @entryProperties = (
|
||||||
|
{
|
||||||
|
name => "Andy",
|
||||||
|
subject => "Problem!",
|
||||||
|
message => "I need a Rita Heyworth",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => "Red",
|
||||||
|
subject => "Solution!",
|
||||||
|
message => "I need about tree fiddy",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
my $birthday = WebGUI::Test->webguiBirthday;
|
||||||
|
|
||||||
|
is $df->entryClass, 'WebGUI::AssetCollateral::DataForm::Entry', 'entry class returns the right class';
|
||||||
|
|
||||||
|
ok ! $df->hasEntries, 'hasEntries: no entries yet';
|
||||||
|
|
||||||
|
my $entry;
|
||||||
|
$entry = $df->entryClass->newFromHash( $df, $entryProperties[0] );
|
||||||
|
isa_ok $entry, $df->entryClass;
|
||||||
|
|
||||||
|
$entry->submissionDate(WebGUI::DateTime->new($session, $birthday++));
|
||||||
|
my $entryId = $entry->save;
|
||||||
|
ok $session->id->valid($entryId), 'save returns the entryId, a GUID';
|
||||||
|
|
||||||
|
ok $df->hasEntries, 'hasEntries returns true after entries added';
|
||||||
|
is $df->entryClass->getCount($df), 1, 'getCount returns the number of entries';
|
||||||
|
|
||||||
|
$entry = $df->entryClass->newFromHash( $df, $entryProperties[0] );
|
||||||
|
isa_ok $entry, $df->entryClass;
|
||||||
|
|
||||||
|
$entry->submissionDate(WebGUI::DateTime->new($session, $birthday++));
|
||||||
|
$entry->save;
|
||||||
|
ok $df->hasEntries, 'hasEntries returns true after entries added';
|
||||||
|
is $df->entryClass->getCount($df), 2, 'count incremented';
|
||||||
|
|
||||||
|
done_testing;
|
||||||
|
#vim:ft=perl
|
||||||
|
|
@ -29,7 +29,7 @@ my $df = WebGUI::Asset->getImportNode($session)->addChild( {
|
||||||
className => 'WebGUI::Asset::Wobject::DataForm',
|
className => 'WebGUI::Asset::Wobject::DataForm',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
addToCleanup( WebGUI::VersionTag->getWorking( $session ) );
|
WebGUI::Test->addToCleanup( WebGUI::VersionTag->getWorking( $session ) );
|
||||||
|
|
||||||
# Add fields to the dataform
|
# Add fields to the dataform
|
||||||
$df->createField( "name", { type => "text", } );
|
$df->createField( "name", { type => "text", } );
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue