line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAO::testcases::FS::collection; |
2
|
1
|
|
|
1
|
|
766
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
548
|
use Error qw(:try); |
|
1
|
|
|
|
|
3793
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
733
|
use XAO::Utils; |
|
1
|
|
|
|
|
15233
|
|
|
1
|
|
|
|
|
88
|
|
5
|
1
|
|
|
1
|
|
573
|
use XAO::Objects; |
|
1
|
|
|
|
|
5547
|
|
|
1
|
|
|
|
|
44
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
9
|
use base qw(XAO::testcases::FS::base); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
583
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# It used to return a damaged object |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub test_am_20031029_wrong_id { |
12
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
13
|
0
|
|
|
|
|
|
my $odb=$self->get_odb; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $coll=$odb->collection(class => 'Data::Customer'); |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $c; |
18
|
|
|
|
|
|
|
try { |
19
|
0
|
|
|
0
|
|
|
$c=$coll->get(9876543); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
otherwise { |
22
|
0
|
|
|
0
|
|
|
my $e=shift; |
23
|
0
|
|
|
|
|
|
dprint "Expected error: $e"; |
24
|
0
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$self->assert(!$c, |
27
|
|
|
|
|
|
|
"Returned non-existing object"); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
## |
31
|
|
|
|
|
|
|
# my $ingredients = $odb->collection('class' => 'Data::Ingredient') ; |
32
|
|
|
|
|
|
|
# my $result = $ingredients->search( |
33
|
|
|
|
|
|
|
# { orderby => ['ascend' => 'name'], |
34
|
|
|
|
|
|
|
# distinct => 'name' } |
35
|
|
|
|
|
|
|
# ) ; |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# ... doesn't seem to work correctly. It returns a list containing a |
38
|
|
|
|
|
|
|
# large list of identical keys, like: |
39
|
|
|
|
|
|
|
# |
40
|
|
|
|
|
|
|
# [ 5589, 5589, 5589, 5589 ... ] |
41
|
|
|
|
|
|
|
# |
42
|
|
|
|
|
|
|
sub test_bild_20030611_distinct { |
43
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
44
|
0
|
|
|
|
|
|
my $odb=$self->get_odb; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $c1=$odb->fetch('/Customers/c1'); |
47
|
0
|
|
|
|
|
|
$c1->build_structure( |
48
|
|
|
|
|
|
|
Orders => { |
49
|
|
|
|
|
|
|
type => 'list', |
50
|
|
|
|
|
|
|
class => 'Data::Order', |
51
|
|
|
|
|
|
|
key => 'order_id', |
52
|
|
|
|
|
|
|
structure => { |
53
|
|
|
|
|
|
|
name => { |
54
|
|
|
|
|
|
|
type => 'text', |
55
|
|
|
|
|
|
|
maxlength => 100, |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
}, |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $orders1=$c1->get('Orders'); |
62
|
0
|
|
|
|
|
|
my $orders2=$odb->fetch('/Customers/c2/Orders'); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $nc=$orders1->get_new; |
65
|
0
|
|
|
|
|
|
$nc->put(name => 'test1'); |
66
|
0
|
|
|
|
|
|
$orders1->put(test1_1_1 => $nc); |
67
|
0
|
|
|
|
|
|
$orders1->put(test1_2_1 => $nc); |
68
|
0
|
|
|
|
|
|
$orders1->put(test1_3_1 => $nc); |
69
|
0
|
|
|
|
|
|
$orders2->put(test1_1_2 => $nc); |
70
|
0
|
|
|
|
|
|
$orders2->put(test1_2_2 => $nc); |
71
|
0
|
|
|
|
|
|
$nc->put(name => 'test2'); |
72
|
0
|
|
|
|
|
|
$orders1->put(test2_1_1 => $nc); |
73
|
0
|
|
|
|
|
|
$orders1->put(test2_2_1 => $nc); |
74
|
0
|
|
|
|
|
|
$orders1->put(test2_3_1 => $nc); |
75
|
0
|
|
|
|
|
|
$orders2->put(test2_1_2 => $nc); |
76
|
0
|
|
|
|
|
|
$orders2->put(test2_2_2 => $nc); |
77
|
0
|
|
|
|
|
|
$nc->put(name => 'test3'); |
78
|
0
|
|
|
|
|
|
$orders1->put(test3_1_1 => $nc); |
79
|
0
|
|
|
|
|
|
$nc->put(name => 'test4'); |
80
|
0
|
|
|
|
|
|
$orders2->put(test4_1_2 => $nc); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $coll=$odb->collection(class => 'Data::Order'); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $sr=$coll->search({ orderby => [ ascend => 'name' ], |
85
|
|
|
|
|
|
|
distinct => 'name' |
86
|
|
|
|
|
|
|
}); |
87
|
0
|
|
|
|
|
|
my $t1c=0; |
88
|
0
|
|
|
|
|
|
my $t2c=0; |
89
|
0
|
|
|
|
|
|
my $t3c=0; |
90
|
0
|
|
|
|
|
|
my $t4c=0; |
91
|
0
|
|
|
|
|
|
foreach my $id (@$sr) { |
92
|
0
|
|
|
|
|
|
my $cust_id=$coll->get($id)->container_key; |
93
|
0
|
0
|
|
|
|
|
$t1c++ if $cust_id =~ /test1_/; |
94
|
0
|
0
|
|
|
|
|
$t2c++ if $cust_id =~ /test2_/; |
95
|
0
|
0
|
|
|
|
|
$t3c++ if $cust_id =~ /test3_/; |
96
|
0
|
0
|
|
|
|
|
$t4c++ if $cust_id =~ /test4_/; |
97
|
0
|
|
|
|
|
|
dprint "$id $cust_id"; |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
$self->assert($t1c == 1, |
100
|
|
|
|
|
|
|
"Expected one occurance of test1, got $t1c"); |
101
|
0
|
|
|
|
|
|
$self->assert($t2c == 1, |
102
|
|
|
|
|
|
|
"Expected one occurance of test2, got $t2c"); |
103
|
0
|
|
|
|
|
|
$self->assert($t3c == 1, |
104
|
|
|
|
|
|
|
"Expected one occurance of test3, got $t3c"); |
105
|
0
|
|
|
|
|
|
$self->assert($t4c == 1, |
106
|
|
|
|
|
|
|
"Expected one occurance of test4, got $t4c"); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
## |
110
|
|
|
|
|
|
|
# This is a testcase for a bug reported by Bil on 12/17/2002. It allows |
111
|
|
|
|
|
|
|
# collection to get some sort of read-only clone object by passing array |
112
|
|
|
|
|
|
|
# reference to collection get() method. Should throw an error instead! |
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
sub test_bild_20021217 { |
115
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
116
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my $clist=$odb->collection(class => 'Data::Customer'); |
119
|
0
|
|
|
|
|
|
$self->assert(ref($clist), |
120
|
|
|
|
|
|
|
"Can't create a collection"); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $sr=$clist->search('customer_id','eq','c1'); |
123
|
0
|
|
|
|
|
|
$self->assert(@$sr==1, |
124
|
|
|
|
|
|
|
"Should have got a single value"); |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $pass; |
127
|
|
|
|
|
|
|
try { |
128
|
0
|
|
|
0
|
|
|
my $c=$clist->get($sr); |
129
|
0
|
|
|
|
|
|
$pass=0; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
otherwise { |
132
|
0
|
|
|
0
|
|
|
my $e=shift; |
133
|
|
|
|
|
|
|
## dprint "Expected error: $e"; |
134
|
0
|
|
|
|
|
|
$pass=1; |
135
|
0
|
|
|
|
|
|
}; |
136
|
0
|
|
|
|
|
|
$self->assert($pass, |
137
|
|
|
|
|
|
|
"Managed to get an object by passing array reference to get()"); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
############################################################################### |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub test_describe { |
143
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my $odb = $self->{odb}; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
my $list=$odb->collection(class => 'Data::Customer'); |
148
|
0
|
|
|
|
|
|
$self->assert($list, "Can't create Data::Customer collection"); |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
$self->assert(defined($list->can('describe')), |
151
|
|
|
|
|
|
|
"Can't call function 'describe()' on the Collection object"); |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $desc=$list->describe; |
154
|
0
|
|
|
|
|
|
$self->assert(ref($desc) eq 'HASH', |
155
|
|
|
|
|
|
|
"Collection description is not a hash reference"); |
156
|
0
|
|
|
|
|
|
$self->assert($desc->{type} eq 'collection', |
157
|
|
|
|
|
|
|
"Type is not 'collection'"); |
158
|
0
|
|
|
|
|
|
$self->assert($desc->{class} eq 'Data::Customer', |
159
|
|
|
|
|
|
|
"Class is not 'Data::Customer'"); |
160
|
0
|
|
|
|
|
|
$self->assert($desc->{key} => 'customer_id', |
161
|
|
|
|
|
|
|
"Key is not 'customer_id'"); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
############################################################################### |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub test_everything { |
167
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
168
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
my $clist=$odb->collection(class => 'Data::Customer'); |
171
|
0
|
|
|
|
|
|
$self->assert(ref($clist), |
172
|
|
|
|
|
|
|
"Can't create a collection"); |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
$self->assert($clist->objtype eq 'Collection', |
175
|
|
|
|
|
|
|
"Objtype() is not 'Collection'"); |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
$self->assert($clist->objname eq 'FS::Collection', |
178
|
|
|
|
|
|
|
"Objname() is not 'FS::Collection'"); |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
my @kk=$clist->keys; |
181
|
0
|
|
|
|
|
|
$self->assert(@kk == 2, |
182
|
|
|
|
|
|
|
"Wrong number of items in the collection"); |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
my $c=$clist->get($kk[0]); |
185
|
0
|
|
|
|
|
|
$self->assert($c->objtype eq 'Hash', |
186
|
|
|
|
|
|
|
"Got something wrong from collection"); |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
$self->assert($c->collection_key eq $kk[0], |
189
|
|
|
|
|
|
|
"Wrong value returned by collection_key()"); |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
$self->assert(!!$clist->exists($c->collection_key), |
192
|
|
|
|
|
|
|
"Expected exists to return true"); |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
$self->assert(!$clist->exists(time), |
195
|
|
|
|
|
|
|
"Expected exists to return false in non-existent int key"); |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
$self->assert(!$clist->exists('BAD'), |
198
|
|
|
|
|
|
|
"Expected exists to return false in non-existent text key"); |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my $kn=$c->container_key(); |
201
|
0
|
|
0
|
|
|
|
$self->assert($kn eq 'c1' || $kn eq 'c2', |
202
|
|
|
|
|
|
|
"Container_key returned wrong value ($kn)"); |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
my $name='New Name'; |
205
|
0
|
|
|
|
|
|
$c->put(name => $name); |
206
|
0
|
|
|
|
|
|
my $got=$c->get('name'); |
207
|
0
|
|
|
|
|
|
$self->assert($got eq $name, |
208
|
|
|
|
|
|
|
"Something wrong with the hash object we got ($got!=$name)"); |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
my $uri=$c->uri; |
211
|
0
|
|
0
|
|
|
|
$self->assert($uri && $uri =~ '/Customers/c?', |
212
|
|
|
|
|
|
|
"Wrong URI ($uri)"); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub test_deeper { |
216
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
217
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
my $c=$odb->fetch('/Customers/c2'); |
220
|
0
|
|
|
|
|
|
$c->add_placeholder(name => 'Orders', |
221
|
|
|
|
|
|
|
type => 'list', |
222
|
|
|
|
|
|
|
class => 'Data::Order', |
223
|
|
|
|
|
|
|
key => 'order_id', |
224
|
|
|
|
|
|
|
); |
225
|
0
|
|
|
|
|
|
my $orders=$c->get('Orders'); |
226
|
0
|
|
|
|
|
|
my $o=$orders->get_new(); |
227
|
0
|
|
|
|
|
|
$o->add_placeholder(name => 'foo', |
228
|
|
|
|
|
|
|
type => 'text', |
229
|
|
|
|
|
|
|
maxlength => 20); |
230
|
0
|
|
|
|
|
|
$o->put(foo => 'test'); |
231
|
0
|
|
|
|
|
|
$orders->put($o); |
232
|
0
|
|
|
|
|
|
$o->put(foo => 'fubar'); |
233
|
0
|
|
|
|
|
|
$orders->put($o); |
234
|
0
|
|
|
|
|
|
$o->put(foo => 'junk'); |
235
|
0
|
|
|
|
|
|
$orders->put($o); |
236
|
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
my $coll=$odb->collection(class => 'Data::Order'); |
238
|
0
|
|
|
|
|
|
$self->assert(ref($coll), |
239
|
|
|
|
|
|
|
"Can't create a collection"); |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
$self->assert($coll->objtype eq 'Collection', |
242
|
|
|
|
|
|
|
"Objtype() is not 'Collection'"); |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
$self->assert($coll->objname eq 'FS::Collection', |
245
|
|
|
|
|
|
|
"Objname() is not 'FS::Collection'"); |
246
|
|
|
|
|
|
|
|
247
|
0
|
|
|
|
|
|
my @kk=$coll->keys; |
248
|
0
|
|
|
|
|
|
$self->assert(@kk == 3, |
249
|
|
|
|
|
|
|
"Wrong number of items in the collection"); |
250
|
|
|
|
|
|
|
|
251
|
0
|
|
|
|
|
|
my $item=$coll->get($kk[1]); |
252
|
0
|
|
|
|
|
|
$self->assert($item->objtype eq 'Hash', |
253
|
|
|
|
|
|
|
"Got something wrong from collection"); |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
|
|
|
my $foo='New Name'; |
256
|
0
|
|
|
|
|
|
$item->put(foo => $foo); |
257
|
0
|
|
|
|
|
|
my $got=$item->get('foo'); |
258
|
0
|
|
|
|
|
|
$self->assert($got eq $foo, |
259
|
|
|
|
|
|
|
"Something wrong with the hash object we got ($got!=$foo)"); |
260
|
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
|
my $uri=$item->uri; |
262
|
0
|
|
0
|
|
|
|
$self->assert($uri && $uri =~ '^/Customers/c2/Orders/', |
263
|
|
|
|
|
|
|
"Wrong URI ($uri)"); |
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
$item=$coll->get($kk[0]); |
266
|
0
|
|
|
|
|
|
$self->assert($item->objtype eq 'Hash', |
267
|
|
|
|
|
|
|
"Got something wrong from collection"); |
268
|
|
|
|
|
|
|
|
269
|
0
|
|
|
|
|
|
$item=$coll->get($kk[2]); |
270
|
0
|
|
|
|
|
|
$self->assert($item->objtype eq 'Hash', |
271
|
|
|
|
|
|
|
"Got something wrong from collection"); |
272
|
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
|
my $list=$coll->search('foo', 'cs', 'New'); |
274
|
0
|
|
0
|
|
|
|
$self->assert($list && scalar(@$list), |
275
|
|
|
|
|
|
|
"Wrong search results on collection"); |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
|
my $id=$list->[0]; |
278
|
0
|
|
|
|
|
|
$item=$coll->get($id); |
279
|
0
|
|
|
|
|
|
$self->assert(ref($item), |
280
|
|
|
|
|
|
|
"Can't get order reference using search results"); |
281
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
|
$got=$item->get('foo'); |
283
|
0
|
|
|
|
|
|
$self->assert($got =~ /New/, |
284
|
|
|
|
|
|
|
"Wrong search results from collection ($got !~ /New/)"); |
285
|
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
|
$foo='Super-Duper'; |
287
|
0
|
|
|
|
|
|
$item->put(foo => $foo); |
288
|
0
|
|
|
|
|
|
$got=$item->get('foo'); |
289
|
0
|
|
|
|
|
|
$self->assert($got eq $foo, |
290
|
|
|
|
|
|
|
"Something wrong with the hash object we got ($got!=$foo)"); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
1; |