4 |
|
|
5 |
=head1 NAME |
=head1 NAME |
6 |
|
|
7 |
schema2model.pl - convert LDAP schema file into jifty model |
ldap2model.pl - convert LDAP schema file into Jifty model |
8 |
|
|
9 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
10 |
|
|
31 |
|
|
32 |
use lib 'lib'; |
use lib 'lib'; |
33 |
|
|
34 |
use Jifty; |
use JiftyModelCreator; |
35 |
use A3C::LDAP; |
use A3C::LDAP; |
36 |
use Net::LDAP::Schema; |
use Net::LDAP::Schema; |
37 |
use File::Slurp; |
use File::Slurp; |
145 |
1; |
1; |
146 |
/; |
/; |
147 |
|
|
148 |
if ( $debug ) { |
JiftyModelCreator->write( $objectClass, $model, $create ); |
|
print "##### ----- start of created model $objectClass\n\n$model\n\n#### ---- END of created model $objectClass\n"; |
|
|
} else { |
|
|
my $model_path = "lib/A3C/Model/$objectClass.pm"; |
|
|
write_file( $model_path, $model ); |
|
|
print "Created $model_path\n"; |
|
|
} |
|
|
|
|
|
my $test = <<'__END_OF_TEST__'; |
|
|
#!/usr/bin/env perl |
|
|
use warnings; |
|
|
use strict; |
|
|
|
|
|
=head1 DESCRIPTION |
|
|
|
|
|
A basic test harness for the _objectClass_ model. |
|
|
|
|
|
=cut |
|
|
|
|
|
use Jifty::Test tests => 11; |
|
|
|
|
|
# Make sure we can load the model |
|
|
use_ok('A3C::Model::_objectClass_'); |
|
|
|
|
|
# Grab a system user |
|
|
my $system_user = A3C::CurrentUser->superuser; |
|
|
ok($system_user, "Found a system user"); |
|
|
|
|
|
# Try testing a create |
|
|
my $o = A3C::Model::_objectClass_->new(current_user => $system_user); |
|
|
my ($id) = $o->create( |
|
|
_create_1_); |
|
|
ok($id, "_objectClass_ create returned success"); |
|
|
ok($o->id, "New _objectClass_ has valid id set"); |
|
|
is($o->id, $id, "Create returned the right id"); |
|
|
|
|
|
# And another |
|
|
$o->create( |
|
|
_create_2_); |
|
|
ok($o->id, "_objectClass_ create returned another value"); |
|
|
isnt($o->id, $id, "And it is different from the previous one"); |
|
|
|
|
|
# Searches in general |
|
|
my $collection = A3C::Model::_objectClass_Collection->new(current_user => $system_user); |
|
|
$collection->unlimit; |
|
|
is($collection->count, 2, "Finds two records"); |
|
|
|
|
|
# Searches in specific |
|
|
$collection->limit(column => 'id', value => $o->id); |
|
|
is($collection->count, 1, "Finds one record with specific id"); |
|
|
|
|
|
# Delete one of them |
|
|
$o->delete; |
|
|
$collection->redo_search; |
|
|
is($collection->count, 0, "Deleted row is gone"); |
|
|
|
|
|
# And the other one is still there |
|
|
$collection->unlimit; |
|
|
is($collection->count, 1, "Still one left"); |
|
|
__END_OF_TEST__ |
|
|
|
|
|
$test =~ s/_objectClass_/$objectClass/gs; |
|
|
|
|
|
foreach my $round ( 1 .. 2 ) { |
|
|
my $data; |
|
|
$data .= qq/\t\t'$_' => / . dump( $create->{$_} ) . qq/,\n/ foreach keys %$create; |
|
|
warn "$round data = $data\n" if $debug; |
|
|
$test =~ s/_create_${round}_/$data/gs; |
|
|
} |
|
|
|
|
|
if ( $debug ) { |
|
|
print "##### ----- template test\n$test\n"; |
|
|
} else { |
|
|
my $test_path = "t/00-model-$objectClass.t"; |
|
|
write_file( $test_path, $test ); |
|
|
print "Created $test_path\n"; |
|
|
chmod 0755, $test_path; |
|
|
} |
|