From 3c012186514b46ece8f6bf9b6740ab9c7c7a6e93 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 11 Dec 2019 16:49:49 -0500
Subject: [PATCH] Fix bug: missing parentheses. - Includes added test coverage.

---
 module/VuFind/src/VuFind/Search/History.php   |   2 +-
 .../src/VuFindTest/Search/HistoryTest.php     | 119 ++++++++++++++++++
 2 files changed, 120 insertions(+), 1 deletion(-)
 create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/Search/HistoryTest.php

diff --git a/module/VuFind/src/VuFind/Search/History.php b/module/VuFind/src/VuFind/Search/History.php
index 93a5ee0c9ae..8115263e6b2 100644
--- a/module/VuFind/src/VuFind/Search/History.php
+++ b/module/VuFind/src/VuFind/Search/History.php
@@ -133,7 +133,7 @@ class History
      */
     public function getScheduleOptions()
     {
-        if (!$this->config->Account->schedule_searches ?? false) {
+        if (!($this->config->Account->schedule_searches ?? false)) {
             return [];
         }
         return $this->config->Account->scheduled_search_frequencies
diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Search/HistoryTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/HistoryTest.php
new file mode 100644
index 00000000000..f03094c8b8e
--- /dev/null
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/HistoryTest.php
@@ -0,0 +1,119 @@
+<?php
+
+/**
+ * History unit tests.
+ *
+ * PHP version 7
+ *
+ * Copyright (C) Villanova University 2019.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * @category VuFind
+ * @package  Tests
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development:testing:unit_tests Wiki
+ */
+namespace VuFindTest\Search;
+
+use VuFind\Search\History;
+use VuFindTest\Unit\TestCase as TestCase;
+
+/**
+ * History unit tests.
+ *
+ * @category VuFind
+ * @package  Tests
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development:testing:unit_tests Wiki
+ */
+class HistoryTest extends TestCase
+{
+    /**
+     * Test that we get no schedule options when scheduled search is disabled
+     * (by default).
+     *
+     * @return void
+     */
+    public function testDefaultDisabledScheduleOptions()
+    {
+        $this->assertEquals([], $this->getHistory()->getScheduleOptions());
+    }
+
+    /**
+     * Test that we get no schedule options when scheduled search is disabled
+     * (explicitly).
+     *
+     * @return void
+     */
+    public function testExplicitlyDisabledScheduleOptions()
+    {
+        $config = new \Zend\Config\Config(
+            [
+                'Account' => [
+                    'schedule_searches' => false,
+                ]
+            ]
+        );
+        $history = $this->getHistory(null, null, $config);
+        $this->assertEquals([], $history->getScheduleOptions());
+    }
+
+    /**
+     * Test that we get reasonable default schedule options when scheduled search
+     * is enabled.
+     *
+     * @return void
+     */
+    public function testDefaultScheduleOptions()
+    {
+        $config = new \Zend\Config\Config(
+            [
+                'Account' => [
+                    'schedule_searches' => true,
+                ]
+            ]
+        );
+        $history = $this->getHistory(null, null, $config);
+        $this->assertEquals(
+            [0 => 'schedule_none', 1 => 'schedule_daily', 7 => 'schedule_weekly'],
+            $history->getScheduleOptions()
+        );
+    }
+
+    /**
+     * Get object for testing.
+     *
+     * @param \VuFind\Db\Table\Search              $searchTable    Search table
+     * @param \VuFind\Search\Results\PluginManager $resultsManager Results manager
+     * @param \Zend\Config\Config                  $config         Configuration
+     *
+     * @return History
+     */
+    protected function getHistory($searchTable = null,
+        $resultsManager = null, \Zend\Config\Config $config = null
+    ) {
+        return new History(
+            $searchTable ?: $this->getMockBuilder(\VuFind\Db\Table\Search::class)
+                ->disableOriginalConstructor()->getMock(),
+            'foosession',
+            $resultsManager ?: $this
+                ->getMockBuilder(\VuFind\Search\Results\PluginManager::class)
+                ->disableOriginalConstructor()->getMock(),
+            $config
+        );
+    }
+}
-- 
GitLab