22
33namespace Tests ;
44
5+ use Scriptotek \Marc \BibliographicRecord ;
56use Scriptotek \Marc \Collection ;
67use Scriptotek \Marc \Exceptions \XmlException ;
78
89class CollectionTest extends TestCase
910{
11+ /**
12+ * Test that an empty Collection is created if no MARC records were found in the input.
13+ */
1014 public function testEmptyCollection ()
1115 {
1216 $ source = '<?xml version="1.0" encoding="UTF-8" ?><test></test> ' ;
@@ -15,21 +19,6 @@ public function testEmptyCollection()
1519 $ this ->assertCount (0 , $ collection ->toArray ());
1620 }
1721
18- public function testBinaryMarc ()
19- {
20- $ records = $ this ->getTestCollection ('sandburg.mrc ' )->toArray ();
21-
22- $ this ->assertCount (1 , $ records );
23- $ this ->assertEquals ('Arithmetic ' , $ records [0 ]->title );
24- }
25-
26- public function testBibsysOaiPmhSample ()
27- {
28- $ collection = $ this ->getTestCollection ('oaipmh-bibsys.xml ' );
29-
30- $ this ->assertCount (89 , $ collection ->toArray ());
31- }
32-
3322 /**
3423 * Test that it XmlException is thrown when the specified encoding (UTF-16)
3524 * differs from the actual encoding (UTF-8).
@@ -40,38 +29,50 @@ public function testExceptionOnInvalidEncoding()
4029 $ this ->getTestCollection ('alma-bibs-api-invalid.xml ' );
4130 }
4231
43- public function testLocSample ()
44- {
45- $ collection = $ this ->getTestCollection ('sru-loc.xml ' );
46-
47- $ this ->assertCount (10 , $ collection ->toArray ());
48- }
49-
50- public function testBibsysSample ()
32+ /**
33+ * Define a list of sample binary MARC files that we can test with,
34+ * and the expected number of records in each.
35+ *
36+ * @return array
37+ */
38+ public function mrcFiles ()
5139 {
52- $ collection = $ this -> getTestCollection ( ' sru-bibsys.xml ' );
53-
54- $ this -> assertCount ( 117 , $ collection -> toArray ()) ;
40+ return [
41+ [ ' sandburg.mrc ' , 1 ], // Single binary MARC file
42+ ] ;
5543 }
5644
57- public function testZdbSample ()
58- {
59- $ collection = $ this ->getTestCollection ('sru-zdb.xml ' );
60-
61- $ this ->assertCount (8 , $ collection ->toArray ());
62- }
63-
64- public function testKthSample ()
45+ /**
46+ * Define a list of sample XML files from different sources that we can test with,
47+ * and the expected number of records in each.
48+ *
49+ * @return array
50+ */
51+ public function xmlFiles ()
6552 {
66- $ collection = $ this ->getTestCollection ('sru-kth.xml ' );
67-
68- $ this ->assertCount (10 , $ collection ->toArray ());
53+ return [
54+ ['oaipmh-bibsys.xml ' , 89 ], // Records encapsulated in OAI-PMH response
55+ ['sru-loc.xml ' , 10 ], // Records encapsulated in SRU response
56+ ['sru-bibsys.xml ' , 117 ], // (Another one)
57+ ['sru-zdb.xml ' , 8 ], // (Another one)
58+ ['sru-kth.xml ' , 10 ], // (Another one)
59+ ['sru-alma.xml ' , 3 ], // (Another one)
60+ ];
6961 }
7062
71- public function testAlmaSample ()
63+ /**
64+ * Test that the sample files can be loaded using Collection::fromFile
65+ *
66+ * @dataProvider mrcFiles
67+ * @dataProvider xmlFiles
68+ * @param string $filename
69+ * @param int $expected
70+ */
71+ public function testCollectionFromFile ($ filename , $ expected )
7272 {
73- $ collection = $ this ->getTestCollection (' sru-alma.xml ' );
73+ $ records = $ this ->getTestCollection ($ filename )-> toArray ( );
7474
75- $ this ->assertCount (3 , $ collection ->toArray ());
75+ $ this ->assertCount ($ expected , $ records );
76+ $ this ->assertInstanceOf (BibliographicRecord::class, $ records [0 ]);
7677 }
7778}
0 commit comments