Bug 9031: (QA follow-up) Pass the same timezone in Calendar.t
[koha.git] / t / db_dependent / Suggestions.t
index ddd7f00..6eb7575 100644 (file)
 
 use Modern::Perl;
 
+use t::lib::Mocks;
 use C4::Context;
 use C4::Members;
 use C4::Letters;
-use C4::Branch;
 use C4::Budgets qw( AddBudgetPeriod AddBudget );
 
 use Koha::DateUtils qw( dt_from_string );
+use Koha::Library;
 use Koha::Libraries;
 
+use t::lib::TestBuilder;
+
 use DateTime::Duration;
-use Test::More tests => 105;
+use Test::More tests => 102;
 use Test::Warn;
 
 BEGIN {
     use_ok('C4::Suggestions');
-    use_ok('C4::Koha');
 }
 
 my $dbh = C4::Context->dbh;
@@ -42,6 +44,7 @@ my $sql;
 $dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
+my $builder = t::lib::TestBuilder->new;
 # Reset item types to only the default ones
 $dbh->do(q|DELETE FROM itemtypes;|);
 $sql = "
@@ -64,27 +67,15 @@ $dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHE
 
 # Add CPL if missing.
 if (not defined Koha::Libraries->find('CPL')) {
-    ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'});
+    Koha::Library->new({ branchcode => 'CPL', branchname => 'Centerville' })->store;
 }
 
-my $sth = $dbh->prepare("SELECT * FROM categories WHERE categorycode='S';");
-$sth->execute();
-if (!$sth->fetchrow_hashref) {
-    $sql = "INSERT INTO categories
-                (categorycode,description,enrolmentperiod,upperagelimit,
-                 dateofbirthrequired,finetype,bulk,enrolmentfee,
-                 overduenoticerequired,issuelimit,reservefee,category_type)
-            VALUES
-                ('S','Staff',99,999,
-                 18,NULL,NULL,'0.000000',
-                 0,NULL,'0.000000','S');";
-    $dbh->do($sql);
-}
+my $patron_category = $builder->build({ source => 'Category' });
 
 my $member = {
     firstname => 'my firstname',
     surname => 'my surname',
-    categorycode => 'S',
+    categorycode => $patron_category->{categorycode},
     branchcode => 'CPL',
 };
 my $borrowernumber = AddMember(%$member);
@@ -302,6 +293,11 @@ $search_suggestion = SearchSuggestion({
     STATUS => $mod_suggestion3->{STATUS},
 });
 is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
+
+$search_suggestion = SearchSuggestion({
+    STATUS => q||
+});
+is( @$search_suggestion, 0, 'SearchSuggestion should not return all suggestions if we want the suggestions with a STATUS=""' );
 $search_suggestion = SearchSuggestion({
     STATUS => 'REJECTED',
 });
@@ -343,17 +339,6 @@ $suggestions = GetSuggestionByStatus('CHECKED');
 is( @$suggestions, 1, 'DelSuggestion deletes one suggestion' );
 is( $suggestions->[0]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' );
 
-## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values
-C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes|loc|ccode');
-my $itemtypes1 = C4::Koha::GetSupportList();
-is(@$itemtypes1, 8, "Purchase suggestion itemtypes collected, multiple AdvancedSearchTypes");
-
-C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes');
-my $itemtypes2 = C4::Koha::GetSupportList();
-is(@$itemtypes2, 8, "Purchase suggestion itemtypes collected, default AdvancedSearchTypes");
-
-is_deeply($itemtypes1, $itemtypes2, 'same set of purchase suggestion formats retrieved');
-
 # Test budgetid fk
 $my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB
 my $my_suggestionid_test_budgetid = NewSuggestion($my_suggestion);