Esempio n. 1
0
 public function testFetchingPageSnippets()
 {
     $bingFetcher = Builder::create('Bing');
     $getPageSnippets = TestHelper::getMethod('getPageSnippets', 'Bing');
     $getSHDWrapper = TestHelper::getMethod('getSHDWrapper', 'Bing');
     $SHDObject = $getSHDWrapper->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=foo'));
     $snippets = $getPageSnippets->invokeArgs($bingFetcher, array($SHDObject));
     $this->assertCount(10, $snippets);
     foreach ($snippets as $snippet) {
         $this->assertTrue(is_string($snippet) && !empty($snippet));
     }
     $this->assertTrue($bingFetcher->cacheHit('http://www.bing.com/search?q=foo'));
     $this->assertFalse($bingFetcher->cacheHit('http://www.bing.com/search?q=foo&first=11'));
     $SHDObject = $getSHDWrapper->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=foo&first=11'));
     $snippets = $getPageSnippets->invokeArgs($bingFetcher, array($SHDObject));
     $this->assertCount(10, $snippets);
     foreach ($snippets as $snippet) {
         $this->assertTrue(is_string($snippet) && !empty($snippet));
     }
     $this->assertTrue($bingFetcher->cacheHit('http://www.bing.com/search?q=foo'));
     $this->assertTrue($bingFetcher->cacheHit('http://www.bing.com/search?q=foo&first=11'));
     $bingFetcher->flushCache();
     $this->assertFalse($bingFetcher->cacheHit('http://www.bing.com/search?q=foo'));
     $this->assertFalse($bingFetcher->cacheHit('http://www.bing.com/search?q=foo&first=11'));
     $bingFetcher->removeCache();
 }
Esempio n. 2
0
 public function testFetchingPageSnippets()
 {
     $askFetcher = Builder::create('Ask');
     $getPageSnippets = TestHelper::getMethod('getPageSnippets', 'Ask');
     $getSHDWrapper = TestHelper::getMethod('getSHDWrapper', 'Ask');
     $SHDObject = $getSHDWrapper->invokeArgs($askFetcher, array('http://us.ask.com/web?q=foo'));
     $snippets = $getPageSnippets->invokeArgs($askFetcher, array($SHDObject));
     $this->assertCount(10, $snippets);
     foreach ($snippets as $snippet) {
         $this->assertTrue(is_string($snippet) && !empty($snippet));
     }
     $this->assertTrue($askFetcher->cacheHit('http://us.ask.com/web?q=foo'));
     $this->assertFalse($askFetcher->cacheHit('http://us.ask.com/web?q=foo&page=2'));
     $SHDObject = $getSHDWrapper->invokeArgs($askFetcher, array('http://us.ask.com/web?q=foo&page=2'));
     $snippets = $getPageSnippets->invokeArgs($askFetcher, array($SHDObject));
     $this->assertCount(10, $snippets);
     foreach ($snippets as $snippet) {
         $this->assertTrue(is_string($snippet) && !empty($snippet));
     }
     $this->assertTrue($askFetcher->cacheHit('http://us.ask.com/web?q=foo'));
     $this->assertTrue($askFetcher->cacheHit('http://us.ask.com/web?q=foo&page=2'));
     $askFetcher->flushCache();
     $this->assertFalse($askFetcher->cacheHit('http://us.ask.com/web?q=foo'));
     $this->assertFalse($askFetcher->cacheHit('http://us.ask.com/web?q=foo&page=2'));
     $askFetcher->removeCache();
 }
