From fb2b2a3240f49ad6613882a9b3dae5795e8db707 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 15 Jan 2020 13:40:56 -0500 Subject: [PATCH] Add more tests. --- .../MetadataVocabulary/BEPressTest.php | 71 ++++++++++++++++++ .../MetadataVocabulary/DublinCoreTest.php | 70 ++++++++++++++++++ .../MetadataVocabulary/EprintsTest.php | 67 +++++++++++++++++ .../MetadataVocabulary/FakeDriverTrait.php | 69 ++++++++++++++++++ .../MetadataVocabulary/HighwirePressTest.php | 72 +++++++++++++++++++ .../MetadataVocabulary/PRISMTest.php | 66 +++++++++++++++++ 6 files changed, 415 insertions(+) create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/BEPressTest.php create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/DublinCoreTest.php create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/EprintsTest.php create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/FakeDriverTrait.php create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/HighwirePressTest.php create mode 100644 module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/PRISMTest.php diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/BEPressTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/BEPressTest.php new file mode 100644 index 00000000000..c6407f6474b --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/BEPressTest.php @@ -0,0 +1,71 @@ +<?php +/** + * BEPress Test Class + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * 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\MetadataVocabulary; + +use VuFind\MetadataVocabulary\BEPress; + +/** + * BEPress 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/wiki/development:testing:unit_tests Wiki + */ +class BEPressTest extends \VuFindTest\Unit\TestCase +{ + use FakeDriverTrait; + + /** + * Test basic functionality of the class. + * + * @return void + */ + public function testMappings() + { + $meta = new BEPress(); + $this->assertEquals( + [ + 'bepress_citation_title' => ['Fake Title'], + 'bepress_citation_doi' => ['FakeDOI'], + 'bepress_citation_lastpage' => [10], + 'bepress_citation_isbn' => ['FakeISBN'], + 'bepress_citation_issn' => ['FakeISSN'], + 'bepress_citation_firstpage' => [1], + 'bepress_citation_volume' => [7], + 'bepress_citation_author' => ['Mr. Person'], + 'bepress_citation_issue' => [5], + 'bepress_citation_journal_title' => ['My Journal'], + 'bepress_citation_publisher' => ['Fake Publisher'], + 'bepress_citation_date' => [2020], + ], + $meta->getMappedData($this->getDriver()) + ); + } +} diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/DublinCoreTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/DublinCoreTest.php new file mode 100644 index 00000000000..c53c958496f --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/DublinCoreTest.php @@ -0,0 +1,70 @@ +<?php +/** + * DublinCore Test Class + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * 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\MetadataVocabulary; + +use VuFind\MetadataVocabulary\DublinCore; + +/** + * DublinCore 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/wiki/development:testing:unit_tests Wiki + */ +class DublinCoreTest extends \VuFindTest\Unit\TestCase +{ + use FakeDriverTrait; + + /** + * Test basic functionality of the class. + * + * @return void + */ + public function testMappings() + { + $meta = new DublinCore(); + $this->assertEquals( + [ + 'DC.title' => ['Fake Title'], + 'DC.language' => ['English'], + 'DC.citation.epage' => [10], + 'DC.identifier' => ['FakeDOI', 'FakeISBN', 'FakeISSN'], + 'DC.citation.spage' => [1], + 'DC.citation.volume' => [7], + 'DC.creator' => ['Mr. Person'], + 'DC.citation.issue' => [5], + 'DC.relation.ispartof' => ['My Journal'], + 'DC.publisher' => ['Fake Publisher'], + 'DC.issued' => [2020], + ], + $meta->getMappedData($this->getDriver()) + ); + } +} diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/EprintsTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/EprintsTest.php new file mode 100644 index 00000000000..eefb15ac84d --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/EprintsTest.php @@ -0,0 +1,67 @@ +<?php +/** + * Eprints Test Class + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * 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\MetadataVocabulary; + +use VuFind\MetadataVocabulary\Eprints; + +/** + * Eprints 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/wiki/development:testing:unit_tests Wiki + */ +class EprintsTest extends \VuFindTest\Unit\TestCase +{ + use FakeDriverTrait; + + /** + * Test basic functionality of the class. + * + * @return void + */ + public function testMappings() + { + $meta = new Eprints(); + $this->assertEquals( + [ + 'eprints.title' => ['Fake Title'], + 'eprints.issn' => ['FakeISSN'], + 'eprints.pagerange' => ['1-10'], + 'eprints.number' => [7], + 'eprints.creators_name' => ['Mr. Person'], + 'eprints.publication' => ['My Journal'], + 'eprints.publisher' => ['Fake Publisher'], + 'eprints.date' => [2020], + ], + $meta->getMappedData($this->getDriver()) + ); + } +} diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/FakeDriverTrait.php b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/FakeDriverTrait.php new file mode 100644 index 00000000000..aa98ee0825e --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/FakeDriverTrait.php @@ -0,0 +1,69 @@ +<?php +/** + * Trait containing method to generate fake drivers for metadata testing. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * 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\MetadataVocabulary; + +use VuFindTest\RecordDriver\TestHarness; + +/** + * Trait containing method to generate fake drivers for metadata testing. + * + * @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 + */ +trait FakeDriverTrait +{ + /** + * Get a fake record driver + * + * @return TestHarness + */ + protected function getDriver() + { + $data = [ + 'Title' => 'Fake Title', + 'PrimaryAuthors' => ['Mr. Person'], + 'ContainerTitle' => 'My Journal', + 'PublicationDates' => [2020], + 'CleanDOI' => 'FakeDOI', + 'ContainerEndPage' => 10, + 'CleanISBN' => 'FakeISBN', + 'CleanISSN' => 'FakeISSN', + 'ContainerIssue' => 5, + 'Languages' => ['English'], + 'Publishers' => ['Fake Publisher'], + 'ContainerStartPage' => 1, + 'ContainerVolume' => 7, + ]; + $driver = new TestHarness(); + $driver->setRawData($data); + return $driver; + } +} diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/HighwirePressTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/HighwirePressTest.php new file mode 100644 index 00000000000..d1654865994 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/HighwirePressTest.php @@ -0,0 +1,72 @@ +<?php +/** + * HighwirePress Test Class + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * 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\MetadataVocabulary; + +use VuFind\MetadataVocabulary\HighwirePress; + +/** + * HighwirePress 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/wiki/development:testing:unit_tests Wiki + */ +class HighwirePressTest extends \VuFindTest\Unit\TestCase +{ + use FakeDriverTrait; + + /** + * Test basic functionality of the class. + * + * @return void + */ + public function testMappings() + { + $meta = new HighwirePress(); + $this->assertEquals( + [ + 'citation_title' => ['Fake Title'], + 'citation_doi' => ['FakeDOI'], + 'citation_lastpage' => [10], + 'citation_isbn' => ['FakeISBN'], + 'citation_issn' => ['FakeISSN'], + 'citation_firstpage' => [1], + 'citation_volume' => [7], + 'citation_author' => ['Mr. Person'], + 'citation_issue' => [5], + 'citation_journal_title' => ['My Journal'], + 'citation_publisher' => ['Fake Publisher'], + 'citation_date' => [2020], + 'citation_language' => ['English'], + ], + $meta->getMappedData($this->getDriver()) + ); + } +} diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/PRISMTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/PRISMTest.php new file mode 100644 index 00000000000..4c9b1165bd1 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/MetadataVocabulary/PRISMTest.php @@ -0,0 +1,66 @@ +<?php +/** + * PRISM Test Class + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * 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\MetadataVocabulary; + +use VuFind\MetadataVocabulary\PRISM; + +/** + * PRISM 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/wiki/development:testing:unit_tests Wiki + */ +class PRISMTest extends \VuFindTest\Unit\TestCase +{ + use FakeDriverTrait; + + /** + * Test basic functionality of the class. + * + * @return void + */ + public function testMappings() + { + $meta = new PRISM(); + $this->assertEquals( + [ + 'prism.title' => ['Fake Title'], + 'prism.doi' => ['FakeDOI'], + 'prism.endingPage' => [10], + 'prism.isbn' => ['FakeISBN'], + 'prism.issn' => ['FakeISSN'], + 'prism.startingPage' => [1], + 'prism.volume' => [7], + ], + $meta->getMappedData($this->getDriver()) + ); + } +} -- GitLab