Exemplo n.º 1
0
    public function testAnalysisRecursive2()
    {
        //PHASE 2 check for errors
        $source_seg = <<<SRC
<g id="pt231"><g id="pt232">APPARTEMENT ELSA ET JOY </g><g id="pt233">&lt;&lt;1.0&gt;&gt;</g></g> <g id="pt235"><g id="pt236"> </g></g> <g id="pt238"><g id="pt239">Elsa sur son ordinateur tape des lignes de code quand sa colocataire, Joy, entre dans sa chambre.</g></g>
SRC;
        $target_seg = <<<TRG
<g id="pt231"><g id="pt232">ELSA AND JOY'S<x id="231"/> APARTMENT </g><g id="pt233"> &lt;&lt;1.0&gt;&gt;</g></g> <g id="pt235"><g id="pt236"> </g></g> <g id="pt238"><g id="pt239">Elsa's on her computer typing lines of code when her roommate, Joy, enters the room.</g></g>
TRG;
        $check = new QA($source_seg, $target_seg);
        $check->performConsistencyCheck();
        $this->assertTrue($check->thereAreNotices());
        //a space after tag: <g id="pt233"> and a mismatch <x id="231"/>
        $this->assertTrue($check->thereAreWarnings());
        //order changed in the tags
        $this->assertTrue($check->thereAreErrors());
        //mismatch <x id="231"/>
        $errors = $check->getErrors();
        $warnings = $check->getWarnings();
        $notices = $check->getNotices();
        $this->assertCount(1, $errors);
        $this->assertCount(2, $warnings);
        $this->assertCount(3, $notices);
        $this->assertAttributeEquals(1000, 'outcome', $errors[0]);
        $this->assertAttributeEquals(15, 'outcome', $warnings[0]);
        $this->assertAttributeEquals(1000, 'outcome', $warnings[1]);
        $this->assertAttributeEquals(1100, 'outcome', $notices[0]);
        $this->assertAttributeEquals(15, 'outcome', $notices[1]);
        $this->assertAttributeEquals(1000, 'outcome', $notices[2]);
        $this->assertEquals('[{"outcome":15,"debug":"Tag order mismatch ( 1 )"},{"outcome":1000,"debug":"Tag mismatch ( 1 )"}]', $check->getWarningsJSON());
        $this->assertEquals('[{"outcome":1000,"debug":"Tag mismatch ( 1 )"}]', $check->getErrorsJSON());
        $this->assertEquals('[{"outcome":1100,"debug":"More\\/fewer whitespaces found next to the tags. ( 1 )"},{"outcome":15,"debug":"Tag order mismatch ( 1 )"},{"outcome":1000,"debug":"Tag mismatch ( 1 )"}]', $check->getNoticesJSON());
        $check = new QA($source_seg, $target_seg);
        $check->performTagCheckOnly();
        $this->assertTrue($check->thereAreErrors());
        $errors = $check->getErrors();
        $this->assertCount(1, $errors);
        $this->assertAttributeEquals(1000, 'outcome', $errors[0]);
        $this->assertRegExp('/ 1 /', $check->getErrorsJSON());
        $this->assertTrue($check->thereAreNotices());
        $this->assertTrue($check->thereAreWarnings());
        $this->assertTrue($check->thereAreErrors());
        $this->assertEquals($check->getNotices(), $check->getWarnings());
        $this->assertEquals($check->getNotices(), $check->getErrors());
        $this->assertEquals($check->getWarnings(), $check->getErrors());
    }
Exemplo n.º 2
0
 /**
  * Performs a check on single segment
  *
  */
 private function __segmentWarningsCall()
 {
     $this->result['details'] = null;
     $this->result['token'] = $this->__postInput->token;
     $this->result['total'] = 0;
     $QA = new QA($this->__postInput->src_content, $this->__postInput->trg_content);
     $QA->performConsistencyCheck();
     if (is_array($this->__postInput->glossaryList) && !empty($this->__postInput->glossaryList)) {
         /**
          * FIXME: temporarily disabled due to a bug.
          */
         //            $QA->performGlossaryCheck( $this->__postInput->glossaryList );
     }
     if ($QA->thereAreNotices()) {
         //        if ( $QA->thereAreErrors() ) {
         $this->result['details'] = array();
         $this->result['details']['id_segment'] = $this->__postInput->id;
         //            $this->result[ 'details' ][ 'warnings' ]   = $QA->getErrorsJSON();
         //            $this->result[ 'total' ]                                             = count( $QA->getErrors() );
         $this->result['details']['warnings'] = $QA->getNoticesJSON();
         $this->result['details']['tag_mismatch'] = $QA->getMalformedXmlStructs();
         $this->result['details']['tag_mismatch']['order'] = $QA->getTargetTagPositionError();
         $this->result['total'] = count($QA->getNotices());
         //temp
         //            Log::doLog($this->__postInput->trg_content);
         //            Log::doLog($this->result);
     }
 }
Exemplo n.º 3
0
 /**
  * @return array
  */
 public function getWarning()
 {
     $result = array();
     $QA = new QA($this->source, $this->translation);
     $QA->performConsistencyCheck();
     if ($QA->thereAreNotices()) {
         $notices = $QA->getNoticesJSON();
         $notices = json_decode($notices, true);
         //the outer if it's here because $notices can be
         //an empty string and json_decode will fail into null value
         if (!empty($notices)) {
             $result = array_merge($result, Utils::array_column($notices, 'debug'));
         }
         $tag_mismatch = $QA->getMalformedXmlStructs();
         $tag_order_mismatch = $QA->getTargetTagPositionError();
         if (count($tag_mismatch) > 0) {
             $result[] = sprintf("Tag Mismatch ( %d )", count($tag_mismatch));
         }
         if (count($tag_order_mismatch) > 0) {
             $result[] = sprintf("Tag order mismatch ( %d )", count($tag_order_mismatch));
         }
     }
     $this->warnings = $result;
 }