private function parse()
 {
     $headerBodyParts = explode("\n", $this->getConfiguration()->getRawOutput(), 2);
     $header = trim($headerBodyParts[0]);
     $body = trim($headerBodyParts[1]);
     if (ExceptionOutputParser::is($body)) {
         $exceptionOutputParser = new ExceptionOutputParser();
         $exceptionOutputParser->setRawOutput($body);
         $this->output->setException($exceptionOutputParser->getOutput());
         return;
     }
     if ($this->isIncorrectUsageOutput($header)) {
         $this->output->setIsIncorrectUsageOutput(true);
         return;
     }
     $this->rawHeader = $header;
     $this->rawBody = $body;
     $optionsParser = new OptionsParser();
     $optionsParser->setOptionsOutput($header);
     $messageParser = new MessageParser();
     $this->output->setOptions($optionsParser->getOptions());
     $bodyDom = new \DOMDocument();
     $bodyDom->loadXML($this->extractXmlContentFromBody($body));
     $container = $bodyDom->getElementsByTagName('observationresponse')->item(0);
     if ($this->isPassedNoMessagesOutput($container)) {
         return;
     }
     $this->output->setSourceUrl($container->getAttribute('ref'));
     $this->output->setDateTime(new \DateTime($container->getAttribute('date')));
     $messageElements = $container->getElementsByTagName('message');
     foreach ($messageElements as $messageElement) {
         /* @var $messageElement \DomElement */
         $messageParser->setMessageElement($messageElement);
         /* @var $message \webignition\CssValidatorOutput\Message\Message */
         $message = $messageParser->getMessage();
         if ($this->getConfiguration()->getReportVendorExtensionIssuesAsWarnings() && $message->isError() && $this->isVendorExtensionMessage($message)) {
             $message = \webignition\CssValidatorOutput\Message\Warning::fromError($message);
         }
         if ($message->isWarning() && $this->getConfiguration()->getIgnoreWarnings() === true) {
             continue;
         }
         if ($this->hasRefDomainToIgnore($message)) {
             continue;
         }
         if ($this->getConfiguration()->getIgnoreVendorExtensionIssues() === true && $this->isVendorExtensionMessage($message)) {
             continue;
         }
         if ($this->getConfiguration()->getIgnoreFalseImageDataUrlMessages() && $this->isFalseImageDataUrlMessage($message)) {
             continue;
         }
         $this->output->addMessage($message);
     }
 }
 public function testParsedWarnings()
 {
     $warnings = $this->cssValidatorOutput->getWarnings();
     $this->assertEquals(2, count($warnings));
     foreach ($warnings as $warningIndex => $warning) {
         /* @var $error \webignition\CssValidatorOutput\Message\Warning */
         $this->assertInstanceOf('\\webignition\\CssValidatorOutput\\Message\\Warning', $warning);
         $this->assertEquals($this->expectedWarningValues[$warningIndex]['level'], $warning->getLevel());
         $this->assertEquals($this->expectedWarningValues[$warningIndex]['line'], $warning->getLineNumber());
         $this->assertEquals($this->expectedWarningValues[$warningIndex]['context'], $warning->getContext());
         $this->assertEquals($this->expectedWarningValues[$warningIndex]['message'], $warning->getMessage());
     }
 }
 public function testWarningsHaveNonBlankRefProperty()
 {
     foreach ($this->cssValidatorOutput->getWarnings() as $warning) {
         $this->assertTrue($warning->getRef() != '');
     }
 }
