/**
  *
  */
 public function testCrawlUrl()
 {
     $url = 'http://test.com';
     $source = 'source';
     $urls = ['/index.php'];
     $Http = $this->getMock('\\Essence\\Http\\Client');
     $Http->expects($this->once())->method('get')->with($this->isEqual($url))->will($this->returnValue($source));
     $Crawler = $this->getMockBuilder('\\Essence\\Crawler')->disableOriginalConstructor()->getMock();
     $Crawler->expects($this->once())->method('crawl')->with($this->isEqual($source))->will($this->returnValue($urls));
     $Essence = new Essence(['Http' => $Http, 'Crawler' => $Crawler]);
     $this->assertEquals(Url::resolveAll($urls, $url), $Essence->crawlUrl($url));
 }
Exemplo n.º 2
0
 /**
  *
  */
 public function testResolveAll()
 {
     $urls = ['/home', '../home'];
     $expected = ['http://test.com/home'];
     $this->assertEquals($expected, Url::resolveAll($urls, 'http://test.com'));
 }
Exemplo n.º 3
0
 /**
  *	Crawls the given source for extractable URLs, optionnaly
  *	resolving them relatively to a base one.
  *
  *	@see Essence\Crawler::crawl()
  *	@see Essence\Utility\Url::resolve()
  *	@param string $source HTML source.
  *	@param string $base Base URL.
  *	@return array URLs.
  */
 public function crawl($source, $base = '')
 {
     $urls = $this->_Crawler->crawl($source);
     return $base ? Url::resolveAll($urls, $base) : $urls;
 }