2
2
3
3
namespace Tests ;
4
4
5
+ use Scriptotek \Marc \BibliographicRecord ;
5
6
use Scriptotek \Marc \Collection ;
6
7
use Scriptotek \Marc \Exceptions \XmlException ;
7
8
8
9
class CollectionTest extends TestCase
9
10
{
11
+ /**
12
+ * Test that an empty Collection is created if no MARC records were found in the input.
13
+ */
10
14
public function testEmptyCollection ()
11
15
{
12
16
$ source = '<?xml version="1.0" encoding="UTF-8" ?><test></test> ' ;
@@ -15,21 +19,6 @@ public function testEmptyCollection()
15
19
$ this ->assertCount (0 , $ collection ->toArray ());
16
20
}
17
21
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
-
33
22
/**
34
23
* Test that it XmlException is thrown when the specified encoding (UTF-16)
35
24
* differs from the actual encoding (UTF-8).
@@ -40,38 +29,50 @@ public function testExceptionOnInvalidEncoding()
40
29
$ this ->getTestCollection ('alma-bibs-api-invalid.xml ' );
41
30
}
42
31
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 ()
51
39
{
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
+ ] ;
55
43
}
56
44
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 ()
65
52
{
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
+ ];
69
61
}
70
62
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 )
72
72
{
73
- $ collection = $ this ->getTestCollection (' sru-alma.xml ' );
73
+ $ records = $ this ->getTestCollection ($ filename )-> toArray ( );
74
74
75
- $ this ->assertCount (3 , $ collection ->toArray ());
75
+ $ this ->assertCount ($ expected , $ records );
76
+ $ this ->assertInstanceOf (BibliographicRecord::class, $ records [0 ]);
76
77
}
77
78
}
0 commit comments