Revision 42 (by dpavlin, 2008/03/30 16:58:21) - move all LDAP-related logic in A3C::LDAP
- remove logic to link User and Organization
- ldap search base is now configurable in config.yml
#!/usr/bin/env perl
use warnings;
use strict;

=head1 DESCRIPTION

A basic test harness for the Organization model.

=cut

use Jifty::Test tests => 11;

# Make sure we can load the model
use_ok('A3C::Model::Organization');

# 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::Organization->new(current_user => $system_user);
my ($id) = $o->create(
	uid => 'carnet.hr',
	hrEduOrgUniqueNumber => 42,
	o => 'CARNet',
	postalAddress => 'Pere Perica b.b.',
	l => 'Zagreb',
);
ok($id, "Organization create returned success");
ok($o->id, "New Organization has valid id set");
is($o->id, $id, "Create returned the right id");

# And another
$o->create(
	uid => 'os-test-zg',
	hrEduOrgUniqueNumber => 11,
	o => 'Osnovna skola',
	postalAddress => 'Pere Perica b.b.',
	l => 'Zagreb',
);
ok($o->id, "Organization create returned another value");
isnt($o->id, $id, "And it is different from the previous one");

# Searches in general
my $collection =  A3C::Model::OrganizationCollection->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");