Bug 22052: Unit tests
authorNick Clemens <nick@bywatersolutions.com>
Fri, 28 Dec 2018 18:48:15 +0000 (18:48 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Tue, 8 Jan 2019 14:02:42 +0000 (14:02 +0000)
Signed-off-by: Charles Farmer <charles.farmer@inLibro.com>
Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
t/db_dependent/Members.t

index 3d6a041..f9595be 100755 (executable)
@@ -337,7 +337,7 @@ $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
 ok( $borrower->{userid},  'A userid should have been generated correctly' );
 
 subtest 'purgeSelfRegistration' => sub {
-    plan tests => 2;
+    plan tests => 5;
 
     #purge unverified
     my $d=360;
@@ -353,8 +353,37 @@ subtest 'purgeSelfRegistration' => sub {
     t::lib::Mocks::mock_preference('PatronSelfRegistrationDefaultCategory', $c );
     t::lib::Mocks::mock_preference('PatronSelfRegistrationExpireTemporaryAccountsDelay', 360);
     C4::Members::DeleteExpiredOpacRegistrations();
-    $dbh->do("INSERT INTO borrowers (surname, address, city, branchcode, categorycode, dateenrolled) VALUES ('Testaabbcc', 'Street 1', 'CITY', ?, '$c', '2014-01-01 01:02:03')", undef, $library1->{branchcode});
-    is( C4::Members::DeleteExpiredOpacRegistrations(), 1, 'Test for DeleteExpiredOpacRegistrations');
+    my $self_reg = $builder->build_object({
+        class => 'Koha::Patrons',
+        value => {
+            dateenrolled => '2014-01-01 01:02:03',
+            categorycode => $c
+        }
+    });
+
+    my $checkout     = $builder->build_object({
+        class=>'Koha::Checkouts',
+        value=>{
+            borrowernumber=>$self_reg->borrowernumber
+        }
+    });
+    is( C4::Members::DeleteExpiredOpacRegistrations(), 0, "DeleteExpiredOpacRegistrations doesn't delete borrower with checkout");
+
+    my $account_line = $builder->build_object({
+        class=>'Koha::Account::Lines',
+        value=>{
+            borrowernumber=>$self_reg->borrowernumber,
+            amountoutstanding=>5
+        }
+    });
+    is( C4::Members::DeleteExpiredOpacRegistrations(), 0, "DeleteExpiredOpacRegistrations doesn't delete borrower with checkout and fine");
+
+    $checkout->delete;
+    is( C4::Members::DeleteExpiredOpacRegistrations(), 0, "DeleteExpiredOpacRegistrations doesn't delete borrower with fine and no checkout");
+
+    $account_line->delete;
+    is( C4::Members::DeleteExpiredOpacRegistrations(), 1, "DeleteExpiredOpacRegistrations does delete borrower with no fines and no checkouts");
+
 };
 
 sub _find_member {