Ejemplo n.º 4
0
 /**
  * 
  * @return \webignition\CssValidatorOutput\CssValidatorOutput
  * @throws \InvalidArgumentException
  */
 public function validate()
 {
     if (!$this->hasConfiguration()) {
         throw new \InvalidArgumentException('Unable to validate; configuration not set', self::INVALID_ARGUMENT_EXCEPTION_CONFIGURATION_NOT_SET);
     }
     try {
         $this->getLocalProxyResource()->prepare();
     } catch (\webignition\WebResource\Exception\InvalidContentTypeException $invalidContentTypeException) {
         $cssValidatorOutput = new CssValidatorOutput();
         $cssValidatorOutputException = new ExceptionOutput();
         $cssValidatorOutputException->setType(new ExceptionOutputType('invalid-content-type:' . $invalidContentTypeException->getResponseContentType()->getTypeSubtypeString()));
         $cssValidatorOutput->setException($cssValidatorOutputException);
         return $cssValidatorOutput;
     } catch (\webignition\WebResource\Exception\Exception $webResourceException) {
         $cssValidatorOutput = new CssValidatorOutput();
         $cssValidatorOutputException = new ExceptionOutput();
         $cssValidatorOutputException->setType(new ExceptionOutputType('http' . $webResourceException->getResponse()->getStatusCode()));
         $cssValidatorOutput->setException($cssValidatorOutputException);
         return $cssValidatorOutput;
     } catch (ConnectException $connectException) {
         $curlExceptionFactory = new CurlExceptionFactory();
         if ($curlExceptionFactory->isCurlException($connectException)) {
             $curlException = $curlExceptionFactory->fromConnectException($connectException);
             $cssValidatorOutput = new CssValidatorOutput();
             $cssValidatorOutputException = new ExceptionOutput();
             $cssValidatorOutputException->setType(new ExceptionOutputType('curl' . $curlException->getCurlCode()));
             $cssValidatorOutput->setException($cssValidatorOutputException);
             return $cssValidatorOutput;
         }
     }
     $cssValidatorOutputParserConfiguration = new CssValidatorOutputParserConfiguration();
     $validatorOutput = $this->replaceLocalFilePathsWithOriginalFilePaths(implode("\n", $this->getRawValidatorOutputLines()));
     $cssValidatorOutputParserConfiguration->setRawOutput($validatorOutput);
     $this->localProxyResource->clear();
     if ($this->getConfiguration()->hasFlag(Flags::FLAG_IGNORE_FALSE_IMAGE_DATA_URL_MESSAGES)) {
         $cssValidatorOutputParserConfiguration->setIgnoreFalseImageDataUrlMessages(true);
     }
     if ($this->getConfiguration()->hasFlag(Flags::FLAG_IGNORE_WARNINGS)) {
         $cssValidatorOutputParserConfiguration->setIgnoreWarnings(true);
     }
     if ($this->getConfiguration()->getVendorExtensionSeverityLevel() === VendorExtensionSeverityLevel::LEVEL_IGNORE) {
         $cssValidatorOutputParserConfiguration->setIgnoreVendorExtensionIssues(true);
     }
     if ($this->getConfiguration()->getVendorExtensionSeverityLevel() === VendorExtensionSeverityLevel::LEVEL_WARN) {
         $cssValidatorOutputParserConfiguration->setReportVendorExtensionIssuesAsWarnings(true);
     }
     if ($this->getConfiguration()->hasDomainsToIgnore()) {
         $cssValidatorOutputParserConfiguration->setRefDomainsToIgnore($this->getConfiguration()->getDomainsToIgnore());
     }
     $cssValidatorOutputParser = new CssValidatorOutputParser();
     $cssValidatorOutputParser->setConfiguration($cssValidatorOutputParserConfiguration);
     $output = $cssValidatorOutputParser->getOutput();
     if ($this->getLocalProxyResource()->hasWebResourceExceptions()) {
         foreach ($this->getLocalProxyResource()->getWebResourceExceptions() as $webResourceException) {
             $error = new \webignition\CssValidatorOutput\Message\Error();
             $error->setContext('');
             $error->setLineNumber(0);
             if ($webResourceException instanceof \webignition\WebResource\Exception\InvalidContentTypeException) {
                 $error->setMessage('invalid-content-type:' . (string) $webResourceException->getResponseContentType());
             } else {
                 $error->setMessage('http-error:' . $webResourceException->getResponse()->getStatusCode());
             }
             $error->setRef($webResourceException->getRequest()->getUrl());
             $output->addMessage($error);
         }
     }
     if ($this->getLocalProxyResource()->hasCurlExceptions()) {
         foreach ($this->getLocalProxyResource()->getCurlExceptions() as $curlExceptionDetails) {
             $error = new \webignition\CssValidatorOutput\Message\Error();
             $error->setContext('');
             $error->setLineNumber(0);
             $error->setMessage('curl-error:' . $curlExceptionDetails['exception']->getCurlCode());
             $error->setRef($curlExceptionDetails['url']);
             $output->addMessage($error);
         }
     }
     return $cssValidatorOutputParser->getOutput();
 }