public function testValidate()
    {
        $xHtml = <<<END
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
</body>
</html>
END;
        $this->assertEmpty(W3CValidatorServiceUtil::validate($xHtml));
        $xHtml = <<<END
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>
</head>
<body>
</body>
</html>
END;
        $this->assertTrue(count(W3CValidatorServiceUtil::validate($xHtml)) >= 1);
    }
예제 #2
0
 /**
  * Validates the page content against the XHTML schema
  * and writes the problems directly to output in bright
  * red on yellow. Is public for access by unit tests.
  */
 public static function validate($content)
 {
     $wrapper = '<span style="background-color: yellow; color: #c00000;"><b>{text}</b></span><br />';
     $valid = false;
     try {
         $xhtmlValidationErrors = W3CValidatorServiceUtil::validate($content);
         if (count($xhtmlValidationErrors)) {
             foreach ($xhtmlValidationErrors as $xhtmlValidationError) {
                 self::$xhtmlValidationErrors[] = str_replace('{text}', $xhtmlValidationError, $wrapper);
             }
         } else {
             $valid = true;
         }
         if (!count(self::$xhtmlValidationErrors)) {
             $valid = true;
         }
     } catch (Exception $e) {
         self::$xhtmlValidationErrors[] = str_replace('{text}', 'Error accessing W3C validation service.', $wrapper);
         self::$xhtmlValidationErrors[] = str_replace('{text}', $e->getMessage(), $wrapper);
     }
     return $valid;
 }