public function testGetErrorsByUrl() { $error1 = new \webignition\CssValidatorOutput\Message\Error(); $error1->setRef('http://foo.example.com'); $error1->setMessage('error 1 message'); $error2 = new \webignition\CssValidatorOutput\Message\Error(); $error2->setRef('http://bar.example.com'); $error2->setMessage('error 2 message'); $error3 = new \webignition\CssValidatorOutput\Message\Error(); $error3->setRef('http://bar.example.com'); $error3->setMessage('error 3 message'); $output = new \webignition\CssValidatorOutput\CssValidatorOutput(); $output->addMessage($error1); $output->addMessage($error2); $output->addMessage($error3); $errorsForFoo = $output->getErrorsByUrl('http://foo.example.com'); $errorsForBar = $output->getErrorsByUrl('http://bar.example.com'); $this->assertEquals(1, count($errorsForFoo)); $this->assertEquals(2, count($errorsForBar)); $this->assertEquals('error 1 message', $errorsForFoo[0]->getMessage()); $this->assertEquals('error 2 message', $errorsForBar[0]->getMessage()); $this->assertEquals('error 3 message', $errorsForBar[1]->getMessage()); }
/** * * @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(); }