use Modern::Perl;
-use Test::More tests => 13;
+use utf8;
+
+use Test::More tests => 15;
use Test::Warn;
use File::Basename qw(dirname);
}
our $schema = Koha::Database->new->schema;
-$schema->storage->txn_begin;
our $builder;
subtest 'Start with some trivial tests' => sub {
plan tests => 7;
+ $schema->storage->txn_begin;
+
$builder = t::lib::TestBuilder->new;
isnt( $builder, undef, 'We got a builder' );
warning_like { $builder->build( $param ) }
qr/Violation of unique constraint/,
'Catch warn on adding existing record';
+
+ $schema->storage->txn_rollback;
};
subtest 'Build all sources' => sub {
plan tests => 1;
+ $schema->storage->txn_begin;
+
my @sources = $builder->schema->sources;
my @source_in_failure;
for my $source ( @sources ) {
diag( "The following sources have not been generated correctly: " .
join ', ', @source_in_failure );
}
+
+ $schema->storage->txn_rollback;
};
subtest 'Test length of some generated fields' => sub {
plan tests => 3;
+ $schema->storage->txn_begin;
+
# Test the length of a returned character field
my $bookseller = $builder->build({ source => 'Aqbookseller' });
my $max = $schema->source('Aqbookseller')->column_info('phone')->{size};
my $item = $builder->build({ source => 'Item' });
is( $item->{replacementprice}, sprintf("%.2f", $item->{replacementprice}), "The number of decimals for floats should not be more than 2" );
+
+ $schema->storage->txn_rollback;
};
subtest 'Test FKs in overduerules_transport_type' => sub {
plan tests => 5;
+ $schema->storage->txn_begin;
+
my $my_overduerules_transport_type = {
message_transport_type => {
message_transport_type => 'my msg_t_t',
undef,
'build generates values if they are not given'
);
+
+ $schema->storage->txn_rollback;
};
subtest 'Tests with composite FK in userpermission' => sub {
plan tests => 9;
+ $schema->storage->txn_begin;
+
my $my_user_permission = default_userpermission();
my $user_permission = $builder->build({
source => 'UserPermission',
$my_user_permission->{code}->{description},
'build stored description correctly'
);
+
+ $schema->storage->txn_rollback;
};
sub default_userpermission {
subtest 'Test build with NULL values' => sub {
plan tests => 3;
+ $schema->storage->txn_begin;
+
# PK should not be null
my $params = { source => 'Branch', value => { branchcode => undef }};
warning_like { $builder->build( $params ) }
$info = $schema->source( 'Reserve' )->column_info( 'itemnumber' );
is( $reserve && $info->{is_nullable} && $info->{is_foreign_key} &&
!defined( $reserve->{itemnumber} ), 1, 'Nullable FK' );
+
+ $schema->storage->txn_rollback;
};
subtest 'Tests for delete method' => sub {
plan tests => 12;
+ $schema->storage->txn_begin;
+
# Test delete with single and multiple records
my $basket1 = $builder->build({ source => 'Aqbasket' });
my $basket2 = $builder->build({ source => 'Aqbasket' });
# Test delete in table without primary key (..)
is( $schema->source('TmpHoldsqueue')->primary_columns, 0,
'Table without primary key detected' );
- my $bibno = 123; # just a number
+ my $bibno = $builder->build_sample_biblio->biblionumber;
my $cnt1 = $schema->resultset('TmpHoldsqueue')->count;
# Insert a new record in TmpHoldsqueue with that biblionumber
my $val = { biblionumber => $bibno };
code => undef };
is( $builder->delete({ source => 'Permission', records => $val }), 0,
'delete returns zero for an undef search with a composite PK' );
-};
+ $schema->storage->txn_rollback;
+};
subtest 'Auto-increment values tests' => sub {
plan tests => 3;
+ $schema->storage->txn_begin;
+
# Pick a table with AI PK
my $source = 'Biblio'; # table
my $column = 'biblionumber'; # ai column
value => { biblionumber => 123 },
}) } qr/^Value not allowed for auto_incr/,
'Build should not overwrite an auto_incr column';
+
+ $schema->storage->txn_rollback;
};
subtest 'Date handling' => sub {
plan tests => 2;
+ $schema->storage->txn_begin;
+
$builder = t::lib::TestBuilder->new;
my $patron = $builder->build( { source => 'Borrower' } );
is( length( $patron->{updated_on} ), 19, 'A timestamp column value should be YYYY-MM-DD HH:MM:SS' );
is( length( $patron->{dateofbirth} ), 10, 'A date column value should be YYYY-MM-DD' );
+
+ $schema->storage->txn_rollback;
};
subtest 'Default values' => sub {
plan tests => 3;
+ $schema->storage->txn_begin;
+
$builder = t::lib::TestBuilder->new;
my $item = $builder->build( { source => 'Item' } );
is( $item->{more_subfields_xml}, undef, 'This xml field should be undef' );
$patron = $builder->build_object({ class => 'Koha::Patrons', value => {categorycode => $patron_category_X->categorycode} });
is( $patron->category->category_type, 'X', );
};
+
+ $schema->storage->txn_rollback;
};
subtest 'build_object() tests' => sub {
plan tests => 5;
+ $schema->storage->txn_begin;
+
$builder = t::lib::TestBuilder->new();
+ my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
my $issuing_rule = $builder->build_object(
- { class => 'Koha::IssuingRules',
+ { class => 'Koha::CirculationRules',
value => {
+ branchcode => $branchcode,
categorycode => $categorycode,
itemtype => $itemtype
}
}
);
- is( ref($issuing_rule), 'Koha::IssuingRule', 'Type is correct' );
+ is( ref($issuing_rule), 'Koha::CirculationRule', 'Type is correct' );
is( $issuing_rule->categorycode,
$categorycode, 'Category code correctly set' );
is( $issuing_rule->itemtype, $itemtype, 'Item type correctly set' );
{ class => 'Koha::Patrons', categorycode => 'foobar' } );
} qr{Unknown parameter\(s\): categorycode}, "Unknown parameter detected";
};
+
+ $schema->storage->txn_rollback;
};
subtest '->build parameter' => sub {
plan tests => 4;
+ $schema->storage->txn_begin;
+
# Test to make sure build() warns user of unknown parameters.
warnings_are {
$builder->build({
$builder->build(
{ source => 'Borrower', categorycode => 'foobar' } );
} qr{Unknown parameter\(s\): categorycode}, "Unkown parameter detected";
+
+ $schema->storage->txn_rollback;
+};
+
+subtest 'build_sample_biblio() tests' => sub {
+
+ plan tests => 1;
+
+ $schema->storage->txn_begin;
+
+ warnings_are
+ { $builder->build_sample_biblio({ title => 'hell❤️' }); }
+ [],
+ "No encoding warnings!";
+
+ $schema->storage->txn_rollback;
};
-$schema->storage->txn_rollback;
+subtest 'Existence of object is only checked using primary keys' => sub {
+
+ plan tests => 1;
+
+ $schema->storage->txn_begin;
+
+ my $biblio = $builder->build_sample_biblio();
+ my $item1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
+ my $item2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
+ warnings_are {
+ $builder->build_object({
+ class => 'Koha::Holds',
+ value => {
+ biblionumber => $biblio->biblionumber
+ }
+ });
+ } [], "No warning about query returning more than one row";
+
+ $schema->storage->txn_rollback;
+};