From 5bb74bd37e1480a123131674382d4d5f232ea5c4 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 29 Jan 2016 14:07:43 -0500 Subject: [PATCH] Began work on ILS tests. First step: place hold. --- .../src/VuFindTest/Mink/IlsActionsTest.php | 213 ++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 module/VuFind/tests/integration-tests/src/VuFindTest/Mink/IlsActionsTest.php diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/IlsActionsTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/IlsActionsTest.php new file mode 100644 index 00000000000..d87600b1c4b --- /dev/null +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/IlsActionsTest.php @@ -0,0 +1,213 @@ +<?php +/** + * Mink ILS actions test class. + * + * PHP version 5 + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://www.vufind.org Main Page + */ +namespace VuFindTest\Mink; +use Behat\Mink\Element\Element; + +/** + * Mink ILS actions test class. + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://www.vufind.org Main Page + */ +class IlsActionsTest extends \VuFindTest\Unit\MinkTestCase +{ + use \VuFindTest\Unit\UserCreationTrait; + + /** + * Standard setup method. + * + * @return void + */ + public static function setUpBeforeClass() + { + return static::failIfUsersExist(); + } + + /** + * Get config.ini override settings for testing ILS functions. + * + * @return array + */ + public function getConfigIniOverrides() + { + return [ + 'Catalog' => [ + 'driver' => 'Demo', + 'holds_mode' => 'driver', + 'title_level_holds_mode' => 'driver', + ] + ]; + } + + /** + * Get Demo.ini override settings for testing ILS functions. + * + * @param string $bibId Bibliographic record ID to create fake item info for. + * + * @return array + */ + public function getDemoIniOverrides($bibId = 'testsample1') + { + return [ + 'Failure_Probabilities' => [ + 'getHoldDefaultRequiredDate' => 0, + 'placeHold' => 0, + ], + 'Holdings' => [$bibId => json_encode([$this->getFakeItem()])], + 'Users' => ['catuser' => 'catpass'], + ]; + } + + /** + * Get a fake item record for inclusion in the Demo driver configuration. + * + * @return array + */ + public function getFakeItem() + { + return [ + 'barcode' => '12345678', + 'availability' => true, + 'status' => 'Available', + 'location' => 'Test Location', + 'locationhref' => false, + 'reserve' => 'N', + 'callnumber' => 'Test Call Number', + 'duedate' => '', + 'is_holdable' => true, + 'addLink' => true, + 'addStorageRetrievalRequestLink' => 'check', + 'addILLRequestLink' => 'check', + ]; + } + + /** + * Move the current page to a record by performing a search. + * + * @param string $id ID of record to access. + * + * @return \Behat\Mink\Element\Element + */ + protected function gotoRecordById($id = 'testsample1') + { + $session = $this->getMinkSession(); + $session->visit($this->getVuFindUrl() . '/Record/' . urlencode($id)); + return $session->getPage(); + } + + /** + * Fill in and submit the catalog login form with the provided credentials. + * + * @param Element $page Page element. + * @param string $username Username + * @param string $password Password + * + * @return void + */ + protected function submitCatalogLoginForm(Element $page, $username, $password) + { + $this->findCss($page, '#profile_cat_username')->setValue($username); + $this->findCss($page, '#profile_cat_password')->setValue($password); + $this->findCss($page, 'input.btn.btn-primary')->click(); + $this->snooze(); + } + + /** + * Test placing a hold. + * + * @return void + */ + public function testPlaceHold() + { + $this->changeConfigs( + [ + 'config' => $this->getConfigIniOverrides(), + 'Demo' => $this->getDemoIniOverrides(), + ] + ); + $page = $this->gotoRecordById(); + $element = $this->findCss($page, '.alert.alert-info a'); + $this->assertEquals('Login', $element->getText()); + $element->click(); + $this->snooze(); + $this->findCss($page, '.createAccountLink')->click(); + $this->fillInAccountForm($page); + $this->findCss($page, 'input.btn.btn-primary')->click(); + $this->snooze(); + + // Test invalid patron login + $this->submitCatalogLoginForm($page, 'bad', 'incorrect'); + $this->assertEquals( + 'Invalid Patron Login', + $this->findCss($page, '.alert.alert-danger')->getText() + ); + + // Test valid patron login + $this->submitCatalogLoginForm($page, 'catuser', 'catpass'); + + // Open the "place hold" dialog + $this->findCss($page, 'a.placehold')->click(); + $this->snooze(); + + // Set pickup location to a non-default value so we can confirm that + // the element is being passed through correctly, then submit form: + $this->findCss($page, '#pickUpLocation')->setValue('B'); + $this->findCss($page, '.modal-body .btn.btn-primary')->click(); + $this->snooze(); + + // If successful, we should now have a link to review the hold: + $link = $this->findCss($page, '.modal-body a'); + $this->assertEquals('Your Holds and Recalls', $link->getText()); + $link->click(); + $this->snooze(); + + // Verify the hold is correct: + $this->assertEquals( + 'Your Holds and Recalls', $this->findCss($page, 'h2')->getText() + ); + $this->assertEquals( + 'Journal of rational emotive therapy :' + . ' the journal of the Institute for Rational-Emotive Therapy.', + $this->findCss($page, 'a.title')->getText() + ); + $this->assertTrue(false !== strstr($page->getContent(), 'Campus B')); + } + + /** + * Standard teardown method. + * + * @return void + */ + public static function tearDownAfterClass() + { + static::removeUsers(['username1']); + } +} \ No newline at end of file -- GitLab