Skip to content

Commit

Permalink
Fix the Subject::getParts() method
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Jan 15, 2019
1 parent 558b268 commit 1fe8408
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

None yet
### Fixed

- Fixed the `Subject::getParts()` method.

## [2.0.1] - 2019-01-09

Expand Down
2 changes: 1 addition & 1 deletion src/Fields/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getId()

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

public function getTerm()
Expand Down
11 changes: 10 additions & 1 deletion tests/SubjectFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public function testSubjectString()
$this->assertEquals('lcsh', $sub->vocabulary);
$this->assertEquals(Subject::TOPICAL_TERM, $sub->type);
$this->assertEquals('Eightfold way (Nuclear physics) : Addresses, essays, lectures', strval($sub));
$this->assertEquals('Eightfold way (Nuclear physics) : Addresses, essays, lectures', $sub->getTerm());

$sf0 = new \File_MARC_Subfield('a', 'Eightfold way (Nuclear physics)');
$sf0->setPosition(0);
$sf1 = new \File_MARC_Subfield('x', 'Addresses, essays, lectures');
$sf1->setPosition(1);
$this->assertEquals([$sf0, $sf1], $sub->getParts());
}

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

# Vocabulary from subfield 2
$subject = $record->subjects[1];
$this->assertInstanceOf('Scriptotek\Marc\Fields\Subject', $subject);
$this->assertEquals('noubomn', $subject->vocabulary);
$this->assertEquals('Elementærpartikler', strval($subject));
$this->assertEquals(Subject::TOPICAL_TERM, $subject->getType());
$this->assertEquals('Elementærpartikler', $subject->getTerm());
$this->assertEquals([new \File_MARC_Subfield('a', 'Elementærpartikler')], $subject->getParts());

$this->assertNull($subject->getId());
}

Expand Down

0 comments on commit 1fe8408

Please sign in to comment.