/** * Test citation generation * * @return void * @access public */ public function testISBNs() { // Valid ISBN-10: $isbn = new ISBN('0123456789'); $this->assertEquals($isbn->get10(), '0123456789'); $this->assertEquals($isbn->get13(), '9780123456786'); $this->assertTrue($isbn->isValid()); // Valid ISBN-13: $isbn = new ISBN('9780123456786'); $this->assertEquals($isbn->get10(), '0123456789'); $this->assertEquals($isbn->get13(), '9780123456786'); $this->assertTrue($isbn->isValid()); // Valid ISBN-10 with dashes: $isbn = new ISBN('0-12-345678-9'); $this->assertEquals($isbn->get10(), '0123456789'); $this->assertEquals($isbn->get13(), '9780123456786'); $this->assertTrue($isbn->isValid()); // Valid ISBN-13 with dashes: $isbn = new ISBN('978-0-12-345678-6'); $this->assertEquals($isbn->get10(), '0123456789'); $this->assertEquals($isbn->get13(), '9780123456786'); $this->assertTrue($isbn->isValid()); // Valid ISBN-13 outside of Bookland EAN: $isbn = new ISBN('9790123456785'); $this->assertEquals($isbn->get10(), false); $this->assertEquals($isbn->get13(), '9790123456785'); $this->assertTrue($isbn->isValid()); // Invalid ISBN-10: $isbn = new ISBN('2314346323'); $this->assertEquals($isbn->get10(), false); $this->assertEquals($isbn->get13(), false); $this->assertFalse($isbn->isValid()); }
function test3() { // NOTE: has bad checksum $this->assertEquals(ISBN::isValid('978-91-7429-121-1'), false); }
public function verifyInvalidChecksum() { $this->assertFalse(ISBN::isValid('0-8436-1072-3')); }
/** * Initialise the object from the global * search parameters in $_REQUEST. * * @access public * @var string|LibrarySearchSource|LocationSearchSource $searchSource * @return boolean */ public function init($searchSource = null) { // Call the standard initialization routine in the parent: parent::init($searchSource); $this->indexEngine->setSearchSource($searchSource); //******************** // Check if we have a saved search to restore -- if restored successfully, // our work here is done; if there is an error, we should report failure; // if restoreSavedSearch returns false, we should proceed as normal. $restored = $this->restoreSavedSearch(null, true, true); if ($restored === true) { return true; } else { if (PEAR_Singleton::isError($restored)) { return false; } } //******************** // Initialize standard search parameters $this->initView(); $this->initPage(); $this->initSort(); $this->initFilters(); $searchTerm = isset($_REQUEST['lookfor']) ? $_REQUEST['lookfor'] : null; global $module; global $action; if (isset($searchTerm) && !is_array($searchTerm)) { //Marmot - search both ISBN-10 and ISBN-13 //Check to see if the search term looks like an ISBN10 or ISBN13 $searchType = 'Keyword'; if (isset($_REQUEST['type'])) { $searchType = $_REQUEST['type']; } elseif (isset($_REQUEST['basicType'])) { $searchType = $_REQUEST['basicType']; } if (isset($searchTerm) && ($searchType == '' || $searchType == 'ISN' || $searchType == 'Keyword' || $searchType == 'AllFields') && (preg_match('/^\\d-?\\d{3}-?\\d{5}-?\\d$/', $searchTerm) || preg_match('/^\\d{3}-?\\d-?\\d{3}-?\\d{5}-?\\d$/', $searchTerm))) { require_once ROOT_DIR . '/sys/ISBN.php'; $isbn = new ISBN($searchTerm); if ($isbn->isValid()) { $isbn10 = $isbn->get10(); $isbn13 = $isbn->get13(); if ($isbn10 && $isbn13) { $searchTerm = $isbn->get10() . ' OR ' . $isbn->get13(); } } } } //******************** // Basic Search logic if ($this->initBasicSearch($searchTerm)) { // If we found a basic search, we don't need to do anything further. } else { if (isset($_REQUEST['tag']) && $module != 'MyAccount') { // Tags, just treat them as normal searches for now. // The search processer knows what to do with them. if ($_REQUEST['tag'] != '') { $this->searchTerms[] = array('index' => 'tag', 'lookfor' => strip_tags($_REQUEST['tag'])); } } else { $this->initAdvancedSearch(); } } //******************** // Author screens - handled slightly differently $author_ajax_call = isset($_REQUEST['author']) && $action == 'AJAX' && $module == 'Search'; if ($module == 'Author' || $author_ajax_call) { // Author module or ajax call from author results page // *** Things in common to both screens // Log a special type of search $this->searchType = 'author'; // We don't spellcheck this screen // it's not for free user input anyway $this->spellcheck = false; // *** Author/Home if ($action == 'Home' || $author_ajax_call) { $this->searchSubType = 'home'; // Remove our empty basic search (default) $this->searchTerms = array(); // Prepare the search as a normal author search $this->searchTerms[] = array('index' => 'Author', 'lookfor' => trim(strip_tags($_REQUEST['author']))); } // *** Author/Search if ($action == 'Search') { $this->searchSubType = 'search'; // We already have the 'lookfor', just set the index $this->searchTerms[0]['index'] = 'Author'; // We really want author facet data $this->facetConfig = array(); $this->addFacet('authorStr'); // Offset the facet list by the current page of results, and // allow up to ten total pages of results -- since we can't // get a total facet count, this at least allows the paging // mechanism to automatically add more pages to the end of the // list so that users can browse deeper and deeper as they go. // TODO: Make this better in the future if Solr offers a way // to get a total facet count (currently not possible). $this->facetOffset = ($this->page - 1) * $this->limit; $this->facetLimit = $this->limit * 10; // Sorting - defaults to off with unlimited facets, so let's // be explicit here for simplicity. if (isset($_REQUEST['sort']) && $_REQUEST['sort'] == 'author') { $this->setFacetSortOrder('index'); } else { $this->setFacetSortOrder('count'); } } } else { if ($module == 'Search' && ($action == 'NewItem' || $action == 'Reserves')) { // We don't need spell checking $this->spellcheck = false; $this->searchType = strtolower($action); } else { if ($module == 'MyAccount') { // Users Lists $this->spellcheck = false; $this->searchType = $action == 'Home' ? 'favorites' : 'list'; } } } // If a query override has been specified, log it here if (isset($_REQUEST['q'])) { $this->query = strip_tags($_REQUEST['q']); } return true; }
/** * Return the first valid ISBN found in the record (favoring ISBN-10 over * ISBN-13 when possible). * * @return mixed */ public function getCleanISBN() { require_once ROOT_DIR . '/sys/ISBN.php'; //Check to see if we already have NovelistData loaded with a primary ISBN require_once ROOT_DIR . '/sys/Novelist/NovelistData.php'; $novelistData = new NovelistData(); $novelistData->groupedRecordPermanentId = $this->getPermanentId(); if (!isset($_REQUEST['reload']) && $this->getPermanentId() != null && $this->getPermanentId() != '' && $novelistData->find(true) && $novelistData->primaryISBN != null) { return $novelistData->primaryISBN; } else { // Get all the ISBNs and initialize the return value: $isbns = $this->getISBNs(); $isbn10 = false; // Loop through the ISBNs: foreach ($isbns as $isbn) { // If we find an ISBN-13, return it immediately; otherwise, if we find // an ISBN-10, save it if it is the first one encountered. $isbnObj = new ISBN($isbn); if ($isbnObj->isValid()) { if ($isbn13 = $isbnObj->get13()) { return $isbn13; } if (!$isbn10) { $isbn10 = $isbnObj->get10(); } } } return $isbn10; } }