public function testExcludeMailtoLinks() { $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example19', 'http://example.com')); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $this->assertEquals([], $checker->getErrored()); }
public function testIgnoreJavascriptColonAnything() { $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example11', 'http://example.com/')); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $this->assertEquals(0, count($checker->getAll())); }
public function testWithVariedLinkTypes() { $this->loadHttpClientFixtures(array('HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok')); $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example04', 'http://example.com/')); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $this->assertEquals(30, count($checker->getAll())); }
public function testReuseLinkState() { $this->loadHttpClientFixtures(array("HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 301 Moved Permanently\r\nLocation: /redirect1\r\nContent-Length: 0\r\n\r\n")); $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example10', 'http://example.com/foo')); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $this->assertEquals(array(new LinkResult('http://example.com/', '<a href="http://example.com/">Example no subdomain</a>', new LinkState(LinkState::TYPE_HTTP, 301))), $checker->getErrored()); }
public function testExcludeMailtoLinks() { $this->loadHttpClientFixtures(array('HTTP/1.1 200 Ok')); $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example05', 'http://example.com')); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $this->assertEquals(array(), $checker->getErrored()); }
public function testWithMixedHttpStatusCodesAndCurlCodes() { $this->loadHttpClientFixtures(array(new ConnectException('cURL error 6: Couldn\'t resolve host. The given remote host was not resolved.', new Request('GET', 'http://example.com/')), 'HTTP/1.1 200 Ok', 'HTTP/1.1 500 Internal Server Error', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok')); $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example01', 'http://example.com')); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $this->assertEquals(array(new LinkResult('http://www.youtube.com/example', '<a href="http://www.youtube.com/example"><img src="/images/youtube.png"></a>', new LinkState(LinkState::TYPE_CURL, 6)), new LinkResult('http://blog.example.com/', '<a href="http://blog.example.com"><img src="/images/blog.png"></a>', new LinkState(LinkState::TYPE_HTTP, 500))), $checker->getErrored()); }
public function testReuseLinkState() { $this->loadHttpClientFixtures(array('HTTP/1.1 500 Internal Server Error', 'HTTP/1.1 200 Ok')); $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example12', 'http://example.com')); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $this->assertEquals(array(new LinkResult('http://example.com/', '<a href="http://example.com/">Example no subdomain 1</a>', new LinkState(LinkState::TYPE_HTTP, 500)), new LinkResult('http://example.com/', '<a href="http://example.com/">Example no subdomain 2</a>', new LinkState(LinkState::TYPE_HTTP, 200))), $checker->getAll()); }
public function testWithMixedHttpStatusCodesAndCurlCodes() { $this->loadHttpClientFixtures(array(new ConnectException('cURL error 6: Couldn\'t resolve host. The given remote host was not resolved.', new Request('GET', 'http://example.com/')), 'HTTP/1.1 200 Ok', new ConnectException('cURL error 28: Operation timeout. The specified time-out period was reached according to the conditions.', new Request('GET', 'http://example.com/')), 'HTTP/1.1 500 Internal Server Error', 'HTTP/1.1 400 Bad Request', 'HTTP/1.1 200 Ok')); $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example01', 'http://example.com/')); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $this->assertEquals(array(new LinkResult('http://example.com/images/youtube.png', '<img src="/images/youtube.png">', new LinkState(LinkState::TYPE_HTTP, 200)), new LinkResult('http://example.com/images/twitter.png', '<img src="/images/twitter.png">', new LinkState(LinkState::TYPE_HTTP, 200))), $checker->getWorking()); }
public function testExcludeDomains() { $this->loadHttpClientFixtures(array('HTTP/1.1 200 Ok')); $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example08', 'http://example.com')); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $checker->getConfiguration()->setUrlsToExclude(array('http://example.com/foo', 'http://example.com/bar')); $this->assertEquals(1, count($checker->getAll())); }
public function testReuseLinkState() { $this->loadHttpClientFixtures(array('HTTP/1.1 200', 'HTTP/1.1 200', 'HTTP/1.1 200')); $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example17', 'http://example.com')); $checker = $this->getDefaultChecker(); $checker->getConfiguration()->enableIgnoreFragmentInUrlComparison(); $checker->setWebPage($webPage); $this->assertEquals(6, count($checker->getAll())); }
public function setUp() { $this->loadHttpClientFixtures(array('HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok', 'HTTP/1.1 200 Ok')); $webPage = new WebPage(); $webPage->setHttpResponse($this->getHttpFixtureFromHtmlDocument('example16', 'http://example.com')); $cookieJar = new CookieJar(); foreach ($this->getCookies() as $cookieData) { $cookieJar->setCookie(new SetCookie($cookieData)); } $this->getHttpClient()->getEmitter()->attach(new HttpCookieSubscriber($cookieJar)); $checker = $this->getDefaultChecker(); $checker->setWebPage($webPage); $checker->getAll(); }
/** * * @return boolean|\webignition\WebResource\WebPage\WebPage */ private function retrieveRootWebPage() { $request = clone $this->getConfiguration()->getBaseRequest(); $request->setUrl($this->getConfiguration()->getRootUrl()); $this->setRequestCookies($request); try { $response = $request->send(); } catch (\Guzzle\Http\Exception\RequestException $requestException) { return false; } try { $webPage = new WebPage(); $webPage->setHttpResponse($response); return $webPage; } catch (\webignition\WebResource\Exception $exception) { // Invalid content type (is not the URL of a web page) return false; } }