/**
  * Read LIFT entry with error reporting
  *
  * @param SimpleXMLElement $sxeNode
  * @param LexEntryModel $entry
  * @param LiftMergeRule $mergeRule
  */
 private function readEntryWithErrorReport($sxeNode, $entry, $mergeRule = LiftMergeRule::CREATE_DUPLICATES)
 {
     try {
         $this->liftDecoder->readEntry($sxeNode, $entry, $mergeRule);
         $this->liftImportNodeError->addSubnodeError($this->liftDecoder->getImportNodeError());
     } catch (Exception $e) {
         $this->liftImportNodeError->addSubnodeError($this->liftDecoder->getImportNodeError());
         $this->report->nodeErrors[] = $this->liftImportNodeError;
         if ($this->report->hasError()) {
             error_log($this->report->toString());
         }
         throw new \Exception($e);
     }
 }
 public function testZipImport_ImportReport_FormatOk()
 {
     $rangeImportNodeError = new LiftRangeImportNodeError(LiftRangeImportNodeError::FILE, 'Test.lift-ranges');
     $rangeImportNodeError->addRangeNotFound('rangeId_01');
     $rangeImportNodeError->addRangeNotFound('rangeId_02');
     $exampleImportNodeError = new LiftImportNodeError(LiftImportNodeError::EXAMPLE, '');
     $exampleImportNodeError->addUnhandledElement('elementName01');
     $senseImportNodeError = new LiftImportNodeError(LiftImportNodeError::SENSE, '00001-00001');
     $senseImportNodeError->addUnhandledField('typeName01');
     $senseImportNodeError->addUnhandledMedia('url01', 'context01');
     $senseImportNodeError->addSubnodeError($exampleImportNodeError);
     $entryImportNodeError = new LiftImportNodeError(LiftImportNodeError::ENTRY, '00000-00001');
     $entryImportNodeError->addUnhandledNote('noteType01');
     $entryImportNodeError->addUnhandledTrait('traitName01');
     $entryImportNodeError->addSubnodeError($senseImportNodeError);
     $liftImportNodeError = new LiftImportNodeError(LiftImportNodeError::FILE, 'Test.lift');
     $liftImportNodeError->addSubnodeError($rangeImportNodeError);
     $liftImportNodeError->addSubnodeError($entryImportNodeError);
     $zipNodeError = new ZipImportNodeError(ZipImportNodeError::FILE, 'Test.zip');
     $zipNodeError->addSubnodeError($liftImportNodeError);
     $report = new ImportErrorReport();
     $report->nodeErrors[] = $zipNodeError;
     //         echo "<pre>";
     //         echo $report->toFormattedString();
     //         echo "</pre>";
     $this->assertRegExp("/" . self::zipImportReport . "/", $report->toFormattedString());
 }
 /**
  * Recursively sanitizes the element only allowing <span> elements through; coverts everything else to text
  *  - also removes native language spans, i.e those that match the input system tag
  *
  * @param \DOMElement $textDom
  * @param string $inputSystemTag
  * @param LiftImportNodeError $currentNodeError
  * @return string
  */
 public static function sanitizeSpans($textDom, $inputSystemTag, $currentNodeError = null)
 {
     $textStr = '';
     foreach ($textDom->childNodes as $child) {
         if ($child->nodeType == XML_TEXT_NODE) {
             $childTextStr = $child->textContent;
         } else {
             if ($currentNodeError && $child->nodeName != 'span') {
                 $currentNodeError->addUnhandledElement($child->nodeName);
             }
             // recurse to sanitize child node
             $childTextStr = self::sanitizeSpans($child, $inputSystemTag, $currentNodeError);
         }
         if ($child->nodeName == 'span') {
             $spanTag = '<span';
             $isNativeSpan = false;
             foreach ($child->attributes as $attribute) {
                 $spanTag .= ' ' . $attribute->name . '="' . $attribute->value . '"';
                 if ($attribute->name == 'lang' && $attribute->value == $inputSystemTag) {
                     $isNativeSpan = true;
                 }
             }
             $spanTag .= '>';
             if ($isNativeSpan) {
                 $textStr .= $childTextStr;
             } else {
                 $textStr .= $spanTag . $childTextStr . '</span>';
             }
         } else {
             $textStr .= $childTextStr;
         }
     }
     return $textStr;
 }