Bug 28581: Add 'from_email_address' method and use in Koha::Patron
[koha-ffzg.git] / t / db_dependent / Koha / Libraries.t
index b66fa89..48a258d 100755 (executable)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 11;
+use Test::More tests => 12;
 
 use C4::Biblio;
 use C4::Context;
@@ -119,6 +119,36 @@ subtest '->get_effective_marcorgcode' => sub {
     $schema->storage->txn_rollback;
 };
 
+subtest '->from_email_address' => sub {
+
+    plan tests => 3;
+
+    $schema->storage->txn_begin;
+
+    my $library_1 = $builder->build_object(
+        {
+            class => 'Koha::Libraries',
+            value => {
+                branchemail   => 'from@mybranc.com',
+            }
+        }
+    );
+
+    t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'admin@mylibrary.com' );
+
+    is( $library_1->from_email_address, $library_1->branchemail,
+       'If defined, use branches branchemail address');
+
+    $library_1->branchemail(undef)->store();
+    is( $library_1->from_email_address, 'admin@mylibrary.com',
+       'Fallback to KohaAdminEmailAddress email address when branchemail is undefined');
+
+    t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', '' );
+    is( $library_1->from_email_address, undef,
+       'Return undef when branchemail and KohaAdminEmailAddress are both undefined');
+    $schema->storage->txn_rollback;
+};
+
 subtest '->inbound_email_address' => sub {
 
     plan tests => 5;