public function testHitChecker() { $googleScraper = Builder::create($this->engines[0], array(array('foo', 'baz'))); $mapKeywordsToUrls = TestHelper::getMethod('mapKeywordsToUrls', 'Google'); $hitCounter = TestHelper::getMethod('hitCounter', 'Google'); $hitChecker = TestHelper::getMethod('hitChecker', 'Google'); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($googleScraper, array(1, $googleScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($googleScraper, array($urlsToScrape)); $this->assertTrue($hitChecker->invokeArgs($googleScraper, array($globalHitCount, $componentHitCount))); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($googleScraper, array(7, $googleScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($googleScraper, array($urlsToScrape)); $this->assertTrue($hitChecker->invokeArgs($googleScraper, array($globalHitCount, $componentHitCount))); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($googleScraper, array(8, $googleScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($googleScraper, array($urlsToScrape)); $this->assertFalse($hitChecker->invokeArgs($googleScraper, array($globalHitCount, $componentHitCount))); $googleScraper->getThrottler()->stop(); $this->assertTrue($googleScraper->getThrottler()->setComponentThreshold(3)); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($googleScraper, array(3, $googleScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($googleScraper, array($urlsToScrape)); $this->assertTrue($hitChecker->invokeArgs($googleScraper, array($globalHitCount, $componentHitCount))); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($googleScraper, array(4, $googleScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($googleScraper, array($urlsToScrape)); $this->assertFalse($hitChecker->invokeArgs($googleScraper, array($globalHitCount, $componentHitCount))); $askScraper = Builder::create($this->engines[1], array(array('foo', 'baz', 'foobaz'))); $mapKeywordsToUrls = TestHelper::getMethod('mapKeywordsToUrls', 'Ask'); $hitCounter = TestHelper::getMethod('hitCounter', 'Ask'); $hitChecker = TestHelper::getMethod('hitChecker', 'Ask'); $askScraper->getThrottler()->stop(); $this->assertTrue($askScraper->getThrottler()->setGlobalThreshold(100)); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($askScraper, array(30, $askScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($askScraper, array($urlsToScrape)); $this->assertTrue($hitChecker->invokeArgs($askScraper, array($globalHitCount, $componentHitCount))); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($askScraper, array(40, $askScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($askScraper, array($urlsToScrape)); $this->assertFalse($hitChecker->invokeArgs($askScraper, array($globalHitCount, $componentHitCount))); $this->assertTrue($askScraper->getThrottler()->setComponentThreshold(20)); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($askScraper, array(15, $askScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($askScraper, array($urlsToScrape)); $this->assertTrue($hitChecker->invokeArgs($askScraper, array($globalHitCount, $componentHitCount))); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($askScraper, array(21, $askScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($askScraper, array($urlsToScrape)); $this->assertFalse($hitChecker->invokeArgs($askScraper, array($globalHitCount, $componentHitCount))); $bingScraper = Builder::create($this->engines[2], array(array('foo', 'baz', 'foobaz'))); $mapKeywordsToUrls = TestHelper::getMethod('mapKeywordsToUrls', 'Bing'); $hitCounter = TestHelper::getMethod('hitCounter', 'Bing'); $hitChecker = TestHelper::getMethod('hitChecker', 'Bing'); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($bingScraper, array(4, $bingScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($bingScraper, array($urlsToScrape)); $this->assertTrue($hitChecker->invokeArgs($bingScraper, array($globalHitCount, $componentHitCount))); $urlsToScrape = $mapKeywordsToUrls->invokeArgs($bingScraper, array(5, $bingScraper->getKeywords())); list($globalHitCount, $componentHitCount) = $hitCounter->invokeArgs($bingScraper, array($urlsToScrape)); $this->assertFalse($hitChecker->invokeArgs($bingScraper, array($globalHitCount, $componentHitCount))); }
protected function tearDown() { TestHelper::cleanMess(); }