5 use Test
::More tests
=> 12;
7 use Koha
::Acquisition
::Baskets
; # Koha::Acquisition::Baskets uses the mixin
8 use Koha
::AdditionalFields
;
9 use Koha
::AdditionalFieldValues
;
12 use t
::lib
::TestBuilder
;
14 my $storage = Koha
::Database
->new->schema->storage;
17 my $builder = t
::lib
::TestBuilder
->new;
18 my $basket1 = $builder->build_object({
19 class => 'Koha::Acquisition::Baskets',
21 my $basket2 = $builder->build_object({
22 class => 'Koha::Acquisition::Baskets',
25 my $foo = Koha
::AdditionalField
->new({
26 tablename
=> 'aqbasket',
29 my $bar = Koha
::AdditionalField
->new({
30 tablename
=> 'aqbasket',
34 Koha
::AdditionalFieldValue
->new({
36 record_id
=> $basket1->basketno,
37 value
=> 'foo value for basket1',
39 Koha
::AdditionalFieldValue
->new({
41 record_id
=> $basket1->basketno,
42 value
=> 'bar value for basket1',
45 my $additional_fields_for_basket2 = [
48 value
=> 'foo value for basket2',
52 value
=> 'bar value for basket2',
55 $basket2->set_additional_fields($additional_fields_for_basket2);
57 my $additional_fields = $basket2->additional_field_values;
58 is
( ref($additional_fields), 'Koha::AdditionalFieldValues', '->additional_field_values should return a Koha::AdditionalFieldValues object' );
63 # We are bascially removing the 'id' field here
64 field_id
=> $_->{field_id
},
65 record_id
=> $_->{record_id
},
68 } sort{ $a->{id
} <=> $b->{id
} } @
{ $additional_fields->unblessed }
72 field_id
=> $additional_fields_for_basket2->[0]->{id
},
73 record_id
=> $basket2->basketno,
74 value
=> $additional_fields_for_basket2->[0]->{value
},
77 field_id
=> $additional_fields_for_basket2->[1]->{id
},
78 record_id
=> $basket2->basketno,
79 value
=> $additional_fields_for_basket2->[1]->{value
},
83 '->additional_field_values should return the correct values'
86 my @baskets = Koha
::Acquisition
::Baskets
->filter_by_additional_fields([
89 value
=> 'foo value for basket1',
93 is
(scalar @baskets, 1, 'search returns only one result');
94 is
($baskets[0]->basketno, $basket1->basketno, 'result is basket1');
96 @baskets = Koha
::Acquisition
::Baskets
->filter_by_additional_fields([
99 value
=> 'foo value for basket2',
103 is
(scalar @baskets, 1, 'search returns only one result');
104 is
($baskets[0]->basketno, $basket2->basketno, 'result is basket2');
106 @baskets = Koha
::Acquisition
::Baskets
->filter_by_additional_fields([
109 value
=> 'foo value for basket1',
113 value
=> 'bar value for basket1',
117 is
(scalar @baskets, 1, 'search returns only one result');
118 is
($baskets[0]->basketno, $basket1->basketno, 'result is basket1');
120 @baskets = Koha
::Acquisition
::Baskets
->filter_by_additional_fields([
123 value
=> 'foo value for basket1',
127 value
=> 'bar value for basket2',
131 is
(scalar @baskets, 0, 'search returns no result');
133 @baskets = Koha
::Acquisition
::Baskets
->filter_by_additional_fields([
140 is
(scalar @baskets, 2, 'search returns two results');
142 @baskets = Koha
::Acquisition
::Baskets
->filter_by_additional_fields([
153 is
(scalar @baskets, 1, 'search returns only one result');
154 is
($baskets[0]->basketno, $basket1->basketno, 'result is basket1');
156 $storage->txn_rollback;