Skip to content

Commit 1fe8408

Browse files
committed
Fix the Subject::getParts() method
1 parent 558b268 commit 1fe8408

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9-
None yet
9+
### Fixed
10+
11+
- Fixed the `Subject::getParts()` method.
1012

1113
## [2.0.1] - 2019-01-09
1214

src/Fields/Subject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function getId()
8888

8989
public function getParts()
9090
{
91-
return $this->getSubfields(self::$termComponentCodes);
91+
return $this->getSubfields('[' . implode('', self::$termComponentCodes) . ']', true);
9292
}
9393

9494
public function getTerm()

tests/SubjectFieldTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ public function testSubjectString()
1616
$this->assertEquals('lcsh', $sub->vocabulary);
1717
$this->assertEquals(Subject::TOPICAL_TERM, $sub->type);
1818
$this->assertEquals('Eightfold way (Nuclear physics) : Addresses, essays, lectures', strval($sub));
19+
$this->assertEquals('Eightfold way (Nuclear physics) : Addresses, essays, lectures', $sub->getTerm());
20+
21+
$sf0 = new \File_MARC_Subfield('a', 'Eightfold way (Nuclear physics)');
22+
$sf0->setPosition(0);
23+
$sf1 = new \File_MARC_Subfield('x', 'Addresses, essays, lectures');
24+
$sf1->setPosition(1);
25+
$this->assertEquals([$sf0, $sf1], $sub->getParts());
1926
}
2027

2128
public function testChopPunctuation()
@@ -33,12 +40,14 @@ public function testSubjects()
3340
{
3441
$record = $this->getNthrecord('sru-alma.xml', 3);
3542

36-
# Vocabulary from subfield 2
3743
$subject = $record->subjects[1];
3844
$this->assertInstanceOf('Scriptotek\Marc\Fields\Subject', $subject);
3945
$this->assertEquals('noubomn', $subject->vocabulary);
4046
$this->assertEquals('Elementærpartikler', strval($subject));
4147
$this->assertEquals(Subject::TOPICAL_TERM, $subject->getType());
48+
$this->assertEquals('Elementærpartikler', $subject->getTerm());
49+
$this->assertEquals([new \File_MARC_Subfield('a', 'Elementærpartikler')], $subject->getParts());
50+
4251
$this->assertNull($subject->getId());
4352
}
4453

0 commit comments

Comments
 (0)