@@ -, +, @@ --- t/db_dependent/Koha/Objects.t | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) --- a/t/db_dependent/Koha/Objects.t +++ a/t/db_dependent/Koha/Objects.t @@ -19,8 +19,9 @@ use Modern::Perl; -use Test::More tests => 21; +use Test::More tests => 22; use Test::Exception; +use Test::MockModule; use Test::Warn; use Koha::Authority::Types; @@ -799,3 +800,33 @@ subtest 'prefetch_whitelist() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'delete() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + # Make sure no cities + warnings_are { Koha::Cities->delete }[], + "No warnings, no Koha::City->delete called as it doesn't exist"; + + # Mock Koha::City + my $mocked_city = Test::MockModule->new('Koha::City'); + $mocked_city->mock( + 'delete', + sub { + warn "delete called!"; + } + ); + + # Add two cities + $builder->build_object( { class => 'Koha::Cities' } ); + $builder->build_object( { class => 'Koha::Cities' } ); + + warnings_are { Koha::Cities->delete } + [ "delete called!", "delete called!" ], + "No warnings, no Koha::City->delete called as it doesn't exist"; + + $schema->storage->txn_rollback; +}; --