line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::PObject::Test::Basic; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Basic.pm,v 1.14 2005/02/20 18:05:00 sherzodr Exp |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
19391
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
6
|
|
|
|
|
|
|
#use diagnostics; |
7
|
1
|
|
|
1
|
|
1105
|
use Test::More; |
|
1
|
|
|
|
|
19894
|
|
|
1
|
|
|
|
|
9
|
|
8
|
1
|
|
|
1
|
|
1068
|
use Class::PObject; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
453
|
use Class::PObject::Test; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
10
|
1
|
|
|
1
|
|
5
|
use vars ('$VERSION', '@ISA'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
11
|
1
|
|
|
1
|
|
4
|
use overload; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@ISA = ('Class::PObject::Test'); |
14
|
|
|
|
|
|
|
$VERSION = '1.03'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
BEGIN { |
18
|
1
|
|
|
1
|
|
69
|
plan(tests => 204); |
19
|
1
|
|
|
1
|
|
155
|
use_ok("Class::PObject") |
|
1
|
|
|
|
|
97
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
5
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub run { |
24
|
1
|
|
|
1
|
0
|
9
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
15
|
pobject 'PO::Author' => { |
27
|
|
|
|
|
|
|
columns => ['id', 'name', 'url', 'email'], |
28
|
|
|
|
|
|
|
driver => $self->{driver}, |
29
|
|
|
|
|
|
|
serializer => 'storable', |
30
|
|
|
|
|
|
|
tmap => { |
31
|
|
|
|
|
|
|
name => 'VARCHAR(40)' |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
}; |
34
|
1
|
|
|
|
|
8
|
ok(1); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
711
|
pobject 'PO::Article' => { |
38
|
|
|
|
|
|
|
columns => ['id', 'title', 'author', 'content', 'rating'], |
39
|
|
|
|
|
|
|
#driver => $self->{driver}, |
40
|
|
|
|
|
|
|
serializer => 'storable' |
41
|
|
|
|
|
|
|
}; |
42
|
1
|
|
|
|
|
4
|
ok(1); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#################### |
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# 2. Testing pobject_init() method |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
{ |
49
|
1
|
|
|
|
|
417
|
package PO::Author; |
50
|
1
|
|
|
1
|
|
453
|
use Test::More; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
51
|
|
|
|
|
|
|
*pobject_init = sub { |
52
|
71
|
|
|
71
|
|
434
|
$_[0]->set_datasource($self->{datasource}); |
53
|
71
|
|
|
|
|
283
|
ok(ref($_[0]) eq 'PO::Author') |
54
|
1
|
|
|
|
|
7
|
}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
package PO::Article; |
57
|
1
|
|
|
1
|
|
337
|
use Test::More; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
58
|
|
|
|
|
|
|
*pobject_init = sub { |
59
|
5
|
|
|
5
|
|
30
|
$_[0]->set_datasource($self->{datasource}); |
60
|
5
|
|
|
|
|
24
|
$_[0]->set_driver( $self->{driver} ); |
61
|
5
|
|
|
|
|
18
|
ok(ref($_[0]) eq 'PO::Article'); |
62
|
1
|
|
|
|
|
7
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# |
66
|
|
|
|
|
|
|
# Setting datasrource on PO::Article |
67
|
|
|
|
|
|
|
# |
68
|
|
|
|
|
|
|
#PO::Article->set_datasource( $self->{datasource} ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
################ |
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
# Testing for the values of @ISA |
73
|
|
|
|
|
|
|
# |
74
|
1
|
|
|
|
|
6
|
ok($PO::Author::ISA[0] eq "Class::PObject::Template"); |
75
|
1
|
|
|
|
|
399
|
ok($PO::Article::ISA[0] eq "Class::PObject::Template"); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#################### |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
# 3. Creating new objects |
81
|
|
|
|
|
|
|
# |
82
|
1
|
|
|
|
|
393
|
my $author1 = new PO::Author(); |
83
|
1
|
|
|
|
|
6
|
ok(ref $author1); |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
415
|
my $author2 = new PO::Author(); |
86
|
1
|
|
|
|
|
35
|
ok(ref $author2); |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
429
|
my $author3 = new PO::Author(name=>"Geek", email=>'sherzodr@cpan.org'); |
89
|
1
|
|
|
|
|
6
|
ok(ref $author3); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
456
|
my $article1 = new PO::Article(); |
93
|
1
|
|
|
|
|
6
|
ok(ref $article1); |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
455
|
my $article2 = new PO::Article(); |
96
|
1
|
|
|
|
|
6
|
ok(ref $article2); |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
398
|
my $article3 = new PO::Article(); |
99
|
1
|
|
|
|
|
6
|
ok(ref $article3); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
################ |
103
|
|
|
|
|
|
|
# |
104
|
|
|
|
|
|
|
# Testing if our object is a 'Class::PObject::Template' |
105
|
|
|
|
|
|
|
# |
106
|
1
|
|
33
|
|
|
443
|
ok($author1->isa('Class::PObject::Template') && $author2->isa('Class::PObject::Template') && |
107
|
|
|
|
|
|
|
$article1->isa('Class::PObject::Template')); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
################ |
110
|
|
|
|
|
|
|
# |
111
|
|
|
|
|
|
|
# Testing if driver of the object is of "Class::PObject::Driver::$driver": |
112
|
|
|
|
|
|
|
# |
113
|
1
|
|
|
|
|
407
|
ok($author1->__driver()->isa("Class::PObject::Driver::" . $self->{driver})); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
################ |
116
|
|
|
|
|
|
|
# |
117
|
|
|
|
|
|
|
# Testing if overloading is applicable |
118
|
|
|
|
|
|
|
# to these particular objects |
119
|
|
|
|
|
|
|
# |
120
|
1
|
|
|
|
|
3598
|
ok(overload::Overloaded($author1)); |
121
|
1
|
|
|
|
|
3142
|
ok(overload::Overloaded($author2)); |
122
|
1
|
|
|
|
|
542
|
ok(overload::Overloaded($author3)); |
123
|
1
|
|
|
|
|
521
|
ok(overload::Overloaded($article1)); |
124
|
1
|
|
|
|
|
657
|
ok(overload::Overloaded($article2)); |
125
|
1
|
|
|
|
|
478
|
ok(overload::Overloaded($article3)); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#################### |
128
|
|
|
|
|
|
|
# |
129
|
|
|
|
|
|
|
# 4. Test columns(), __props() and __driver() methods |
130
|
|
|
|
|
|
|
# |
131
|
1
|
|
|
|
|
470
|
ok(ref($author1) eq 'PO::Author'); |
132
|
1
|
|
|
|
|
443
|
ok(ref($author1->columns) eq 'HASH'); |
133
|
1
|
|
|
|
|
472
|
ok(ref($author1->__props) eq 'HASH'); |
134
|
1
|
|
|
|
|
465
|
ok(ref($author1->__driver) eq 'Class::PObject::Driver::' . $self->{driver}); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
#################### |
138
|
|
|
|
|
|
|
# |
139
|
|
|
|
|
|
|
# 5. Test if accessor methods have been created successfully |
140
|
|
|
|
|
|
|
# |
141
|
1
|
|
33
|
|
|
470
|
ok($author1->can('id') && $author2->can('name') && $author3->can('email')); |
142
|
1
|
50
|
|
|
|
440
|
ok($author1->name ? 0 : 1); |
143
|
|
|
|
|
|
|
#ok(1); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
1
|
|
33
|
|
|
538
|
ok($article1->can('id') && $article2->can('title') && $article3->can('author')); |
147
|
|
|
|
|
|
|
#exit; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#################### |
150
|
|
|
|
|
|
|
# |
151
|
|
|
|
|
|
|
# 6. Checking if accessor methods function as expected |
152
|
|
|
|
|
|
|
# |
153
|
1
|
|
|
|
|
441
|
$author1->name("Sherzod Ruzmetov"); |
154
|
1
|
|
|
|
|
4
|
$author1->url('http://author.handalak.com/'); |
155
|
1
|
|
|
|
|
7
|
$author1->email('sherzodr@cpan.org'); |
156
|
|
|
|
|
|
|
|
157
|
1
|
|
|
|
|
3
|
my $name = $author1->name(); |
158
|
1
|
|
|
|
|
16
|
ok($name->isa("Class::PObject::Type")); |
159
|
1
|
|
|
|
|
669
|
ok($name eq "Sherzod Ruzmetov"); |
160
|
|
|
|
|
|
|
|
161
|
1
|
|
|
|
|
612
|
ok($author1->name eq "Sherzod Ruzmetov"); |
162
|
1
|
|
|
|
|
509
|
ok($author1->email eq 'sherzodr@cpan.org'); |
163
|
|
|
|
|
|
|
|
164
|
1
|
|
|
|
|
494
|
$author1->name(undef); |
165
|
|
|
|
|
|
|
|
166
|
1
|
50
|
|
|
|
5
|
ok($author1->name ? 0 : 1); |
167
|
|
|
|
|
|
|
#ok($author1->{_is_new} == 1); |
168
|
1
|
|
|
|
|
586
|
ok(1); |
169
|
|
|
|
|
|
|
#exit; |
170
|
|
|
|
|
|
|
|
171
|
1
|
|
|
|
|
429
|
$author2->name("Hilola Nasyrova"); |
172
|
1
|
|
|
|
|
4
|
$author2->url('http://hilola.handalak.com/'); |
173
|
1
|
|
|
|
|
6
|
$author2->email('some@email.com'); |
174
|
|
|
|
|
|
|
|
175
|
1
|
|
|
|
|
5
|
ok($author2->name eq "Hilola Nasyrova"); |
176
|
1
|
|
|
|
|
529
|
ok($author2->email eq 'some@email.com'); |
177
|
1
|
|
|
|
|
442
|
ok($author2->{_is_new} == 1); |
178
|
|
|
|
|
|
|
|
179
|
1
|
|
|
|
|
429
|
$article1->title("Class::PObject rules!"); |
180
|
1
|
|
|
|
|
5
|
$article1->content("This is the article about Class::PObject and how great this library is"); |
181
|
1
|
|
|
|
|
5
|
$article1->rating(0); |
182
|
|
|
|
|
|
|
|
183
|
1
|
|
|
|
|
4
|
ok($article1->title eq "Class::PObject rules!"); |
184
|
1
|
|
|
|
|
521
|
ok($article1->rating == 0); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
#################### |
188
|
|
|
|
|
|
|
# |
189
|
|
|
|
|
|
|
# 7. Testing save() |
190
|
|
|
|
|
|
|
# |
191
|
1
|
|
|
|
|
450
|
my $author1_id = undef; |
192
|
1
|
|
|
|
|
15
|
ok($author1_id = $author1->save); |
193
|
|
|
|
|
|
|
|
194
|
1
|
|
|
|
|
675
|
my $author2_id = undef; |
195
|
1
|
|
|
|
|
6
|
ok($author2_id = $author2->save); |
196
|
|
|
|
|
|
|
|
197
|
1
|
|
|
|
|
373
|
my $author3_id = undef; |
198
|
1
|
|
|
|
|
6
|
ok($author3_id = $author3->save); |
199
|
|
|
|
|
|
|
|
200
|
1
|
|
|
|
|
572
|
$article1->author($author1_id); |
201
|
|
|
|
|
|
|
|
202
|
1
|
|
|
|
|
3
|
my $article1_id = undef; |
203
|
1
|
|
|
|
|
11
|
print $article1->dump; |
204
|
1
|
|
|
|
|
1209
|
ok($article1_id = $article1->save); |
205
|
|
|
|
|
|
|
|
206
|
1
|
|
|
|
|
345
|
ok($article1_id == $article1->id); |
207
|
1
|
|
|
|
|
219
|
ok($article1 == $article1_id); |
208
|
|
|
|
|
|
|
|
209
|
1
|
|
|
|
|
211
|
undef($author1); |
210
|
1
|
|
|
|
|
35
|
undef($author2); |
211
|
1
|
|
|
|
|
7
|
undef($article1); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# |
214
|
|
|
|
|
|
|
# 'undef'ining 'datasource' class attribute. |
215
|
|
|
|
|
|
|
# Since this attribuate was defined inside pobject_init() earlier, |
216
|
|
|
|
|
|
|
# we need to check whether will it be redefined when load() is called |
217
|
|
|
|
|
|
|
# |
218
|
|
|
|
|
|
|
{ |
219
|
1
|
|
|
1
|
|
1005
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2473
|
|
|
1
|
|
|
|
|
13
|
|
220
|
1
|
|
|
|
|
2
|
${"PO::Article::props"}->{datasource} = undef; |
|
1
|
|
|
|
|
5
|
|
221
|
1
|
|
|
|
|
3
|
${"PO::Author::props"}->{datasource} = undef; |
|
1
|
|
|
|
|
4
|
|
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
#################### |
226
|
|
|
|
|
|
|
# |
227
|
|
|
|
|
|
|
# 8. Testing load() and integrity of the object |
228
|
|
|
|
|
|
|
# |
229
|
|
|
|
|
|
|
|
230
|
1
|
|
|
|
|
11
|
$article1 = PO::Article->load($article1_id); |
231
|
1
|
|
|
|
|
3
|
ok($article1); |
232
|
|
|
|
|
|
|
|
233
|
1
|
|
|
|
|
202
|
ok($article1->title eq "Class::PObject rules!"); |
234
|
1
|
|
|
|
|
205
|
ok(defined $article1->rating); |
235
|
1
|
|
|
|
|
255
|
ok($article1->rating == 0); |
236
|
|
|
|
|
|
|
|
237
|
1
|
|
|
|
|
227
|
$author1 = PO::Author->load($article1->author); |
238
|
1
|
|
|
|
|
4
|
ok($author1); |
239
|
|
|
|
|
|
|
|
240
|
1
|
|
|
|
|
195
|
ok($author1->{_is_new} == 0); |
241
|
1
|
|
|
|
|
209
|
ok($author1->email eq 'sherzodr@cpan.org'); |
242
|
1
|
50
|
|
|
|
232
|
ok($author1->name ? 0 : 1); |
243
|
1
|
|
|
|
|
207
|
ok($author1->url eq 'http://author.handalak.com/'); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
#################### |
246
|
|
|
|
|
|
|
# |
247
|
|
|
|
|
|
|
# 9. Checking if object properties can be updated |
248
|
|
|
|
|
|
|
# |
249
|
1
|
|
|
|
|
290
|
$author1->url('http://sherzodr.handalak.com/'); |
250
|
1
|
|
|
|
|
6
|
$author1->name("Sherzod Ruzmetov"); |
251
|
1
|
|
|
|
|
4
|
ok($author1->save); |
252
|
|
|
|
|
|
|
|
253
|
1
|
|
|
|
|
290
|
$author1 = undef; |
254
|
1
|
|
|
|
|
11
|
$author1 = PO::Author->load($author1_id); |
255
|
1
|
|
|
|
|
4
|
ok($author1); |
256
|
|
|
|
|
|
|
|
257
|
1
|
|
|
|
|
200
|
ok($author1->name eq "Sherzod Ruzmetov"); |
258
|
1
|
|
|
|
|
201
|
ok($author1->email eq "sherzodr\@cpan.org"); |
259
|
1
|
|
|
|
|
301
|
ok($author1->url eq 'http://sherzodr.handalak.com/'); |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
#################### |
262
|
|
|
|
|
|
|
# |
263
|
|
|
|
|
|
|
# 10. load()ing pobject in array context |
264
|
|
|
|
|
|
|
# |
265
|
1
|
|
|
|
|
200
|
my @authors = PO::Author->load(); |
266
|
1
|
|
|
|
|
5
|
ok(@authors == 3); |
267
|
1
|
|
|
|
|
294
|
for ( @authors ) { |
268
|
3
|
|
|
|
|
14
|
printf("[%d] - %s <%s>\n", $_->id, $_->name, $_->email) |
269
|
|
|
|
|
|
|
} |
270
|
1
|
|
|
|
|
12
|
@authors = undef; |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
################ |
275
|
|
|
|
|
|
|
# |
276
|
|
|
|
|
|
|
# FIX: if load(0) was treated the same way as load() |
277
|
|
|
|
|
|
|
# |
278
|
1
|
|
|
|
|
8
|
my $author4 = PO::Author->load(0); |
279
|
1
|
|
|
|
|
6
|
ok(!$author4); |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
#################### |
282
|
|
|
|
|
|
|
# |
283
|
|
|
|
|
|
|
# 11. Loading object(s) in array context with terms |
284
|
|
|
|
|
|
|
# |
285
|
1
|
|
|
|
|
312
|
@authors = PO::Author->load({id=>$author1_id}); |
286
|
1
|
|
|
|
|
4
|
for ( @authors ) { |
287
|
1
|
|
|
|
|
5
|
ok($_->name eq "Sherzod Ruzmetov"); |
288
|
1
|
|
|
|
|
240
|
ok($_->email eq "sherzodr\@cpan.org") |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
#################### |
293
|
|
|
|
|
|
|
# |
294
|
|
|
|
|
|
|
# 12. Checking count() |
295
|
|
|
|
|
|
|
# |
296
|
1
|
|
|
|
|
232
|
ok(PO::Author->count == 3); |
297
|
|
|
|
|
|
|
|
298
|
1
|
|
|
|
|
316
|
ok(PO::Author->count({name=>"Doesn't exist!"}) == 0); |
299
|
|
|
|
|
|
|
|
300
|
1
|
|
|
|
|
260
|
ok(PO::Author->count({email=>'sherzodr@cpan.org', name=>"Sherzod Ruzmetov"}) == 1); |
301
|
|
|
|
|
|
|
|
302
|
1
|
|
|
|
|
574
|
ok(PO::Author->count({email=>'sherzodr@cpan.org'}) == 2); |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
#################### |
306
|
|
|
|
|
|
|
# |
307
|
|
|
|
|
|
|
# 13. Checking more complex terms |
308
|
|
|
|
|
|
|
# |
309
|
1
|
|
|
|
|
518
|
@authors = PO::Author->load({email=>'sherzodr@cpan.org', name=>"Sherzod Ruzmetov"}); |
310
|
1
|
|
|
|
|
21
|
ok(@authors == 1); |
311
|
1
|
|
|
|
|
603
|
ok($authors[0]->id == $author1_id); |
312
|
1
|
|
|
|
|
399
|
ok($authors[0]->url eq 'http://sherzodr.handalak.com/', $authors[0]->url); |
313
|
|
|
|
|
|
|
|
314
|
1
|
|
|
|
|
296
|
@authors = undef; |
315
|
1
|
|
|
|
|
9
|
@authors = PO::Author->load({url=>'http://hilola.handalak.com/', name=>"Bogus"}); |
316
|
1
|
|
|
|
|
6
|
ok(@authors == 0); |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
|
319
|
1
|
|
|
|
|
442
|
@authors = PO::Author->load({url=>'http://hilola.handalak.com/'}); |
320
|
1
|
|
|
|
|
5
|
ok(@authors == 1); |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
#################### |
324
|
|
|
|
|
|
|
# |
325
|
|
|
|
|
|
|
# 14. Checking load(undef, \%args) syntax |
326
|
|
|
|
|
|
|
# |
327
|
1
|
|
|
|
|
371
|
@authors = PO::Author->load(undef, {'sort' => 'name'}); |
328
|
1
|
|
|
|
|
6
|
ok(@authors == 3); |
329
|
|
|
|
|
|
|
|
330
|
1
|
|
|
|
|
731
|
ok($authors[0]->name eq "Geek"); |
331
|
1
|
|
|
|
|
545
|
ok($authors[1]->name eq "Hilola Nasyrova"); |
332
|
1
|
|
|
|
|
574
|
ok($authors[2]->name eq "Sherzod Ruzmetov"); |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
|
338
|
1
|
|
|
|
|
544
|
@authors = (); |
339
|
1
|
|
|
|
|
11
|
@authors = PO::Author->load(undef, {'sort' => 'email'}); |
340
|
1
|
|
|
|
|
7
|
ok(@authors == 3); |
341
|
|
|
|
|
|
|
|
342
|
1
|
|
|
|
|
434
|
ok($authors[0]->email eq 'sherzodr@cpan.org'); |
343
|
1
|
|
|
|
|
603
|
ok($authors[1]->email eq 'sherzodr@cpan.org'); |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
# same as above, but with explicit 'direction' |
350
|
1
|
|
|
|
|
400
|
@authors = (); |
351
|
1
|
|
|
|
|
11
|
@authors = PO::Author->load(undef, {'sort' => 'email', direction=>'asc'}); |
352
|
1
|
|
|
|
|
6
|
ok(@authors == 3); |
353
|
|
|
|
|
|
|
|
354
|
1
|
|
|
|
|
494
|
ok($authors[0]->email eq 'sherzodr@cpan.org'); |
355
|
1
|
|
|
|
|
384
|
ok($authors[1]->email eq 'sherzodr@cpan.org'); |
356
|
1
|
|
|
|
|
478
|
ok($authors[2]->email eq 'some@email.com'); |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
|
364
|
1
|
|
|
|
|
432
|
@authors = (); |
365
|
1
|
|
|
|
|
10
|
@authors = PO::Author->load(undef, {'sort'=>'name', direction=>'desc'}); |
366
|
1
|
|
|
|
|
8
|
ok(@authors == 3); |
367
|
|
|
|
|
|
|
|
368
|
1
|
|
|
|
|
406
|
ok($authors[0]->name eq "Sherzod Ruzmetov"); |
369
|
1
|
|
|
|
|
553
|
ok($authors[1]->name eq "Hilola Nasyrova"); |
370
|
1
|
|
|
|
|
403
|
ok($authors[2]->name eq "Geek"); |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
|
375
|
1
|
|
|
|
|
476
|
@authors = (); |
376
|
1
|
|
|
|
|
11
|
@authors = PO::Author->load(undef, {'sort'=>'id', direction=>'desc', limit=>1}); |
377
|
1
|
|
|
|
|
7
|
ok(@authors == 1); |
378
|
|
|
|
|
|
|
|
379
|
1
|
|
|
|
|
460
|
ok($authors[0]->name eq "Geek"); |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
# same as above, but with explicit 'offset' |
384
|
1
|
|
|
|
|
450
|
@authors = (); |
385
|
1
|
|
|
|
|
11
|
@authors = PO::Author->load(undef, {'sort'=>'id', direction=>'desc', limit=>1, offset=>0}); |
386
|
1
|
|
|
|
|
6
|
ok(@authors == 1); |
387
|
|
|
|
|
|
|
|
388
|
1
|
|
|
|
|
407
|
ok($authors[0]->name eq "Geek"); |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
|
392
|
1
|
|
|
|
|
470
|
@authors = (); |
393
|
1
|
|
|
|
|
11
|
@authors = PO::Author->load(undef, {'sort'=>'id', direction=>'desc', offset=>1, limit=>1}); |
394
|
1
|
|
|
|
|
7
|
ok(@authors == 1); |
395
|
|
|
|
|
|
|
|
396
|
1
|
|
|
|
|
389
|
ok($authors[0]->name eq "Hilola Nasyrova"); |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
|
400
|
1
|
|
|
|
|
405
|
$author1 = PO::Author->load(undef, {'sort'=>'id', direction=>'desc', limit=>1}); |
401
|
1
|
|
|
|
|
13
|
ok($author1); |
402
|
1
|
|
|
|
|
394
|
ok($author1->name eq "Geek"); |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
#################### |
407
|
|
|
|
|
|
|
# |
408
|
|
|
|
|
|
|
# 15. Checking load(\%terms, \%args) syntax |
409
|
|
|
|
|
|
|
# |
410
|
1
|
|
|
|
|
395
|
@authors = (); |
411
|
1
|
|
|
|
|
9
|
@authors = PO::Author->load({name=>"Sherzod Ruzmetov"}, {'sort'=>'name'}); |
412
|
1
|
|
|
|
|
8
|
ok(@authors == 1); |
413
|
1
|
|
|
|
|
455
|
ok($authors[0]->email eq 'sherzodr@cpan.org'); |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
|
421
|
1
|
|
|
|
|
451
|
@authors = (); |
422
|
1
|
|
|
|
|
10
|
@authors = PO::Author->load({email=>'sherzodr@cpan.org'}, {'sort'=>'name'}); |
423
|
1
|
|
|
|
|
7
|
ok(@authors == 2); |
424
|
|
|
|
|
|
|
|
425
|
1
|
|
|
|
|
386
|
ok($authors[0]->name eq "Geek"); |
426
|
1
|
|
|
|
|
443
|
ok($authors[1]->name eq "Sherzod Ruzmetov"); |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
|
431
|
1
|
|
|
|
|
388
|
@authors = (); |
432
|
1
|
|
|
|
|
11
|
@authors = PO::Author->load({email=>'sherzodr@cpan.org'}, {'sort'=>'name', direction=>'desc'}); |
433
|
1
|
|
|
|
|
7
|
ok(@authors == 2); |
434
|
|
|
|
|
|
|
|
435
|
1
|
|
|
|
|
468
|
ok($authors[0]->name eq "Sherzod Ruzmetov"); |
436
|
1
|
|
|
|
|
448
|
ok($authors[1]->name eq "Geek"); |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
|
441
|
1
|
|
|
|
|
397
|
@authors = PO::Author->load({email=>'sherzodr@cpan.org'}, {'sort'=>'name', direction=>'asc', limit=>1}); |
442
|
1
|
|
|
|
|
359
|
ok(@authors == 1); |
443
|
|
|
|
|
|
|
|
444
|
1
|
|
|
|
|
523
|
ok($authors[0]->name eq "Geek"); |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
|
448
|
1
|
|
|
|
|
447
|
$author3 = undef; |
449
|
1
|
|
|
|
|
16
|
$author3 = PO::Author->load({email=>'sherzodr@cpan.org'}, {'sort'=>'name', direction=>'asc', limit=>1}); |
450
|
1
|
|
|
|
|
6
|
ok($author3); |
451
|
1
|
|
|
|
|
461
|
ok($author3->name eq "Geek"); |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
|
454
|
1
|
|
|
|
|
377
|
@authors = PO::Author->load({email=>'sherzodr@cpan.org'}, {'sort'=>'name', limit=>1, offset=>1}); |
455
|
1
|
|
|
|
|
6
|
ok(@authors == 1); |
456
|
|
|
|
|
|
|
|
457
|
1
|
|
|
|
|
377
|
ok($authors[0]->name eq "Sherzod Ruzmetov"); |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
################### |
461
|
|
|
|
|
|
|
# |
462
|
|
|
|
|
|
|
# Checking the iterator |
463
|
|
|
|
|
|
|
# |
464
|
1
|
|
|
|
|
454
|
my $iterator = PO::Author->fetch(undef, {'sort'=>'name'}); |
465
|
|
|
|
|
|
|
#die $iterator->dump; |
466
|
1
|
|
|
|
|
5
|
ok( $iterator->size == 3); |
467
|
|
|
|
|
|
|
#die $iterator->size; |
468
|
1
|
|
|
|
|
464
|
ok(ref $iterator eq "Class::PObject::Iterator"); |
469
|
1
|
|
|
|
|
387
|
$author1 = $iterator->next(); |
470
|
1
|
|
|
|
|
13
|
ok(ref $author1 eq "PO::Author"); |
471
|
1
|
|
|
|
|
417
|
ok( $author1->name eq "Geek"); |
472
|
|
|
|
|
|
|
|
473
|
1
|
|
|
|
|
420
|
$author2 = $iterator->next(); |
474
|
1
|
|
|
|
|
6
|
ok( ref $author2 eq "PO::Author"); |
475
|
1
|
|
|
|
|
384
|
ok( $author2->name eq "Hilola Nasyrova"); |
476
|
|
|
|
|
|
|
|
477
|
1
|
|
|
|
|
409
|
ok( $iterator->size == 1); |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
# trying to iterate through the list. We should |
480
|
|
|
|
|
|
|
# have only one object left, since we already called next() two times: |
481
|
1
|
|
|
|
|
365
|
while ( my $author = $iterator->next ) { |
482
|
1
|
|
|
|
|
4
|
ok( $author->name eq "Sherzod Ruzmetov" ); |
483
|
|
|
|
|
|
|
} |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
# now we need to reset the pointers: |
486
|
1
|
|
|
|
|
5
|
$iterator->reset(); |
487
|
|
|
|
|
|
|
|
488
|
1
|
|
|
|
|
4
|
while ( my $author = $iterator->next ) { |
489
|
3
|
|
|
|
|
11
|
ok( ref $author eq "PO::Author"); |
490
|
|
|
|
|
|
|
} |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
#################### |
494
|
|
|
|
|
|
|
# |
495
|
|
|
|
|
|
|
# Cleaning up all the objects so that for the next 'make test' |
496
|
|
|
|
|
|
|
# can start with brand new scratch board |
497
|
|
|
|
|
|
|
# |
498
|
|
|
|
|
|
|
|
499
|
1
|
|
|
|
|
6
|
$iterator->reset(); |
500
|
1
|
|
|
|
|
5
|
my $author = $iterator->next; |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
# removing author named 'Geek': |
503
|
1
|
|
|
|
|
16
|
ok($author->remove, $author->errstr); |
504
|
|
|
|
|
|
|
|
505
|
1
|
|
|
|
|
387
|
ok(PO::Author->count == 2, "count: " . PO::Author->count); |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
# again trying to remove the author 'Geek'. This should have no |
508
|
|
|
|
|
|
|
# effect, since it's been removed in previous query |
509
|
1
|
|
|
|
|
511
|
ok(PO::Author->remove_all({name=>"Geek"})); |
510
|
|
|
|
|
|
|
# we still should have two objects in total in our database |
511
|
1
|
|
|
|
|
469
|
ok(PO::Author->count == 2, "count: " . PO::Author->count); |
512
|
1
|
|
|
|
|
498
|
ok(PO::Author->remove_all); |
513
|
1
|
|
|
|
|
458
|
ok(PO::Author->count == 0); |
514
|
|
|
|
|
|
|
|
515
|
1
|
|
|
|
|
461
|
ok(PO::Article->remove_all); |
516
|
1
|
|
|
|
|
585
|
ok(PO::Article->count == 0); |
517
|
|
|
|
|
|
|
|
518
|
1
|
|
|
|
|
405
|
ok(PO::Article->drop_datasource); |
519
|
1
|
|
|
|
|
420
|
ok(PO::Author->drop_datasource); |
520
|
|
|
|
|
|
|
} |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
1; |
531
|
|
|
|
|
|
|
__END__ |