* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development:testing:unit_tests Wiki */ namespace VuFind\Marc\Test; use VuFind\Marc\MarcCollection; /** * MarcCollection Test Class * * @category VuFind * @package Tests * @author Ere Maijala * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development:testing:unit_tests Wiki */ class MarcCollectionTest extends \PHPUnit\Framework\TestCase { use Feature\FixtureTrait; /** * Return collection fixtures for the tests * * @return array */ public static function collectionFixtures(): array { return [ ['marc/marc_collection.xml'], ['marc/marc_collection.mrc'], ['marc/marc_collection.json'], ]; } /** * Test MarcCollectionReader * * @param string $fixture Fixture to use * * @dataProvider collectionFixtures * * @return void */ public function testMarcCollection($fixture) { $marc = $this->getFixture($fixture); $collection = new MarcCollection($marc); $this->assertTrue($collection->valid()); $collection->rewind(); $this->assertTrue($collection->valid()); $this->assertEquals(0, $collection->key()); $record = $collection->current(); $title = $record->getField('245'); $this->assertEquals('The Foo', $record->getSubfield($title, 'a')); $collection->next(); $this->assertTrue($collection->valid()); $this->assertEquals(1, $collection->key()); $record = $collection->current(); $title = $record->getField('245'); $this->assertEquals('The Bar', $record->getSubfield($title, 'a')); $collection->next(); $this->assertFalse($collection->valid()); } /** * Test bad collection format * * @return void */ public function testBadCollectionFormat() { $this->expectExceptionMessage('MARC collection format not recognized'); new MarcCollection('foo'); } /** * Test empty MarcCollectionReader * * @return void */ public function testEmptyMarcCollection() { $collection = new MarcCollection(); $this->assertFalse($collection->valid()); } }