3 # This file is part of Koha.
5 # Copyright 2014 - Biblibre SARL
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Test
::More tests
=> 41;
24 use_ok
('t::lib::TestBuilder');
28 my $builder = t
::lib
::TestBuilder
->new();
30 is
( $builder->build(), undef, 'build without arguments returns undef' );
32 my @sources = $builder->schema->sources;
34 for my $source (@sources) {
35 eval { $builder->build( { source
=> $source } ); };
36 $nb_failure++ if ($@
);
38 is
( $nb_failure, 0, 'TestBuilder can create a entry for every sources' );
40 my $my_overduerules_transport_type = {
41 message_transport_type
=> {
42 message_transport_type
=> 'my msg_t_t',
46 branchcode
=> 'codeB',
47 categorycode
=> 'codeC',
49 categorycode
=> undef,
51 $my_overduerules_transport_type->{categorycode
} = $my_overduerules_transport_type->{branchcode
};
52 my $overduerules_transport_type = $builder->build({
53 source
=> 'OverduerulesTransportType',
54 value
=> $my_overduerules_transport_type,
57 $overduerules_transport_type->{message_transport_type
},
58 $my_overduerules_transport_type->{message_transport_type
}->{message_transport_type
},
59 'build stores the message_transport_type correctly'
62 $overduerules_transport_type->{letternumber
},
63 $my_overduerules_transport_type->{letternumber
},
64 'build stores the letternumber correctly'
67 $overduerules_transport_type->{branchcode
},
68 $my_overduerules_transport_type->{branchcode
}->{branchcode
},
69 'build stores the branchcode correctly'
72 $overduerules_transport_type->{categorycode
},
73 $my_overduerules_transport_type->{categorycode
}->{categorycode
},
74 'build stores the categorycode correctly'
77 $overduerules_transport_type->{_fk
}->{message_transport_type
}->{message_transport_type
},
78 $my_overduerules_transport_type->{message_transport_type
}->{message_transport_type
},
79 'build stores the foreign key message_transport_type correctly'
82 $overduerules_transport_type->{_fk
}->{branchcode
}->{branchcode
},
83 $my_overduerules_transport_type->{branchcode
}->{branchcode
},
84 'build stores the foreign key branchcode correctly'
87 $overduerules_transport_type->{_fk
}->{categorycode
}->{categorycode
},
88 $my_overduerules_transport_type->{categorycode
}->{categorycode
},
89 'build stores the foreign key categorycode correctly'
92 $overduerules_transport_type->{_fk
}->{branchcode
},
93 $overduerules_transport_type->{_fk
}->{categorycode
},
94 'build links the branchcode and the categorycode correctly'
97 $overduerules_transport_type->{_fk
}->{branchcode
}->{letter2
},
99 'build generates values if they are not given'
102 my $my_user_permission = $t::lib
::TestBuilder
::default_value
->{UserPermission
};
103 my $user_permission = $builder->build({
104 source
=> 'UserPermission',
107 $user_permission->{borrowernumber
},
109 'build generates a borrowernumber correctly'
112 $user_permission->{module_bit
},
113 $my_user_permission->{module_bit
}->{module_bit
}->{bit
},
114 'build stores the default value correctly'
117 $user_permission->{code
},
118 $my_user_permission->{module_bit
}->{code
},
119 'build stores the default value correctly'
122 $user_permission->{borrowernumber
},
123 $user_permission->{_fk
}->{borrowernumber
}->{borrowernumber
},
124 'build links the foreign key correctly'
127 $user_permission->{_fk
}->{borrowernumber
}->{surname
},
128 $my_user_permission->{borrowernumber
}->{surname
},
129 'build stores the foreign key value correctly'
132 $user_permission->{_fk
}->{borrowernumber
}->{address
},
133 $my_user_permission->{borrowernumber
}->{address
},
134 'build stores the foreign key value correctly'
137 $user_permission->{_fk
}->{borrowernumber
}->{city
},
138 $my_user_permission->{borrowernumber
}->{city
},
139 'build stores the foreign key value correctly'
142 $user_permission->{_fk
}->{borrowernumber
}->{_fk
}->{branchcode
}->{branchcode
},
143 $my_user_permission->{borrowernumber
}->{branchcode
}->{branchcode
},
144 'build stores the foreign key value correctly'
147 $user_permission->{_fk
}->{borrowernumber
}->{_fk
}->{branchcode
}->{branchname
},
148 $my_user_permission->{borrowernumber
}->{branchcode
}->{branchname
},
149 'build stores the foreign key value correctly'
152 $user_permission->{_fk
}->{borrowernumber
}->{_fk
}->{categorycode
}->{categorycode
},
153 $my_user_permission->{borrowernumber
}->{categorycode
}->{categorycode
},
154 'build stores the foreign key value correctly'
157 $user_permission->{_fk
}->{borrowernumber
}->{_fk
}->{categorycode
}->{hidelostitems
},
158 $my_user_permission->{borrowernumber
}->{categorycode
}->{hidelostitems
},
159 'build stores the foreign key value correctly'
162 $user_permission->{_fk
}->{borrowernumber
}->{_fk
}->{categorycode
}->{category_type
},
163 $my_user_permission->{borrowernumber
}->{categorycode
}->{category_type
},
164 'build stores the foreign key value correctly'
167 $user_permission->{_fk
}->{borrowernumber
}->{_fk
}->{categorycode
}->{defaultprivacy
},
168 $my_user_permission->{borrowernumber
}->{categorycode
}->{defaultprivacy
},
169 'build stores the foreign key value correctly'
172 $user_permission->{_fk
}->{borrowernumber
}->{privacy
},
173 $my_user_permission->{borrowernumber
}->{privacy
},
174 'build stores the foreign key value correctly'
177 $user_permission->{_fk
}->{module_bit
}->{_fk
}->{module_bit
}->{bit
},
178 $my_user_permission->{module_bit
}->{module_bit
}->{bit
},
179 'build stores the foreign key value correctly'
182 $user_permission->{_fk
}->{module_bit
}->{code
},
183 $my_user_permission->{module_bit
}->{code
},
184 'build stores the foreign key value correctly'
187 $user_permission->{_fk
}->{module_bit
},
188 $user_permission->{_fk
}->{code
},
189 'build links the codes correctly'
192 $user_permission->{_fk
}->{borrowernumber
}->{cardnumber
},
194 'build generates values if they are not given'
197 $user_permission->{_fk
}->{borrowernumber
}->{_fk
}->{branchcode
}->{branchaddress1
},
199 'build generates values if they are not given'
202 $user_permission->{_fk
}->{borrowernumber
}->{_fk
}->{categorycode
}->{description
},
204 'build generates values if they are not given'
207 $user_permission->{_fk
}->{module_bit
}->{description
},
209 'build generates values if they are not given'
212 $user_permission->{_fk
}->{module_bit
}->{_fk
}->{module_bit
}->{flag
},
214 'build generates values if they are not given'
218 my $nb_basket = $builder->schema->resultset('Aqbasket')->search();
219 isnt
( $nb_basket, 0, 'add stores the generated entries correctly' );
220 $builder->clear( { source
=> 'Aqbasket' } );
221 $nb_basket = $builder->schema->resultset('Aqbasket')->search();
222 is
( $nb_basket, 0, 'clear removes all the entries correctly' );
225 my $rs_aqbookseller = $builder->schema->resultset('Aqbookseller');
226 my $bookseller = $builder->build({
227 source
=> 'Aqbookseller',
230 delete $bookseller->{_fk
};
231 my $bookseller_from_db = $rs_aqbookseller->find($bookseller);
232 is
( $bookseller_from_db, undef, 'build with only_fk = 1 does not store the entry' );
233 my $bookseller_result = $rs_aqbookseller->create($bookseller);
234 is
( $bookseller_result->in_storage, 1, 'build with only_fk = 1 creates the foreign keys correctly' );
236 $bookseller = $builder->build({
237 source
=> 'Aqbookseller',
239 ok
( length( $bookseller->{phone
} ) <= 30, 'The length for a generated string should not be longer than the size of the DB field' );
240 delete $bookseller->{_fk
};
241 $bookseller_from_db = $rs_aqbookseller->find($bookseller);
242 is
( $bookseller_from_db->in_storage, 1, 'build without the parameter only_sk stores the entry correctly' );
244 $bookseller = $builder->build({
245 source
=> 'Aqbookseller',
248 delete $bookseller->{_fk
};
249 $bookseller_from_db = $rs_aqbookseller->find($bookseller);
250 is
( $bookseller_from_db->in_storage, 1, 'build with only_fk = 0 stores the entry correctly' );