Bugzilla – Attachment 70097 Details for
Bug 19828
Koha::Object->store should catch DBIC exceptions and raise Koha::Exceptions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19828: Unit tests
Bug-19828-Unit-tests.patch (text/plain), 3.47 KB, created by
Josef Moravec
on 2017-12-22 07:46:33 UTC
(
hide
)
Description:
Bug 19828: Unit tests
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2017-12-22 07:46:33 UTC
Size:
3.47 KB
patch
obsolete
>From 691799eb26751b7899f9d46fb87b7ebb5e67657f Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 18 Dec 2017 13:47:53 -0300 >Subject: [PATCH] Bug 19828: Unit tests > >This patch introduces unit tests for the changes this bug introduces to >Koha::Object->store. > >To test: >- Apply this patch >- Run: > $ kshell > k$ prove t/db_dependent/Koha/Object.t >=> FAIL: Tests should fail because the changes are not implemented on this patch > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > t/db_dependent/Koha/Object.t | 93 +++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 92 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index 5f91415..542b1e2 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -17,7 +17,8 @@ > > use Modern::Perl; > >-use Test::More tests => 9; >+use Test::More tests => 10; >+use Test::Exception; > use Test::Warn; > > use C4::Context; >@@ -218,3 +219,93 @@ subtest "Test update method" => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'store() tests' => sub { >+ >+ plan tests => 10; >+ >+ $schema->storage->txn_begin; >+ >+ # Create a category to make sure its ID doesn't exist on the DB >+ my $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); >+ my $category_id = $category->id; >+ $category->delete; >+ >+ my $patron = Koha::Patron->new({ categorycode => $category_id }); >+ >+ my $print_error = $schema->storage->dbh->{PrintError}; >+ $schema->storage->dbh->{PrintError} = 0; >+ throws_ok >+ { $patron->store } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'Exception is thrown correctly'; >+ is( >+ $@->message, >+ "Broken FK constraint", >+ 'Exception message is correct' >+ ); >+ is( >+ $@->broken_fk, >+ 'categorycode', >+ 'Exception field is correct' >+ ); >+ >+ my $library = $builder->build_object({ class => 'Koha::Libraries' }); >+ $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); >+ $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ my $new_patron = Koha::Patron->new({ >+ branchcode => $library->id, >+ cardnumber => $patron->cardnumber, >+ categorycode => $category->id >+ }); >+ >+ throws_ok >+ { $new_patron->store } >+ 'Koha::Exceptions::Object::DuplicateID', >+ 'Exception is thrown correctly'; >+ >+ is( >+ $@->message, >+ 'Duplicate ID', >+ 'Exception message is correct' >+ ); >+ >+ is( >+ $@->duplicate_id, >+ 'cardnumber', >+ 'Exception field is correct' >+ ); >+ >+ $new_patron = Koha::Patron->new({ >+ branchcode => $library->id, >+ userid => $patron->userid, >+ categorycode => $category->id >+ }); >+ >+ throws_ok >+ { $new_patron->store } >+ 'Koha::Exceptions::Object::DuplicateID', >+ 'Exception is thrown correctly'; >+ >+ is( >+ $@->message, >+ 'Duplicate ID', >+ 'Exception message is correct' >+ ); >+ >+ is( >+ $@->duplicate_id, >+ 'userid', >+ 'Exception field is correct' >+ ); >+ >+ $schema->storage->dbh->{PrintError} = $print_error; >+ >+ # Successful test >+ $patron->set({ firstname => 'Manuel' }); >+ my $ret = $patron->store; >+ is( ref($ret), 'Koha::Patron', 'store() returns the object on success' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 19828
:
69857
|
69858
|
69907
|
69908
|
69963
|
69964
|
69965
|
70048
|
70049
|
70050
| 70097 |
70098
|
70099
|
70100