Commit 816565ac authored by David Maus's avatar David Maus
Browse files

New function: Return true if field has subfield

* src/HAB/Pica/Record/Field.php (hasSubfield): New function. Return true
  if field has subfield.
parent f670b474
......@@ -262,6 +262,21 @@ class Field
return null;
}
/**
* Return true if a subfield with given code exists.
*
* If optional argument $n return true if the field has subfield
* at the specified position.
*
* @param string $code Subfield code
* @param integer $n Optional zero-based subfield index
* @return boolean
*/
public function hasSubfield ($code, $n = 0)
{
return (boolean)$this->getNthSubfield($code, $n);
}
/**
* Return all subfields with the specified code.
*
......
......@@ -130,6 +130,17 @@ class FieldTest extends PHPUnit_FrameWork_TestCase
$this->assertNull($s);
}
public function testHasSubfield ()
{
$f = new Field('003@', 0, array(new Subfield('a', 'first a'),
new Subfield('b', 'first b'),
new Subfield('a', 'second a')));
$this->assertTrue($f->hasSubfield('a'));
$this->assertTrue($f->hasSubfield('a', 1));
$this->assertFalse($f->hasSubfield('a', 2));
$this->assertFalse($f->hasSubfield('c'));
}
/**
* @depends testSetSubfields
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment