Jonathan Druart
57f5332b63
Sometimes t/db_dependent/TestBuilder.t fails with 'TestBuilder can create a entry for every sources' but we don't know which ones have failed. Test plan: Create the following file: Koha/Schema/Result/Test.pm package Koha::Schema::Result::Test; use base 'DBIx::Class::Core'; __PACKAGE__->table("test"); 1; If you don't have a table named 'test' in your DB, prove t/db_dependent/TestBuilder.t should return a failure, but without any explanation. With this patch you should get a diag and know what's wrong. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
253 lines
8.7 KiB
Perl
253 lines
8.7 KiB
Perl
#!/usr/bin/perl
|
|
|
|
# This file is part of Koha.
|
|
#
|
|
# Copyright 2014 - Biblibre SARL
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
use Modern::Perl;
|
|
use Test::More tests => 41;
|
|
|
|
BEGIN {
|
|
use_ok('t::lib::TestBuilder');
|
|
}
|
|
|
|
|
|
my $builder = t::lib::TestBuilder->new();
|
|
|
|
is( $builder->build(), undef, 'build without arguments returns undef' );
|
|
|
|
my @sources = $builder->schema->sources;
|
|
my @source_in_failure;
|
|
for my $source (@sources) {
|
|
eval { $builder->build( { source => $source } ); };
|
|
push @source_in_failure, $source if $@;
|
|
}
|
|
is( @source_in_failure, 0, 'TestBuilder should be able to create an object for every sources' );
|
|
if ( @source_in_failure ) {
|
|
diag ("The following sources have not been generated correctly: " . join ', ', @source_in_failure)
|
|
}
|
|
|
|
my $my_overduerules_transport_type = {
|
|
message_transport_type => {
|
|
message_transport_type => 'my msg_t_t',
|
|
},
|
|
letternumber => 1,
|
|
branchcode => {
|
|
branchcode => 'codeB',
|
|
categorycode => 'codeC',
|
|
},
|
|
categorycode => undef,
|
|
};
|
|
$my_overduerules_transport_type->{categorycode} = $my_overduerules_transport_type->{branchcode};
|
|
my $overduerules_transport_type = $builder->build({
|
|
source => 'OverduerulesTransportType',
|
|
value => $my_overduerules_transport_type,
|
|
});
|
|
is(
|
|
$overduerules_transport_type->{message_transport_type},
|
|
$my_overduerules_transport_type->{message_transport_type}->{message_transport_type},
|
|
'build stores the message_transport_type correctly'
|
|
);
|
|
is(
|
|
$overduerules_transport_type->{letternumber},
|
|
$my_overduerules_transport_type->{letternumber},
|
|
'build stores the letternumber correctly'
|
|
);
|
|
is(
|
|
$overduerules_transport_type->{branchcode},
|
|
$my_overduerules_transport_type->{branchcode}->{branchcode},
|
|
'build stores the branchcode correctly'
|
|
);
|
|
is(
|
|
$overduerules_transport_type->{categorycode},
|
|
$my_overduerules_transport_type->{categorycode}->{categorycode},
|
|
'build stores the categorycode correctly'
|
|
);
|
|
is(
|
|
$overduerules_transport_type->{_fk}->{message_transport_type}->{message_transport_type},
|
|
$my_overduerules_transport_type->{message_transport_type}->{message_transport_type},
|
|
'build stores the foreign key message_transport_type correctly'
|
|
);
|
|
is(
|
|
$overduerules_transport_type->{_fk}->{branchcode}->{branchcode},
|
|
$my_overduerules_transport_type->{branchcode}->{branchcode},
|
|
'build stores the foreign key branchcode correctly'
|
|
);
|
|
is(
|
|
$overduerules_transport_type->{_fk}->{categorycode}->{categorycode},
|
|
$my_overduerules_transport_type->{categorycode}->{categorycode},
|
|
'build stores the foreign key categorycode correctly'
|
|
);
|
|
is_deeply(
|
|
$overduerules_transport_type->{_fk}->{branchcode},
|
|
$overduerules_transport_type->{_fk}->{categorycode},
|
|
'build links the branchcode and the categorycode correctly'
|
|
);
|
|
isnt(
|
|
$overduerules_transport_type->{_fk}->{branchcode}->{letter2},
|
|
undef,
|
|
'build generates values if they are not given'
|
|
);
|
|
|
|
my $my_user_permission = $t::lib::TestBuilder::default_value->{UserPermission};
|
|
my $user_permission = $builder->build({
|
|
source => 'UserPermission',
|
|
});
|
|
isnt(
|
|
$user_permission->{borrowernumber},
|
|
undef,
|
|
'build generates a borrowernumber correctly'
|
|
);
|
|
is(
|
|
$user_permission->{module_bit},
|
|
$my_user_permission->{module_bit}->{module_bit}->{bit},
|
|
'build stores the default value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{code},
|
|
$my_user_permission->{module_bit}->{code},
|
|
'build stores the default value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{borrowernumber},
|
|
$user_permission->{_fk}->{borrowernumber}->{borrowernumber},
|
|
'build links the foreign key correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{surname},
|
|
$my_user_permission->{borrowernumber}->{surname},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{address},
|
|
$my_user_permission->{borrowernumber}->{address},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{city},
|
|
$my_user_permission->{borrowernumber}->{city},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{_fk}->{branchcode}->{branchcode},
|
|
$my_user_permission->{borrowernumber}->{branchcode}->{branchcode},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{_fk}->{branchcode}->{branchname},
|
|
$my_user_permission->{borrowernumber}->{branchcode}->{branchname},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{_fk}->{categorycode}->{categorycode},
|
|
$my_user_permission->{borrowernumber}->{categorycode}->{categorycode},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{_fk}->{categorycode}->{hidelostitems},
|
|
$my_user_permission->{borrowernumber}->{categorycode}->{hidelostitems},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{_fk}->{categorycode}->{category_type},
|
|
$my_user_permission->{borrowernumber}->{categorycode}->{category_type},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{_fk}->{categorycode}->{defaultprivacy},
|
|
$my_user_permission->{borrowernumber}->{categorycode}->{defaultprivacy},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{borrowernumber}->{privacy},
|
|
$my_user_permission->{borrowernumber}->{privacy},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{module_bit}->{_fk}->{module_bit}->{bit},
|
|
$my_user_permission->{module_bit}->{module_bit}->{bit},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is(
|
|
$user_permission->{_fk}->{module_bit}->{code},
|
|
$my_user_permission->{module_bit}->{code},
|
|
'build stores the foreign key value correctly'
|
|
);
|
|
is_deeply(
|
|
$user_permission->{_fk}->{module_bit},
|
|
$user_permission->{_fk}->{code},
|
|
'build links the codes correctly'
|
|
);
|
|
isnt(
|
|
$user_permission->{_fk}->{borrowernumber}->{cardnumber},
|
|
undef,
|
|
'build generates values if they are not given'
|
|
);
|
|
isnt(
|
|
$user_permission->{_fk}->{borrowernumber}->{_fk}->{branchcode}->{branchaddress1},
|
|
undef,
|
|
'build generates values if they are not given'
|
|
);
|
|
isnt(
|
|
$user_permission->{_fk}->{borrowernumber}->{_fk}->{categorycode}->{description},
|
|
undef,
|
|
'build generates values if they are not given'
|
|
);
|
|
isnt(
|
|
$user_permission->{_fk}->{module_bit}->{description},
|
|
undef,
|
|
'build generates values if they are not given'
|
|
);
|
|
isnt(
|
|
$user_permission->{_fk}->{module_bit}->{_fk}->{module_bit}->{flag},
|
|
undef,
|
|
'build generates values if they are not given'
|
|
);
|
|
|
|
|
|
my $nb_basket = $builder->schema->resultset('Aqbasket')->search();
|
|
isnt( $nb_basket, 0, 'add stores the generated entries correctly' );
|
|
$builder->clear( { source => 'Aqbasket' } );
|
|
$nb_basket = $builder->schema->resultset('Aqbasket')->search();
|
|
is( $nb_basket, 0, 'clear removes all the entries correctly' );
|
|
|
|
|
|
my $rs_aqbookseller = $builder->schema->resultset('Aqbookseller');
|
|
my $bookseller = $builder->build({
|
|
source => 'Aqbookseller',
|
|
only_fk => 1,
|
|
});
|
|
delete $bookseller->{_fk};
|
|
my $bookseller_from_db = $rs_aqbookseller->find($bookseller);
|
|
is( $bookseller_from_db, undef, 'build with only_fk = 1 does not store the entry' );
|
|
my $bookseller_result = $rs_aqbookseller->create($bookseller);
|
|
is( $bookseller_result->in_storage, 1, 'build with only_fk = 1 creates the foreign keys correctly' );
|
|
|
|
$bookseller = $builder->build({
|
|
source => 'Aqbookseller',
|
|
});
|
|
ok( length( $bookseller->{phone} ) <= 30, 'The length for a generated string should not be longer than the size of the DB field' );
|
|
delete $bookseller->{_fk};
|
|
$bookseller_from_db = $rs_aqbookseller->find($bookseller);
|
|
is( $bookseller_from_db->in_storage, 1, 'build without the parameter only_sk stores the entry correctly' );
|
|
|
|
$bookseller = $builder->build({
|
|
source => 'Aqbookseller',
|
|
only_fk => 0,
|
|
});
|
|
delete $bookseller->{_fk};
|
|
$bookseller_from_db = $rs_aqbookseller->find($bookseller);
|
|
is( $bookseller_from_db->in_storage, 1, 'build with only_fk = 0 stores the entry correctly' );
|