Bug 21087: Hash passwords in ->update_password
[koha-ffzg.git] / t / db_dependent / AdditionalField.t
index f7f5227..93121db 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 
 use Modern::Perl;
-use Test::More tests => 34;
+use Test::More tests => 40;
 
 use C4::Context;
 use Koha::AdditionalField;
@@ -104,22 +104,14 @@ use C4::Acquisition;
 use C4::Biblio;
 use C4::Budgets;
 use C4::Serials;
-
-my $booksellerid = C4::Bookseller::AddBookseller(
-    {
-        name => "my vendor",
-        address1 => "bookseller's address",
-        phone => "0123456",
-        active => 1
-    }
-);
+use C4::Serials::Frequency;
+use C4::Serials::Numberpattern;
 
 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
 my $budgetid;
 my $bpid = AddBudgetPeriod({
-    budget_period_startdate => '01-01-2015',
-    budget_period_enddate   => '12-31-2015',
-    budget_description      => "budget desc"
+    budget_period_startdate => '2015-01-01',
+    budget_period_enddate   => '2016-01-01',
 });
 
 my $budget_id = AddBudget({
@@ -127,27 +119,32 @@ my $budget_id = AddBudget({
     budget_amount      => "123.132",
     budget_name        => "Périodiques",
     budget_notes       => "This is a note",
-    budget_description => "Serials",
-    budget_active      => 1,
     budget_period_id   => $bpid
 });
 
+my $frequency_id = AddSubscriptionFrequency({ description => "Test frequency 1" });
+my $pattern_id = AddSubscriptionNumberpattern({
+    label => 'Test numberpattern 1',
+    description => 'Description for numberpattern 1',
+    numberingmethod => '{X}'
+});
+
 my $subscriptionid1 = NewSubscription(
-    undef,      "",     undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
-    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
-    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
-    undef,      undef,  undef, undef, undef,      undef,         undef,  1,
-    "notes",    undef,  undef, undef, undef,      undef,         undef,  0,
-    "intnotes", 0,      undef, undef, 0,          undef,         '31-12-2013',
+    undef,      "",     undef, undef, $budget_id, $biblionumber,
+    '2013-01-01', $frequency_id, undef, undef,  undef,
+    undef,      undef,  undef, undef, undef, undef,
+    1,          "notes",undef, '2013-01-01', undef, $pattern_id,
+    undef,       undef,  0,    "intnotes",  0,
+    undef, undef, 0,          undef,         '2013-01-01', 0
 );
 
 my $subscriptionid2 = NewSubscription(
-    undef,      "",     undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
-    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
-    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
-    undef,      undef,  undef, undef, undef,      undef,         undef,  1,
-    "notes",    undef,  undef, undef, undef,      undef,         undef,  0,
-    "intnotes", 0,      undef, undef, 0,          undef,         '31-12-2013',
+    undef,      "",     undef, undef, $budget_id, $biblionumber,
+    '2013-01-01', $frequency_id, undef, undef,  undef,
+    undef,      undef,  undef, undef, undef, undef,
+    1,          "notes",undef, '2013-01-01', undef, $pattern_id,
+    undef,       undef,  0,    "intnotes",  0,
+    undef, undef, 0,          undef,         '2013-01-01', 0
 );
 
 # insert
@@ -268,4 +265,31 @@ is ( $exists, 1, "get_matching_record_ids: field common: common_value matches su
 $exists = grep /not_existent_id/, @$matching_record_ids;
 is ( $exists, 0, "get_matching_record_ids: field common: common_value does not inexistent id" );
 
+$fields = [
+    {
+        name => 'common',
+        value => q|common|,
+    }
+];
+$matching_record_ids = Koha::AdditionalField->get_matching_record_ids({ tablename => 'subscription', fields => $fields, exact_match => 0 });
+$exists = grep /$subscriptionid1/, @$matching_record_ids;
+is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscription1" );
+$exists = grep /$subscriptionid2/, @$matching_record_ids;
+is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscription2 too" );
+$exists = grep /not_existent_id/, @$matching_record_ids;
+is ( $exists, 0, "get_matching_record_ids: field common: common% does not inexistent id" );
+
+# delete_values
+$af1 = Koha::AdditionalField->new({ id => $af1->id })->fetch;
+
+$af1->fetch_values;
+is_deeply ( $af1->values, {$subscriptionid1 => qq|value_for_af1_$subscriptionid1|, $subscriptionid2 => qq|value_for_af1_$subscriptionid2| }, "fetch_values: without argument, returns 2 records" );
+$af1->delete_values({record_id => $subscriptionid1});
+$af1->fetch_values;
+is_deeply ( $af1->values, {$subscriptionid2 => qq|value_for_af1_$subscriptionid2|}, "fetch_values: values for af2 and subscription2" );
+$af1->delete_values;
+$af1->fetch_values;
+is_deeply ( $af1->values, {}, "fetch_values: no values" );
+
+
 $dbh->rollback;