Bug 12001: Move GetMemberAccountBalance to Koha::Account->non_issues_charges
[srvgit] / t / db_dependent / Members.t
index f75652c..c7bc6b3 100755 (executable)
 
 use Modern::Perl;
 
-use Test::More tests => 63;
+use Test::More tests => 60;
 use Test::MockModule;
+use Test::Exception;
+
 use Data::Dumper qw/Dumper/;
 use C4::Context;
 use Koha::Database;
@@ -137,19 +139,6 @@ $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
 is ($checkcardnum, "2", "Card number is too long");
 
 
-
-t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
-C4::Context->clear_syspref_cache();
-
-my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
-is ($notice_email, $EMAIL, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is off");
-
-t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
-C4::Context->clear_syspref_cache();
-
-$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
-is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
-
 # Check_Userid tests
 %data = (
     cardnumber   => "123456789",
@@ -293,6 +282,10 @@ $builder->build({
         },
 });
 
+# The following calls to GetBorrowersToExpunge are assuming that the pref
+# IndependentBranches is off.
+t::lib::Mocks::mock_preference('IndependentBranches', 0);
+
 my $owner = AddMember (categorycode => 'STAFFER', branchcode => $library2->{branchcode} );
 my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } );
 my @listpatrons = ($bor1inlist, $bor2inlist);
@@ -380,72 +373,6 @@ ok( $borrower->{userid},  'A userid should have been generated correctly' );
 is( Check_Userid( C4::Context->config('user'), '' ), 0,
     'Check_Userid should return 0 for the DB user (Bug 12226)');
 
-subtest 'GetMemberAccountRecords' => sub {
-
-    plan tests => 2;
-
-    my $borrowernumber = $builder->build({ source => 'Borrower' })->{ borrowernumber };
-    my $accountline_1  = $builder->build({
-        source => 'Accountline',
-        value  => {
-            borrowernumber    => $borrowernumber,
-            amountoutstanding => 64.60
-        }
-    });
-
-    my ($total,undef,undef) = GetMemberAccountRecords( $borrowernumber );
-    is( $total , 64.60, "Rounding works correctly in total calculation (single value)" );
-
-    my $accountline_2 = $builder->build({
-        source => 'Accountline',
-        value  => {
-            borrowernumber    => $borrowernumber,
-            amountoutstanding => 10.65
-        }
-    });
-
-    ($total,undef,undef) = GetMemberAccountRecords( $borrowernumber );
-    is( $total , 75.25, "Rounding works correctly in total calculation (multiple values)" );
-
-};
-
-subtest 'GetMemberAccountBalance' => sub {
-
-    plan tests => 6;
-
-    my $members_mock = new Test::MockModule('C4::Members');
-    $members_mock->mock( 'GetMemberAccountRecords', sub {
-        my ($borrowernumber) = @_;
-        if ($borrowernumber) {
-            my @accountlines = (
-            { amountoutstanding => '7', accounttype => 'Rent' },
-            { amountoutstanding => '5', accounttype => 'Res' },
-            { amountoutstanding => '3', accounttype => 'Pay' } );
-            return ( 15, \@accountlines );
-        }
-        else {
-            my @accountlines;
-            return ( 0, \@accountlines );
-        }
-    });
-
-    # do not count holds charges
-    t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', '1' );
-    t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', '0' );
-    my ($total, $total_minus_charges,
-        $other_charges) = C4::Members::GetMemberAccountBalance(123);
-    is( $total, 15 , "Total calculated correctly");
-    is( $total_minus_charges, 15, "Holds charges are not count if HoldsInNoissuesCharge=1");
-    is( $other_charges, 0, "Holds charges are not considered if HoldsInNoissuesCharge=1");
-
-    t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', '0' );
-    ($total, $total_minus_charges,
-        $other_charges) = C4::Members::GetMemberAccountBalance(123);
-    is( $total, 15 , "Total calculated correctly");
-    is( $total_minus_charges, 10, "Holds charges are count if HoldsInNoissuesCharge=0");
-    is( $other_charges, 5, "Holds charges are considered if HoldsInNoissuesCharge=1");
-};
-
 subtest 'purgeSelfRegistration' => sub {
     plan tests => 2;
 
@@ -497,3 +424,25 @@ subtest 'Trivial test for AddMember_Auto' => sub {
 };
 
 $schema->storage->txn_rollback;
+
+subtest 'AddMember (invalid categorycode) tests' => sub {
+    plan tests => 1;
+
+    $schema->storage->txn_begin;
+
+    my $category    = $builder->build_object({ class => 'Koha::Patron::Categories' });
+    my $category_id = $category->id;
+    # Remove category to make sure the id is not on the DB
+    $category->delete;
+
+    my $patron_data = {
+        categorycode => $category_id
+    };
+
+    throws_ok
+        { AddMember( %{ $patron_data } ); }
+        'Koha::Exceptions::BadParameter',
+        'AddMember raises an exception on invalid categorycode';
+
+    $schema->storage->txn_rollback;
+};