From 1d3ce290a953d67c0b057901f74a18688e4967e8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 25 Jun 2018 13:14:05 -0300 Subject: [PATCH] Bug 20287: Test exception DuplicateID for Koha::Patron->store Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Object.t | 2 +- t/db_dependent/Koha/Patrons.t | 24 +++++++++++++++++++++++- t/db_dependent/Members.t | 3 +++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index b377e4b908..abb0d740ad 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -255,7 +255,7 @@ subtest 'store() tests' => sub { my $api_key = Koha::ApiKey->new({ patron_id => $patron_id }); my $print_error = $schema->storage->dbh->{PrintError}; - $schema->storage->dbh->{PrintError} = 0; # FIXME This does not longer work - because of the transaction in Koha::Patron->store? + $schema->storage->dbh->{PrintError} = 0; throws_ok { $api_key->store } 'Koha::Exceptions::Object::FKConstraint', diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index fa3c8dd43a..960b55c9c5 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,8 +19,9 @@ use Modern::Perl; -use Test::More tests => 31; +use Test::More tests => 32; use Test::Warn; +use Test::Exception; use Time::Fake; use DateTime; use JSON; @@ -1425,6 +1426,27 @@ subtest 'Test Koha::Patrons::merge' => sub { $schema->storage->txn_rollback; }; +subtest '->store' => sub { + plan tests => 1; + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + my $print_error = $schema->storage->dbh->{PrintError}; + $schema->storage->dbh->{PrintError} = 0; ; # FIXME This does not longer work - because of the transaction in Koha::Patron->store? + + my $patron_1 = $builder->build_object({class=> 'Koha::Patrons'}); + my $patron_2 = $builder->build_object({class=> 'Koha::Patrons'}); + + throws_ok + { $patron_2->userid($patron_1->userid)->store; } + 'Koha::Exceptions::Object::DuplicateID', + 'AddMember raises an exception on invalid categorycode'; + + $schema->storage->dbh->{PrintError} = $print_error; + $schema->storage->txn_rollback; +}; + + # TODO Move to t::lib::Mocks and reuse it! sub set_logged_in_user { my ($patron) = @_; diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index b9a2e3fccf..b878afbfed 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -176,6 +176,8 @@ is( $borrower->{dateenrolled}, '2015-09-06', 'Koha::Patron->store should correct subtest 'Koha::Patron->store should not update userid if not true' => sub { plan tests => 3; + # TODO Move this to t/db_dependent/Koha/Patrons.t subtest ->store + $data{ cardnumber } = "234567890"; $data{userid} = 'a_user_id'; $borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber; @@ -382,6 +384,7 @@ $schema->storage->txn_rollback; subtest 'Koha::Patron->store (invalid categorycode) tests' => sub { plan tests => 1; + # TODO Move this to t/db_dependent/Koha/Patrons.t subtest ->store $schema->storage->txn_begin; -- 2.11.0