Revision 208 (by dpavlin, 2008/06/19 21:24:26) another round of re-factoring

- re-organize LDAP-related pages under /ldap with new view A3C::View::LDAP
- move record multi-value support into A3C::Record
- document multi-value solution which started it all
#!/usr/bin/env perl
use warnings;
use strict;

=head1 DESCRIPTION

A basic test harness for the hrEduOrg model.

=cut

use Jifty::Test tests => 12;

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

# 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::hrEduOrg->new(current_user => $system_user);
my ($id) = $o->create(
		'dc' => "dc",
		'uid' => 'foo',
		'cn' => [
  "cn",
  "RFC2256: common name(s) for which the entity is known by",
],
		'homeDirectory' => "homeDirectory",
		'hrEduOrgMail' => ["hrEduOrgMail", "Sluzbena e-mail adresa ustanove"],
		'uidNumber' => 42,
		'hrEduOrgURL' => "hrEduOrgURL",
		'objectClass' => ["objectClass", "RFC2256: object classes of the entity"],
		'gidNumber' => 1042,
		'hrEduOrgUniqueNumber' => [
  "hrEduOrgUniqueNumber",
  "Visestruka vrijednost brojcani identifikator ustanove",
],
		'hrEduOrgType' => "hrEduOrgType",
		'o' => ["o", "RFC2256: organization this object belongs to"],
);
ok($id, "hrEduOrg create returned success");
ok($o->id, "New hrEduOrg has valid id set");
is($o->id, $id, "Create returned the right id");

# And another
$o->create(
		'dc' => "dc",
		'uid' => 'bar',
		'cn' => [
  "cn",
  "RFC2256: common name(s) for which the entity is known by",
],
		'homeDirectory' => "homeDirectory",
		'hrEduOrgMail' => ["hrEduOrgMail", "Sluzbena e-mail adresa ustanove"],
		'uidNumber' => 43,
		'hrEduOrgURL' => "hrEduOrgURL",
		'objectClass' => ["objectClass", "RFC2256: object classes of the entity"],
		'gidNumber' => 1043,
		'hrEduOrgUniqueNumber' => [
  "hrEduOrgUniqueNumber",
  "Visestruka vrijednost brojcani identifikator ustanove",
],
		'hrEduOrgType' => "hrEduOrgType",
		'o' => ["o", "RFC2256: organization this object belongs to"],
);
ok($o->id, "hrEduOrg create returned another value");
isnt($o->id, $id, "And it is different from the previous one");

# multi-value rollup
use Data::Dump qw/dump/;
dump( $o->cn );
is( $o->cn, 'cn <*> RFC2256: common name(s) for which the entity is known by', 'ARRAY value');

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