/** * @expectedException chkGlobalException * @group WebCheckerTests */ public function testThrowingLongException() { $customException = new chkGlobalException( 'testing long exceptions' ); $customException->log( $message, ezcLog::ERROR, 'short' ); $customException->log( $message, ezcLog::ERROR, 'long' ); $customException->log( $message, ezcLog::ERROR, 'long', 'html' ); throw $customException; }
/** * Check W3C compliance check * * @param array $this->options - array('url'=>string, 'urls'=>array, 'fromPage'=>string) * @see http://pear.php.net/manual/en/package.webservices.services-w3c-htmlvalidator.examples.php * @see validator.w3.org/docs/api.html * @see iBenchmarkable::run() * @return boolean */ public function run() { //TODO : RETURN an ARRAY : $result = array(); $log = ''; if ( !isset($this->urls ) ) { throw new chkMissingOptionsCheckException( __METHOD__.' : urls array is missing in $this->options parameter' ); } if ( count($this->urls ) === 0 ) { throw new chkMissingOptionsCheckException( __METHOD__.' : urls array is empty in $this->options parameter' ); } foreach ($this->urls as $url) { if ( !filter_var($url, FILTER_VALIDATE_URL ) ) { throw new chkFilterVarException( __METHOD__.' : '. $url . ' is not a valid URL' ); } } // @codeCoverageIgnoreStart if ( class_exists('Services_W3C_HTMLValidator' ) ) { throw new chkW3CPearCheckException( __METHOD__.' : Please uncomment this piece of code below in ' . __FILE__. ', line ' . __LINE__ . ' :' ); //<PEAR's Services_W3C_HTMLValidator> //require_once 'Services/W3C/HTMLValidator.php'; //$v = new Services_W3C_HTMLValidator(); //$r = $v->validate($this->options['url'] ); //return $r->isValid(); //</PEAR's Services_W3C_HTMLValidator> } // @codeCoverageIgnoreEnd // @codeCoverageIgnoreStart if( !function_exists( 'curl_init' ) ) { throw new chkMissingPHPExtensionCheckException( __METHOD__.' : is php-curl installed ? :' ); } // @codeCoverageIgnoreEnd $success = true; foreach ($this->urls as $url) { if( $success ) $ch = curl_init(); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt( $ch, CURLOPT_URL, chkBenchmarkW3C::W3C_URL_CHECKER . $url ); $html = curl_exec( $ch ); curl_close( $ch ); if(strpos( $html,"Passed" ) === false) { $message = "\n" . chkBenchmarkW3C::W3C_URL_CHECKER. $url . " : ERRORS FOUND at the W3C validator check"; $exception = new chkGlobalException(); $exception->log( $message ); $success = false; if( $this->stopOnError ) { break; } } $message = "\n" . chkBenchmarkW3C::W3C_URL_CHECKER . $url . " : OK at the W3C validator check"; $exception = new chkGlobalException(); $exception->log( $message ); $success = true; } return $success; }