1 |
dpavlin |
2 |
#!/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 |
dpavlin |
32 |
use Jifty::Test tests => 12; |
12 |
dpavlin |
2 |
|
13 |
|
|
# Make sure we can load the model |
14 |
dpavlin |
11 |
use_ok('A3C::Model::User'); |
15 |
dpavlin |
2 |
|
16 |
|
|
# Grab a system user |
17 |
dpavlin |
11 |
my $system_user = A3C::CurrentUser->superuser; |
18 |
dpavlin |
2 |
ok($system_user, "Found a system user"); |
19 |
|
|
|
20 |
dpavlin |
32 |
my $organization = A3C::Model::Organization->new(current_user => $system_user); |
21 |
|
|
my ($id) = $organization->create( |
22 |
|
|
o => 'CARNet', |
23 |
|
|
hrEduPersonHomeOrg => 'skole.hr', |
24 |
|
|
postalAddress => 'Pere Perica b.b.', |
25 |
|
|
l => 'Zagreb', |
26 |
|
|
); |
27 |
|
|
ok($id, "Organization create returned success"); |
28 |
|
|
|
29 |
dpavlin |
2 |
# Try testing a create |
30 |
dpavlin |
11 |
my $o = A3C::Model::User->new(current_user => $system_user); |
31 |
dpavlin |
32 |
($id) = $o->create( |
32 |
dpavlin |
18 |
uid => 42, |
33 |
|
|
hrEduPersonUniqueID => 42, |
34 |
|
|
hrEduPersonExpireDate => '2042-12-30', |
35 |
dpavlin |
32 |
givenName => 'Foo', |
36 |
|
|
sn => 'Bar', |
37 |
|
|
cn => 'Foo Bar', |
38 |
dpavlin |
6 |
hrEduPersonUniqueNumber => 42, |
39 |
|
|
hrEduPersonAffiliation => 'suradnik', |
40 |
dpavlin |
32 |
organization => $organization, |
41 |
dpavlin |
6 |
); |
42 |
dpavlin |
2 |
ok($id, "User create returned success"); |
43 |
|
|
ok($o->id, "New User has valid id set"); |
44 |
|
|
is($o->id, $id, "Create returned the right id"); |
45 |
|
|
|
46 |
|
|
# And another |
47 |
dpavlin |
6 |
$o->create( |
48 |
dpavlin |
18 |
uid => 1001, |
49 |
|
|
hrEduPersonUniqueID => 1001, |
50 |
|
|
hrEduPersonExpireDate => '1999-01-01', |
51 |
dpavlin |
32 |
givenName => 'Bary', |
52 |
dpavlin |
6 |
sn => 'Fooby', |
53 |
dpavlin |
32 |
cn => 'Bary Fooby', |
54 |
dpavlin |
6 |
hrEduPersonUniqueNumber => 1001, |
55 |
|
|
hrEduPersonAffiliation => 'gost', |
56 |
dpavlin |
32 |
organization => $organization, |
57 |
dpavlin |
6 |
); |
58 |
dpavlin |
2 |
ok($o->id, "User create returned another value"); |
59 |
|
|
isnt($o->id, $id, "And it is different from the previous one"); |
60 |
|
|
|
61 |
|
|
# Searches in general |
62 |
dpavlin |
11 |
my $collection = A3C::Model::UserCollection->new(current_user => $system_user); |
63 |
dpavlin |
2 |
$collection->unlimit; |
64 |
|
|
is($collection->count, 2, "Finds two records"); |
65 |
|
|
|
66 |
|
|
# Searches in specific |
67 |
|
|
$collection->limit(column => 'id', value => $o->id); |
68 |
|
|
is($collection->count, 1, "Finds one record with specific id"); |
69 |
|
|
|
70 |
|
|
# Delete one of them |
71 |
|
|
$o->delete; |
72 |
|
|
$collection->redo_search; |
73 |
|
|
is($collection->count, 0, "Deleted row is gone"); |
74 |
|
|
|
75 |
|
|
# And the other one is still there |
76 |
|
|
$collection->unlimit; |
77 |
|
|
is($collection->count, 1, "Still one left"); |
78 |
|
|
|