1 |
#!/usr/bin/env perl |
2 |
use warnings; |
3 |
use strict; |
4 |
|
5 |
=head1 DESCRIPTION |
6 |
|
7 |
A basic test harness for the User 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::User'); |
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::User->new(current_user => $system_user); |
22 |
my ($id) = $o->create( |
23 |
sn => 'Foo', |
24 |
givenName => 'Bar', |
25 |
hrEduPersonUniqueNumber => 42, |
26 |
hrEduPersonAffiliation => 'suradnik', |
27 |
o => 'CARNet', |
28 |
hrEduPersonHomeOrg => 'skole.hr', |
29 |
postalAddress => 'Pere Perica b.b.', |
30 |
l => 'Zagreb', |
31 |
); |
32 |
ok($id, "User create returned success"); |
33 |
ok($o->id, "New User has valid id set"); |
34 |
is($o->id, $id, "Create returned the right id"); |
35 |
|
36 |
# And another |
37 |
$o->create( |
38 |
sn => 'Fooby', |
39 |
givenName => 'Bary', |
40 |
hrEduPersonUniqueNumber => 1001, |
41 |
hrEduPersonAffiliation => 'gost', |
42 |
o => 'CARNet', |
43 |
hrEduPersonHomeOrg => 'skole.hr', |
44 |
postalAddress => 'Pere Perica b.b.', |
45 |
l => 'Zagreb', |
46 |
); |
47 |
ok($o->id, "User create returned another value"); |
48 |
isnt($o->id, $id, "And it is different from the previous one"); |
49 |
|
50 |
# Searches in general |
51 |
my $collection = A3C::Model::UserCollection->new(current_user => $system_user); |
52 |
$collection->unlimit; |
53 |
is($collection->count, 2, "Finds two records"); |
54 |
|
55 |
# Searches in specific |
56 |
$collection->limit(column => 'id', value => $o->id); |
57 |
is($collection->count, 1, "Finds one record with specific id"); |
58 |
|
59 |
# Delete one of them |
60 |
$o->delete; |
61 |
$collection->redo_search; |
62 |
is($collection->count, 0, "Deleted row is gone"); |
63 |
|
64 |
# And the other one is still there |
65 |
$collection->unlimit; |
66 |
is($collection->count, 1, "Still one left"); |
67 |
|