| 1 |
32 |
dpavlin |
#!/usr/bin/env perl |
| 2 |
|
|
use warnings; |
| 3 |
|
|
use strict; |
| 4 |
|
|
|
| 5 |
|
|
=head1 DESCRIPTION |
| 6 |
|
|
|
| 7 |
|
|
A basic test harness for the Organization model. |
| 8 |
|
|
|
| 9 |
|
|
=cut |
| 10 |
|
|
|
| 11 |
|
|
use Jifty::Test tests => 11; |
| 12 |
|
|
|
| 13 |
|
|
# Make sure we can load the model |
| 14 |
|
|
use_ok('A3C::Model::Organization'); |
| 15 |
|
|
|
| 16 |
|
|
# Grab a system user |
| 17 |
|
|
my $system_user = A3C::CurrentUser->superuser; |
| 18 |
|
|
ok($system_user, "Found a system user"); |
| 19 |
|
|
|
| 20 |
|
|
# Try testing a create |
| 21 |
|
|
my $o = A3C::Model::Organization->new(current_user => $system_user); |
| 22 |
|
|
my ($id) = $o->create( |
| 23 |
42 |
dpavlin |
uid => 'carnet.hr', |
| 24 |
|
|
hrEduOrgUniqueNumber => 42, |
| 25 |
32 |
dpavlin |
o => 'CARNet', |
| 26 |
|
|
postalAddress => 'Pere Perica b.b.', |
| 27 |
|
|
l => 'Zagreb', |
| 28 |
|
|
); |
| 29 |
|
|
ok($id, "Organization create returned success"); |
| 30 |
|
|
ok($o->id, "New Organization has valid id set"); |
| 31 |
|
|
is($o->id, $id, "Create returned the right id"); |
| 32 |
|
|
|
| 33 |
|
|
# And another |
| 34 |
|
|
$o->create( |
| 35 |
42 |
dpavlin |
uid => 'os-test-zg', |
| 36 |
|
|
hrEduOrgUniqueNumber => 11, |
| 37 |
32 |
dpavlin |
o => 'Osnovna skola', |
| 38 |
|
|
postalAddress => 'Pere Perica b.b.', |
| 39 |
|
|
l => 'Zagreb', |
| 40 |
|
|
); |
| 41 |
|
|
ok($o->id, "Organization create returned another value"); |
| 42 |
|
|
isnt($o->id, $id, "And it is different from the previous one"); |
| 43 |
|
|
|
| 44 |
|
|
# Searches in general |
| 45 |
|
|
my $collection = A3C::Model::OrganizationCollection->new(current_user => $system_user); |
| 46 |
|
|
$collection->unlimit; |
| 47 |
|
|
is($collection->count, 2, "Finds two records"); |
| 48 |
|
|
|
| 49 |
|
|
# Searches in specific |
| 50 |
|
|
$collection->limit(column => 'id', value => $o->id); |
| 51 |
|
|
is($collection->count, 1, "Finds one record with specific id"); |
| 52 |
|
|
|
| 53 |
|
|
# Delete one of them |
| 54 |
|
|
$o->delete; |
| 55 |
|
|
$collection->redo_search; |
| 56 |
|
|
is($collection->count, 0, "Deleted row is gone"); |
| 57 |
|
|
|
| 58 |
|
|
# And the other one is still there |
| 59 |
|
|
$collection->unlimit; |
| 60 |
|
|
is($collection->count, 1, "Still one left"); |
| 61 |
|
|
|