Esempio n. 3
0
 public function testFetchingMethods()
 {
     $googleFetcher = Builder::create($this->engines[0]);
     $fetchSerpContent = TestHelper::getMethod('fetchSerpContent', 'Google');
     $getSHDWrapper = TestHelper::getMethod('getSHDWrapper', 'Google');
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=foo"));
     $fetchedContent = $fetchSerpContent->invokeArgs($googleFetcher, array('http://www.google.com/search?q=foo'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($googleFetcher->cacheHit("http://www.google.com/search?q=foo"));
     $SHDObject = $getSHDWrapper->invokeArgs($googleFetcher, array('http://www.google.com/search?q=foo'));
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=bar"));
     $fetchedContent = $fetchSerpContent->invokeArgs($googleFetcher, array('http://www.google.com/search?q=bar'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($googleFetcher->cacheHit("http://www.google.com/search?q=bar"));
     $SHDObject = $getSHDWrapper->invokeArgs($googleFetcher, array('http://www.google.com/search?q=bar'));
     $googleFetcher->disableCaching();
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=foo"));
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=bar"));
     $this->assertTrue($googleFetcher->enableCaching());
     $this->assertTrue($googleFetcher->enableCachingForever());
     $this->assertTrue($googleFetcher->cacheHit("http://www.google.com/search?q=foo"));
     $this->assertTrue($googleFetcher->cacheHit("http://www.google.com/search?q=bar"));
     $this->assertTrue($googleFetcher->setCacheDir('baz'));
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=baz"));
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=foobar"));
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=bar"));
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=foo"));
     $fetchedContent = $fetchSerpContent->invokeArgs($googleFetcher, array('http://www.google.com/search?q=baz'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($googleFetcher->cacheHit("http://www.google.com/search?q=baz"));
     $SHDObject = $getSHDWrapper->invokeArgs($googleFetcher, array('http://www.google.com/search?q=baz'));
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=foobar"));
     $fetchedContent = $fetchSerpContent->invokeArgs($googleFetcher, array('http://www.google.com/search?q=foobar'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($googleFetcher->cacheHit("http://www.google.com/search?q=foobar"));
     $SHDObject = $getSHDWrapper->invokeArgs($googleFetcher, array('http://www.google.com/search?q=foobar'));
     $this->assertTrue($googleFetcher->setCacheDir('cache'));
     $this->assertTrue($googleFetcher->cacheHit('http://www.google.com/search?q=foo'));
     $this->assertTrue($googleFetcher->cacheHit('http://www.google.com/search?q=bar'));
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=baz"));
     $this->assertFalse($googleFetcher->cacheHit("http://www.google.com/search?q=foobar"));
     $this->assertTrue($googleFetcher->setCacheDir('baz'));
     $this->assertFalse($googleFetcher->cacheHit('http://www.google.com/search?q=foo'));
     $this->assertFalse($googleFetcher->cacheHit('http://www.google.com/search?q=bar'));
     $this->assertTrue($googleFetcher->cacheHit("http://www.google.com/search?q=baz"));
     $this->assertTrue($googleFetcher->cacheHit("http://www.google.com/search?q=foobar"));
     $askFetcher = Builder::create($this->engines[1], array('bar' . DIRECTORY_SEPARATOR . 'foo', 1, false));
     $fetchSerpContent = TestHelper::getMethod('fetchSerpContent', 'Ask');
     $getSHDWrapper = TestHelper::getMethod('getSHDWrapper', 'Ask');
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=foo"));
     $fetchedContent = $fetchSerpContent->invokeArgs($askFetcher, array('http://us.ask.com/web?q=foo'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=foo"));
     $this->assertTrue($askFetcher->enableCaching());
     $SHDObject = $getSHDWrapper->invokeArgs($askFetcher, array('http://us.ask.com/web?q=foo'));
     $this->assertTrue($askFetcher->cacheHit("http://us.ask.com/web?q=foo"));
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=bar"));
     $fetchedContent = $fetchSerpContent->invokeArgs($askFetcher, array('http://us.ask.com/web?q=bar'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($askFetcher->cacheHit("http://us.ask.com/web?q=bar"));
     $SHDObject = $getSHDWrapper->invokeArgs($askFetcher, array('http://us.ask.com/web?q=bar'));
     $askFetcher->disableCaching();
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=foo"));
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=bar"));
     $this->assertTrue($askFetcher->enableCaching());
     $this->assertTrue($askFetcher->enableCachingForever());
     $this->assertTrue($askFetcher->cacheHit("http://us.ask.com/web?q=foo"));
     $this->assertTrue($askFetcher->cacheHit("http://us.ask.com/web?q=bar"));
     $this->assertTrue($askFetcher->setCacheDir('barfoo'));
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=foo"));
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=bar"));
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=foobar"));
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=baz"));
     $fetchedContent = $fetchSerpContent->invokeArgs($askFetcher, array('http://us.ask.com/web?q=baz'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($askFetcher->cacheHit("http://us.ask.com/web?q=baz"));
     $SHDObject = $getSHDWrapper->invokeArgs($askFetcher, array('http://us.ask.com/web?q=baz'));
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=foobar"));
     $fetchedContent = $fetchSerpContent->invokeArgs($askFetcher, array('http://us.ask.com/web?q=foobar'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($askFetcher->cacheHit("http://us.ask.com/web?q=foobar"));
     $SHDObject = $getSHDWrapper->invokeArgs($askFetcher, array('http://us.ask.com/web?q=foobar'));
     $this->assertTrue($askFetcher->setCacheDir('bar' . DIRECTORY_SEPARATOR . 'foo'));
     $this->assertTrue($askFetcher->cacheHit('http://us.ask.com/web?q=foo'));
     $this->assertTrue($askFetcher->cacheHit('http://us.ask.com/web?q=bar'));
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=baz"));
     $this->assertFalse($askFetcher->cacheHit("http://us.ask.com/web?q=foobar"));
     $this->assertTrue($askFetcher->setCacheDir('barfoo'));
     $this->assertFalse($askFetcher->cacheHit('http://us.ask.com/web?q=foo'));
     $this->assertFalse($askFetcher->cacheHit('http://us.ask.com/web?q=bar'));
     $this->assertTrue($askFetcher->cacheHit("http://us.ask.com/web?q=baz"));
     $this->assertTrue($askFetcher->cacheHit("http://us.ask.com/web?q=foobar"));
     $bingFetcher = Builder::create($this->engines[2], array('foobar', 48, true, true, 'UTF-16'));
     $fetchSerpContent = TestHelper::getMethod('fetchSerpContent', 'Bing');
     $getSHDWrapper = TestHelper::getMethod('getSHDWrapper', 'Bing');
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=foo"));
     $fetchedContent = $fetchSerpContent->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=foo'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($bingFetcher->cacheHit("http://www.bing.com/search?q=foo"));
     $SHDObject = $getSHDWrapper->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=foo'));
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=bar"));
     $fetchedContent = $fetchSerpContent->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=bar'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($bingFetcher->cacheHit("http://www.bing.com/search?q=bar"));
     $SHDObject = $getSHDWrapper->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=bar'));
     $bingFetcher->disableCaching();
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=foo"));
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=bar"));
     $this->assertTrue($bingFetcher->enableCaching());
     $this->assertTrue($bingFetcher->enableCachingForever());
     $this->assertTrue($bingFetcher->cacheHit("http://www.bing.com/search?q=foo"));
     $this->assertTrue($bingFetcher->cacheHit("http://www.bing.com/search?q=bar"));
     $this->assertTrue($bingFetcher->setCacheDir('barz'));
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=baz"));
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=foobar"));
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=bar"));
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=foo"));
     $fetchedContent = $fetchSerpContent->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=baz'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($bingFetcher->cacheHit("http://www.bing.com/search?q=baz"));
     $SHDObject = $getSHDWrapper->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=baz'));
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=foobar"));
     $fetchedContent = $fetchSerpContent->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=foobar'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($bingFetcher->cacheHit("http://www.bing.com/search?q=foobar"));
     $SHDObject = $getSHDWrapper->invokeArgs($bingFetcher, array('http://www.bing.com/search?q=foobar'));
     $this->assertTrue($bingFetcher->setCacheDir('foobar'));
     $this->assertTrue($bingFetcher->cacheHit('http://www.bing.com/search?q=foo'));
     $this->assertTrue($bingFetcher->cacheHit('http://www.bing.com/search?q=bar'));
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=baz"));
     $this->assertFalse($bingFetcher->cacheHit("http://www.bing.com/search?q=foobar"));
     $this->assertTrue($bingFetcher->setCacheDir('barz'));
     $this->assertFalse($bingFetcher->cacheHit('http://www.bing.com/search?q=foo'));
     $this->assertFalse($bingFetcher->cacheHit('http://www.bing.com/search?q=bar'));
     $this->assertTrue($bingFetcher->cacheHit("http://www.bing.com/search?q=baz"));
     $this->assertTrue($bingFetcher->cacheHit("http://www.bing.com/search?q=foobar"));
     $yahooFetcher = Builder::create($this->engines[3], array('fubar', 48, true, true, 'UTF-16'));
     $fetchSerpContent = TestHelper::getMethod('fetchSerpContent', 'Yahoo');
     $getSHDWrapper = TestHelper::getMethod('getSHDWrapper', 'Yahoo');
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foo"));
     $fetchedContent = $fetchSerpContent->invokeArgs($yahooFetcher, array('https://search.yahoo.com/search?q=foo'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foo"));
     $SHDObject = $getSHDWrapper->invokeArgs($yahooFetcher, array('https://search.yahoo.com/search?q=foo'));
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=bar"));
     $fetchedContent = $fetchSerpContent->invokeArgs($yahooFetcher, array('https://search.yahoo.com/search?q=bar'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=bar"));
     $SHDObject = $getSHDWrapper->invokeArgs($yahooFetcher, array('https://search.yahoo.com/search?q=bar'));
     $yahooFetcher->disableCaching();
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foo"));
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=bar"));
     $this->assertTrue($yahooFetcher->enableCaching());
     $this->assertTrue($yahooFetcher->enableCachingForever());
     $this->assertTrue($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foo"));
     $this->assertTrue($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=bar"));
     $this->assertTrue($yahooFetcher->setCacheDir('fubarz'));
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=baz"));
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foobar"));
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=bar"));
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foo"));
     $fetchedContent = $fetchSerpContent->invokeArgs($yahooFetcher, array('https://search.yahoo.com/search?q=baz'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=baz"));
     $SHDObject = $getSHDWrapper->invokeArgs($yahooFetcher, array('https://search.yahoo.com/search?q=baz'));
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foobar"));
     $fetchedContent = $fetchSerpContent->invokeArgs($yahooFetcher, array('https://search.yahoo.com/search?q=foobar'));
     $this->assertRegExp('/^<!doctype html/i', $fetchedContent);
     $this->assertTrue($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foobar"));
     $SHDObject = $getSHDWrapper->invokeArgs($yahooFetcher, array('https://search.yahoo.com/search?q=foobar'));
     $this->assertTrue($yahooFetcher->setCacheDir('fubar'));
     $this->assertTrue($yahooFetcher->cacheHit('https://search.yahoo.com/search?q=foo'));
     $this->assertTrue($yahooFetcher->cacheHit('https://search.yahoo.com/search?q=bar'));
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=baz"));
     $this->assertFalse($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foobar"));
     $this->assertTrue($yahooFetcher->setCacheDir('fubarz'));
     $this->assertFalse($yahooFetcher->cacheHit('https://search.yahoo.com/search?q=foo'));
     $this->assertFalse($yahooFetcher->cacheHit('https://search.yahoo.com/search?q=bar'));
     $this->assertTrue($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=baz"));
     $this->assertTrue($yahooFetcher->cacheHit("https://search.yahoo.com/search?q=foobar"));
 }
 protected function tearDown()
 {
     TestHelper::cleanMess();
 }