diff --git a/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php b/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php index ef14b3d6c8a53f24f586a3289b8ee385061f167a..d1d2adc59f8b435966709f04b9bd7cc23f8482e2 100644 --- a/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php +++ b/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php @@ -307,6 +307,24 @@ abstract class MinkTestCase extends DbTestCase return false; } + /** + * Search for the specified query. + * + * @param string $query Search term(s) + * + * @return \Behat\Mink\Element\Element + */ + protected function performSearch($query) + { + $session = $this->getMinkSession(); + $session->visit($this->getVuFindUrl() . '/Search/Home'); + $page = $session->getPage(); + $this->findCss($page, '#searchForm_lookfor')->setValue($query); + $this->findCss($page, '.btn.btn-primary')->click(); + $this->snooze(); + return $page; + } + /** * Standard setup method. * diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CallnumberBrowseTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CallnumberBrowseTest.php index 36a8c0181898a9871c28b771cd64a00d1ee6d74c..8cf96006b98e1b192aabee225647c5d55cd358ec 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CallnumberBrowseTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CallnumberBrowseTest.php @@ -53,24 +53,6 @@ class CallnumberBrowseTest extends \VuFindTest\Unit\MinkTestCase } } - /** - * Search for the specified query. - * - * @param string $query Search term(s) - * - * @return \Behat\Mink\Element\Element - */ - protected function performSearch($query, $page = false) - { - $session = $this->getMinkSession(); - $session->visit($this->getVuFindUrl() . '/Search/Home'); - $page = $session->getPage(); - $this->findCss($page, '#searchForm_lookfor')->setValue($query); - $this->findCss($page, '.btn.btn-primary')->click(); - $this->snooze(); - return $page; - } - /** * Set config for callnumber tests * Sets callnumber_handler to false diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SavedSearchesTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SavedSearchesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a4056d8d5ef66cde67904d77e3b6ba7fab3eb9d9 --- /dev/null +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SavedSearchesTest.php @@ -0,0 +1,194 @@ +<?php +/** + * Mink saved searches test class. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2011. + * + * 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 Main Page + */ +namespace VuFindTest\Mink; + +/** + * Mink saved searches test class. + * + * @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 Main Page + */ +class SavedSearchesTest extends \VuFindTest\Unit\MinkTestCase +{ + use \VuFindTest\Unit\UserCreationTrait; + + /** + * Standard setup method. + * + * @return void + */ + public static function setUpBeforeClass() + { + return static::failIfUsersExist(); + } + + /** + * Standard setup method. + * + * @return void + */ + public function setUp() + { + // Give up if we're not running in CI: + if (!$this->continuousIntegrationRunning()) { + return $this->markTestSkipped('Continuous integration not running.'); + } + } + + /** + * Test saving and clearing a search. + * + * @return void + */ + public function testSaveSearch() + { + $page = $this->performSearch('test'); + $this->findCss($page, '.fa.fa-save')->click(); + $this->snooze(); + $this->findCss($page, '.createAccountLink')->click(); + $this->snooze(); + $this->fillInAccountForm($page); + $this->findCss($page, 'input.btn.btn-primary')->click(); + $this->snooze(); + $this->assertEquals( + 'Search saved successfully.', + $this->findCss($page, '.alert.alert-success')->getText() + ); + } + + /** + * Test search history. + * + * @return void + */ + public function testSearchHistory() + { + // Use "foo \ bar" as our search because the backslash has been known + // to cause problems in some situations (e.g. PostgreSQL database with + // incorrect escaping); this allows us to catch regressions for a few + // different problems in a single test. + $page = $this->performSearch('foo \ bar'); + $this->findAndAssertLink($page, 'Search History')->click(); + $this->snooze(); + // We should see our "foo \ bar" search in the history, but no saved + // searches because we are logged out: + $this->assertEquals( + 'foo \ bar', $this->findAndAssertLink($page, 'foo \ bar')->getText() + ); + $this->assertFalse( + $this->hasElementsMatchingText($page, 'h2', 'Saved Searches') + ); + $this->assertNull($page->findLink('test')); + + // Now log in and see if our saved search shows up (without making the + // unsaved search go away): + $this->findCss($page, '#loginOptions a')->click(); + $this->snooze(); + $this->fillInLoginForm($page, 'username1', 'test'); + $this->submitLoginForm($page); + $this->assertEquals( + 'foo \ bar', $this->findAndAssertLink($page, 'foo \ bar')->getText() + ); + $this->assertTrue( + $this->hasElementsMatchingText($page, 'h2', 'Saved Searches') + ); + $this->assertEquals( + 'test', $this->findAndAssertLink($page, 'test')->getText() + ); + + // Now purge unsaved searches, confirm that unsaved search is gone + // but saved search is still present: + $this->findAndAssertLink($page, 'Purge unsaved searches')->click(); + $this->snooze(); + $this->assertNull($page->findLink('foo \ bar')); + $this->assertEquals( + 'test', $this->findAndAssertLink($page, 'test')->getText() + ); + } + + /** + * Test that user A cannot delete user B's favorites. + * + * @return void + */ + public function testSavedSearchSecurity() + { + // Log in as user A and get the ID of their saved search: + $session = $this->getMinkSession(); + $session->visit($this->getVuFindUrl() . '/Search/History'); + $page = $session->getPage(); + $this->findCss($page, '#loginOptions a')->click(); + $this->snooze(); + $this->fillInLoginForm($page, 'username1', 'test'); + $this->submitLoginForm($page); + $delete = $this->findAndAssertLink($page, 'Delete')->getAttribute('href'); + $this->findAndAssertLink($page, 'Log Out')->click(); + $this->snooze(); + + // Use user A's delete link, but try to execute it as user B: + list($base, $params) = explode('?', $delete); + $session->visit($this->getVuFindUrl() . '/MyResearch/SaveSearch?' . $params); + $page = $session->getPage(); + $this->findCss($page, '.createAccountLink')->click(); + $this->snooze(); + $this->fillInAccountForm( + $page, ['username' => 'username2', 'email' => 'username2@example.com'] + ); + $this->findCss($page, 'input.btn.btn-primary')->click(); + $this->snooze(); + $this->findAndAssertLink($page, 'Log Out')->click(); + $this->snooze(); + + // Go back in as user A -- see if the saved search still exists. + $this->findAndAssertLink($page, 'Search History')->click(); + $this->snooze(); + $this->findCss($page, '#loginOptions a')->click(); + $this->snooze(); + $this->fillInLoginForm($page, 'username1', 'test'); + $this->submitLoginForm($page); + $this->assertTrue( + $this->hasElementsMatchingText($page, 'h2', 'Saved Searches') + ); + $this->assertEquals( + 'test', $this->findAndAssertLink($page, 'test')->getText() + ); + } + + /** + * Standard teardown method. + * + * @return void + */ + public static function tearDownAfterClass() + { + static::removeUsers(['username1', 'username2']); + } +} diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchActionsTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchFacetsTest.php similarity index 67% rename from module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchActionsTest.php rename to module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchFacetsTest.php index 0c5f38a3e06f6929ce3e85c8c4a51159ca66db8b..c6d5283f969e8e762797201316732c1631484e0f 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchActionsTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchFacetsTest.php @@ -1,6 +1,6 @@ <?php /** - * Mink search actions test class. + * Mink search facet/filter functionality test class. * * PHP version 7 * @@ -28,7 +28,7 @@ namespace VuFindTest\Mink; /** - * Mink search actions test class. + * Mink search facet/filter functionality test class. * * @category VuFind * @package Tests @@ -36,20 +36,8 @@ namespace VuFindTest\Mink; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org Main Page */ -class SearchActionsTest extends \VuFindTest\Unit\MinkTestCase +class SearchFacetsTest extends \VuFindTest\Unit\MinkTestCase { - use \VuFindTest\Unit\UserCreationTrait; - - /** - * Standard setup method. - * - * @return void - */ - public static function setUpBeforeClass() - { - return static::failIfUsersExist(); - } - /** * Standard setup method. * @@ -63,24 +51,6 @@ class SearchActionsTest extends \VuFindTest\Unit\MinkTestCase } } - /** - * Search for the specified query. - * - * @param string $query Search term(s) - * - * @return \Behat\Mink\Element\Element - */ - protected function performSearch($query) - { - $session = $this->getMinkSession(); - $session->visit($this->getVuFindUrl() . '/Search/Home'); - $page = $session->getPage(); - $this->findCss($page, '#searchForm_lookfor')->setValue($query); - $this->findCss($page, '.btn.btn-primary')->click(); - $this->snooze(); - return $page; - } - /** * Get filtered search * @@ -93,125 +63,6 @@ class SearchActionsTest extends \VuFindTest\Unit\MinkTestCase return $session->getPage(); } - /** - * Test saving and clearing a search. - * - * @return void - */ - public function testSaveSearch() - { - $page = $this->performSearch('test'); - $this->findCss($page, '.fa.fa-save')->click(); - $this->snooze(); - $this->findCss($page, '.createAccountLink')->click(); - $this->snooze(); - $this->fillInAccountForm($page); - $this->findCss($page, 'input.btn.btn-primary')->click(); - $this->snooze(); - $this->assertEquals( - 'Search saved successfully.', - $this->findCss($page, '.alert.alert-success')->getText() - ); - } - - /** - * Test search history. - * - * @return void - */ - public function testSearchHistory() - { - // Use "foo \ bar" as our search because the backslash has been known - // to cause problems in some situations (e.g. PostgreSQL database with - // incorrect escaping); this allows us to catch regressions for a few - // different problems in a single test. - $page = $this->performSearch('foo \ bar'); - $this->findAndAssertLink($page, 'Search History')->click(); - $this->snooze(); - // We should see our "foo \ bar" search in the history, but no saved - // searches because we are logged out: - $this->assertEquals( - 'foo \ bar', $this->findAndAssertLink($page, 'foo \ bar')->getText() - ); - $this->assertFalse( - $this->hasElementsMatchingText($page, 'h2', 'Saved Searches') - ); - $this->assertNull($page->findLink('test')); - - // Now log in and see if our saved search shows up (without making the - // unsaved search go away): - $this->findCss($page, '#loginOptions a')->click(); - $this->snooze(); - $this->fillInLoginForm($page, 'username1', 'test'); - $this->submitLoginForm($page); - $this->assertEquals( - 'foo \ bar', $this->findAndAssertLink($page, 'foo \ bar')->getText() - ); - $this->assertTrue( - $this->hasElementsMatchingText($page, 'h2', 'Saved Searches') - ); - $this->assertEquals( - 'test', $this->findAndAssertLink($page, 'test')->getText() - ); - - // Now purge unsaved searches, confirm that unsaved search is gone - // but saved search is still present: - $this->findAndAssertLink($page, 'Purge unsaved searches')->click(); - $this->snooze(); - $this->assertNull($page->findLink('foo \ bar')); - $this->assertEquals( - 'test', $this->findAndAssertLink($page, 'test')->getText() - ); - } - - /** - * Test that user A cannot delete user B's favorites. - * - * @return void - */ - public function testSavedSearchSecurity() - { - // Log in as user A and get the ID of their saved search: - $session = $this->getMinkSession(); - $session->visit($this->getVuFindUrl() . '/Search/History'); - $page = $session->getPage(); - $this->findCss($page, '#loginOptions a')->click(); - $this->snooze(); - $this->fillInLoginForm($page, 'username1', 'test'); - $this->submitLoginForm($page); - $delete = $this->findAndAssertLink($page, 'Delete')->getAttribute('href'); - $this->findAndAssertLink($page, 'Log Out')->click(); - $this->snooze(); - - // Use user A's delete link, but try to execute it as user B: - list($base, $params) = explode('?', $delete); - $session->visit($this->getVuFindUrl() . '/MyResearch/SaveSearch?' . $params); - $page = $session->getPage(); - $this->findCss($page, '.createAccountLink')->click(); - $this->snooze(); - $this->fillInAccountForm( - $page, ['username' => 'username2', 'email' => 'username2@example.com'] - ); - $this->findCss($page, 'input.btn.btn-primary')->click(); - $this->snooze(); - $this->findAndAssertLink($page, 'Log Out')->click(); - $this->snooze(); - - // Go back in as user A -- see if the saved search still exists. - $this->findAndAssertLink($page, 'Search History')->click(); - $this->snooze(); - $this->findCss($page, '#loginOptions a')->click(); - $this->snooze(); - $this->fillInLoginForm($page, 'username1', 'test'); - $this->submitLoginForm($page); - $this->assertTrue( - $this->hasElementsMatchingText($page, 'h2', 'Saved Searches') - ); - $this->assertEquals( - 'test', $this->findAndAssertLink($page, 'test')->getText() - ); - } - /** * Helper function for facets lists * @@ -477,14 +328,4 @@ class SearchActionsTest extends \VuFindTest\Unit\MinkTestCase $items = $page->findAll('css', '.active-filters'); $this->assertEquals(0, count($items)); } - - /** - * Standard teardown method. - * - * @return void - */ - public static function tearDownAfterClass() - { - static::removeUsers(['username1', 'username2']); - } }