Bug 24151: Add tests - if config does not exist
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sat, 30 Nov 2019 11:48:04 +0000 (12:48 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 20 Jul 2020 13:17:42 +0000 (15:17 +0200)
Sponsored-by: Association KohaLa - https://koha-fr.org/
Signed-off-by: Signed-off-by: Sonia Bouis <sonia.bouis@univ-lyon3.fr>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Koha/Pseudonymization.t

index 99f6e2d..6c80312 100644 (file)
 
 use Modern::Perl;
 
-use Test::More tests => 1;
+use Test::More tests => 2;
+use Try::Tiny;
 
 use C4::Circulation;
+use C4::Stats;
 
 use Koha::Database;
 use Koha::DateUtils qw( dt_from_string );
@@ -34,7 +36,41 @@ use t::lib::Mocks;
 my $schema  = Koha::Database->new->schema;
 my $builder = t::lib::TestBuilder->new;
 
-subtest 'Koha::PseudonymizedTransactions tests' => sub {
+subtest 'Config does not exist' => sub {
+
+    plan tests => 2;
+
+    $schema->storage->txn_begin;
+
+    t::lib::Mocks::mock_config( 'key', '' );
+    t::lib::Mocks::mock_preference( 'Pseudonymization', 1 );
+    t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' );
+
+    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+    my $item    = $builder->build_sample_item;
+    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
+
+    try{
+        C4::Stats::UpdateStats(
+            {
+                type           => 'issue',
+                branch         => 'BBB',
+                itemnumber     => $item->itemnumber,
+                borrowernumber => $patron->borrowernumber,
+                itemtype       => $item->effective_itemtype,
+                location       => $item->location,
+            }
+        );
+
+    } catch {
+        ok($_->isa('Koha::Exceptions::Config::MissingEntry'), "Koha::Patron->store should raise a Koha::Exceptions::Config::MissingEntry if 'key' is not defined in the config");
+        is( $_->message, "Missing 'key' entry in config file");
+    };
+
+    $schema->storage->txn_rollback;
+};
+
+subtest 'Koha::Anonymized::Transactions tests' => sub {
 
     plan tests => 11;