Skip to content

Commit 3a1958a

Browse files
committed
Add tests for the Classification class
1 parent d3aa726 commit 3a1958a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/ClassificationFieldTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Scriptotek\Marc\Fields\Classification;
6+
7+
class ClassificationFieldTest extends TestCase
8+
{
9+
public function testClassificationString()
10+
{
11+
$record = $this->getNthrecord('sru-alma.xml', 1);
12+
13+
# Vocabulary from indicator2
14+
$cls = $record->classifications[0];
15+
$this->assertInstanceOf('Scriptotek\Marc\Fields\Classification', $cls);
16+
$this->assertEquals('msc', $cls->scheme);
17+
$this->assertEquals('81', strval($cls));
18+
$this->assertEquals(Classification::OTHER_SCHEME, $cls->type);
19+
}
20+
21+
public function testJsonSerialization()
22+
{
23+
$record = $this->getNthrecord('sru-alma.xml', 3);
24+
$cls = $record->classifications[1];
25+
26+
$this->assertJsonStringEqualsJsonString(
27+
json_encode([
28+
'scheme' => 'inspec',
29+
'number' => 'a1130',
30+
]),
31+
json_encode($cls)
32+
);
33+
}
34+
35+
public function testRepeatedA()
36+
{
37+
$record = $this->makeMinimalRecord('
38+
<datafield tag="084" ind1=" " ind2=" ">
39+
<subfield code="a">330</subfield>
40+
<subfield code="a">380</subfield>
41+
<subfield code="a">650</subfield>
42+
<subfield code="q">DE-101</subfield>
43+
<subfield code="2">sdnb</subfield>
44+
</datafield>
45+
');
46+
47+
$this->assertCount(3, $record->classifications);
48+
49+
$this->assertEquals('DE-101', $record->classifications[2]->assigningVocabulary);
50+
$this->assertEquals('sdnb', $record->classifications[2]->scheme);
51+
}
52+
}

0 commit comments

Comments
 (0)