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