/**
  *
  * Test of PicaPlainParser function, primary used by HeBIS in order to parse
  * Pica+ records in HDS
  *
  * @test
  */
 public function testParseField()
 {
     $rawPicaRecord = $this->picaFile;
     /*
      * split raw record in its levels (raw)
      */
     $recordLevels = explode("\n\n", $rawPicaRecord);
     $mode = null;
     $modeArr['alg']['count'] = $modeArr['lok']['count'] = $modeArr['exp']['count'] = 0;
     $record['fields'] = [];
     $j = 0;
     foreach ($recordLevels as $level) {
         /*
          * find record type
          */
         $match = [];
         if (preg_match("/^(alg|lok|exp)/", $level, $match)) {
             if (!empty($record['fields'][$match[1]])) {
                 $modeArr[$match[1]]['count']++;
                 $mode = $match[1] . $modeArr[$match[1]]['count'];
             } else {
                 $mode = $match[1];
             }
         }
         /*
          * split level in its fields
          */
         $fieldsArray = explode("\n", $level);
         /*
          * parse lines to Pica Fields
          */
         $rawFields = array_slice($fieldsArray, 1, count($fieldsArray) - 1);
         $record['fields'][$mode] = [];
         foreach ($rawFields as $rawField) {
             $record['fields'][$mode][] = Parser::parseField($rawField);
         }
     }
     $this->assertNotEmpty($record['fields']['alg']);
     $this->assertNotEmpty($record['fields']['lok']);
     $this->assertNotEmpty($record['fields']['exp']);
     $field = $this->searchField($record, "028A");
     $notExist = true;
     $empty = true;
     foreach ($field['subfields'] as $subField) {
         if ($subField['code'] === '#' && !empty($subField['code'])) {
             $notExist = false;
             $empty = false;
         }
     }
     if ($notExist && $empty) {
         $this->fail('pseudo sub field "#" not found or empty');
     }
     // assert occurence of field 201B in first exp equals 01
     $this->assertEquals('01', $record['fields']['exp'][0]['occurrence']);
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 protected function next()
 {
     $record = false;
     if (current($this->_data) !== false) {
         $record = array('fields' => array());
         do {
             $line = current($this->_data);
             $record['fields'][] = PicaPlainParser::parseField($line);
         } while (next($this->_data));
         next($this->_data);
     }
     return $record;
 }