Browse Source

Bug 15159: TestBuilder behaviour on AI values should be tested

This patch introduces a test for t::lib::TestBuilder to check it
doesn't mess with AI values. As it is generating random values based
on the defined column type, chances are that it is creating the
AI values on its own, instead of letting the DB handle it.

This could be problematic of course. This test uses the 'biblio' table
by creating two values and checking their biblionumbers are consecutive.

To test:
- Apply the patch
- Run:
  $ prove t/db_dependent/TestBuilder.t -v
=> SUCCESS: The new tests are run and:
   - biblio.biblionumber is detected as an auto-increment column
   - generated biblionumbers are consecutive
- Sign off

Regards

Signed-off-by: Hector Castro <hector.hecaxmmx@gmail.com>
All tests successful.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
3.22.x
Tomás Cohen Arazi 9 years ago
parent
commit
72d0dc6ed3
  1. 25
      t/db_dependent/TestBuilder.t

25
t/db_dependent/TestBuilder.t

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 41;
use Test::More tests => 42;
use Koha::Database;
@ -257,6 +257,29 @@ 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' );
subtest 'Auto-increment values tests' => sub {
plan tests => 2;
# Pick a table with AI PK
my $source = 'Biblio'; # table
my $column = 'biblionumber'; # ai column
my $col_info = $schema->source( $source )->column_info( $column );
is( $col_info->{is_auto_increment}, 1, "biblio.biblionumber is detected as autoincrement");
# Create a biblio
my $biblio_1 = $builder->build({ source => $source });
# Get the AI value
my $ai_value = $biblio_1->{ biblionumber };
# Create a biblio
my $biblio_2 = $builder->build({ source => $source });
# Get the next AI value
my $next_ai_value = $biblio_2->{ biblionumber };
is( $ai_value + 1, $next_ai_value, "AI values are consecutive");
};
$schema->storage->txn_rollback;
1;

Loading…
Cancel
Save