Myco
view release on metacpan or search on metacpan
test/Myco/Entity/Test.pm view on Meta::CPAN
# $Id: Test.pm,v 1.4 2006/03/19 19:34:08 sommerb Exp $
#
# See license and copyright near the end of this file.
###############################################################################
=head1 NAME
Myco::Entity::Test -
unit tests for features of Myco::Entity
=head1 DATE
$Date: 2006/03/19 19:34:08 $
=head1 SYNOPSIS
cd $MYCO_DISTRIB/bin
# run tests. '-m': test just in-memory behavior
./myco-testrun [-m] Myco::Entity::Test
# run tests, GUI style
./tkmyco-testrun Myco::Entity::Test
=head1 DESCRIPTION
Unit tests for features of Myco::Entity.
=cut
### Inheritance
# Myco::Test::Entity is not itself an entity class, so
# for testing we mustn't inherit from Myco::Test::EntityTest
use base qw(Test::Unit::TestCase Myco::Test::Fodder);
### Module Dependencies and Compiler Pragma
use Myco::Entity;
use Myco::Entity::SampleEntity;
use Data::Dumper;
use Myco::Util::DateTime;
use strict;
use warnings;
### Class Data
my $testpkg = 'Myco::Entity::TestFoo';
my $samp_ent = 'Myco::Person';
use constant DATETIME => 'Myco::Util::DateTime';
my $test_attr_params = {
name => 'meat_cooked_pref',
tangram_options => {required => 1},
type => 'int',
synopsis => "How you'd like your meat cooked",
syntax_msg => "single number: 0 through 5",
values => [qw(0 1 2 3 4 5)],
value_labels => {0 => 'rare',
1 => 'medium-rare',
2 => 'medium',
3 => 'medium-well',
4 => 'well',
5 => 'charred'},
ui => { widget => [ popup_menu => undef ] },
};
# This class tests features of:
my $class = 'Myco::Entity';
my %test_parameters =
### Test Control Prameters ###
(
# A scalar attribute that can be used for testing... set to undef
# to disable related tests
simple_accessor => 'abstract',
skip_persistence => 0,
# Default attribute values for use when constructing objects
# Needed for any 'required' attributes
defaults =>
{ name => $testpkg },
);
##### Sample class package used by these unit tests
package Myco::Entity::TestFoo;
use base qw(Myco::Entity);
use strict;
use warnings;
my $metadata = Myco::Entity::Meta->new(name => __PACKAGE__);
$metadata->add_attribute(name => 'name', type => 'transient');
$metadata->add_attribute(name => 'foobar', type => 'transient');
$metadata->activate_class;
##### Now back to regularly scheduled testing...
package Myco::Entity::Test;
###
### Unit Tests for Myco::Entity
###
##
## Tests for In-Memory Behavior
use constant ENDER => 'Ender Wiggin';
sub test_introspect {
my $test = shift;
return if $test->should_skip; # skip over this test if asked
# Class method usage
my $testmeta = eval { $testpkg->introspect; };
$test->assert( ! $@, "call to new_metadata(): $@");
$test->assert( defined($testmeta), '$testmeta defined');
$test->assert( UNIVERSAL::isa($testmeta,'Myco::Entity::Meta'),
'we have a ::Meta object');
$test->assert( $testmeta->name eq $testpkg, '$testmeta knows his name');
# Instance method usage
my $instance = eval { $testpkg->new(name => 'Valentine Wiggen'); };
$test->assert( UNIVERSAL::isa($instance, $testpkg),
( run in 1.085 second using v1.01-cache-2.11-cpan-364913b4093 )