hit("2007-09-05 00:01:14", "59.115.201.73", "1","http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit); $this->assertTrue($res, "Failed : $res"); $res = fs_getentries(); $this->assertNull($res, "getentries failed"); $this->assertEquals(0, count($res[0])); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertFalse($res == false, "getentries failed"); $this->assertEquals(1, count($res)); $this->assertEquelsHits($hit, $res[0]); $this->assertUrlEquals(array("http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download")); $this->assertUseragentsEquals(array("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")); } function testDelayedInsert2() { $hit = $this->hit("2007-09-05 00:01:14", "59.115.201.73", "1","http://firestats.cc/wiki/InstallUpgrade","http:\888r.ru", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit); $this->assertTrue($res, "Failed : $res"); $res = fs_getentries(); $this->assertNull($res, "getentries failed"); $this->assertEquals(0, count($res[0])); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertFalse($res == false, "getentries failed"); $this->assertEquals(1, count($res)); $this->assertEquelsHits($hit, $res[0]); $this->assertUrlEquals(array("http://firestats.cc/wiki/InstallUpgrade","http:\888r.ru")); $this->assertUseragentsEquals(array("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")); } function testDelayedHit_ipExcluded() { require_once FS_ABS_PATH.'/php/db-sql.php'; fs_add_excluded_ip("59.115.201.73"); $hit = $this->hit("2007-09-05 00:01:14", "59.115.201.73", "1","http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertNull($res, "getentries failed"); fs_add_excluded_ip("59.115.100.10","59.115.100.100"); $hit = $this->hit("2007-09-05 00:01:14","59.115.100.10","1","http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download","Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertNull($res, "getentries failed"); fs_add_excluded_ip("59.115.100.10","59.115.100.100"); // gets in $hit1 = $this->hit("2007-09-05 00:01:14", "59.115.100.9", "1","http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download", "ua1"); // doesn't get in $hit2 = $this->hit("2007-09-05 00:01:14", "59.115.100.50", "1","http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download", "ua2"); // useragent is included because it appears in $hit1 // doesn't get in $hit3 = $this->hit("2007-09-05 00:01:14", "59.115.100.100", "1","http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download", "ua2"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit1); $this->assertTrue($res, "Failed : $res"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit2); $this->assertTrue($res, "Failed : $res"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit3); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertNotNull($res, "getentries failed"); $this->assertEquals(1, count($res)); $this->assertEquelsHits($hit1, $res[0]); $expected_urls = array("http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download"); $expected_useragents = array("ua1"); $this->assertUrlEquals($expected_urls); $this->assertUseragentsEquals($expected_useragents); } function testDelayedHit_urlExcluded() { require_once FS_ABS_PATH.'/php/db-sql.php'; fs_add_excluded_url("http://firestats.cc/wiki/InstallUpgrade"); $hit = $this->hit("2007-09-05 00:01:14", "59.115.201.73", "1","http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $this->assertUrlEquals(array()); $this->assertUseragentsEquals(array()); $this->assertNull(fs_getentries(), "getentries failed"); fs_add_excluded_ip("59.115.100.10","59.115.100.100"); // EXCLUDED $hit = $this->hit("2007-09-05 00:01:14", "59.115.100.10", "1","http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $this->assertUrlEquals(array()); $this->assertUseragentsEquals(array()); $this->assertNull(fs_getentries(), "getentries failed"); fs_add_excluded_url("google.com"); // get in $hit1 = $this->hit("2007-09-05 00:01:14", "59.115.100.9", "1","http://firestats.cc/wiki/","http://firestats.cc/wiki/Download", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); // doesn't get in $hit2 = $this->hit("2007-09-05 00:01:14", "59.115.100.50", "1","http://google.com/blah","http://firestats.cc/wiki/STAYOUT", "BOT BEGONE"); // doesn't get in $hit3 = $this->hit("2007-09-05 00:01:14", "59.115.100.100", "1","http://firestats.cc/wiki/InstallUpgrade","http://google.com/blah", "Stay away from my database"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit1); $this->assertTrue($res, "Failed : $res"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit2); $this->assertTrue($res, "Failed : $res"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit3); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertNotNull($res, "getentries failed"); $this->assertEquals(1, count($res)); $this->assertEquelsHits($hit1, $res[0]); $this->assertUrlEquals(array("http://firestats.cc/wiki/","http://firestats.cc/wiki/Download")); $this->assertUseragentsEquals(array("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")); } function testDelayedHit_useragentExcluded() { require_once FS_ABS_PATH.'/php/db-sql.php'; fs_add_bot("Googlebot"); $hit1 = $this->hit("2007-09-05 00:01:14", "59.115.201.73", "1","http://firestats.cc/wiki/InstallUpgrade","http://firestats.cc/wiki/Download", "Googlebot is here"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit1); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertNull($res, "getentries failed"); $this->assertUrlEquals(array()); $this->assertUseragentsEquals(array()); // get in $hit1 = $this->hit("2007-09-05 00:01:14", "59.115.100.9", "1","http://firestats.cc/wiki/","http://firestats.cc/wiki/Download", "Included useragent"); // doesn't get in $hit2 = $this->hit("2007-09-05 00:01:14", "59.115.100.50", "1","http://google.com/blah","http://firestats.cc/wiki/STAYOUT", "Googlebot BEGONE"); // doesn't get in $hit3 = $this->hit("2007-09-05 00:01:14", "59.115.100.100", "1","http://firestats.cc/wiki/InstallUpgrade","http://google.com/blah", "Googlebot Stay away from my database"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit1); $this->assertTrue($res, "Failed : $res"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit2); $this->assertTrue($res, "Failed : $res"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit3); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertNotNull($res, "getentries failed"); $this->assertEquals(1, count($res)); $this->assertEquelsHits($hit1, $res[0]); $this->assertUrlEquals(array("http://firestats.cc/wiki/","http://firestats.cc/wiki/Download")); $this->assertUseragentsEquals(array("Included useragent")); } /** * This tests the bug created by Escaping useragent strings, messing them up. */ function testDelayedHit_useragentExcluded2() { require_once FS_ABS_PATH.'/php/db-sql.php'; require_once FS_ABS_PATH.'/php/db-hit.php'; $fsdb = &fs_get_db_conn(); $bots = fs_bots_table(); $useragents = fs_useragents_table(); $res = $fsdb->query("truncate $bots"); $this->assertTrue($res !== false, "Failed : $res " . fs_db_error()); // gets in $hit1 = $this->hit("2007-09-05 00:01:14", "59.115.100.50", "1","http://google.com/blah","http://firestats.cc/wiki/STAYOUT", "Cabot/Nutch-0.9 (Amfibi\\\'s web-crawling robot; http://www.amfibi.com/cabot/; agent@amfibi.com)"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit1); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertNotNull($res, "getentries failed"); return; $res = fs_add_bot("Nutch"); $this->assertEquals("", $res, "Failed : $res"); // doesn't get in $hit1 = $this->hit("2007-09-05 00:01:16", "59.115.100.50", "1","http://google.com/blah","http://firestats.cc/wiki/STAYOUT", "Cabot/Nutch-0.9 (Amfibi\\\'s web-crawling robot; http://www.amfibi.com/cabot/; agent@amfibi.com)"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit1); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $res = fs_getentries(); $this->assertNull($res, "getentries failed"); $this->assertUrlEquals(array()); $this->assertUseragentsEquals(array("Cabot/Nutch-0.9 (Amfibi's web-crawling robot; http://www.amfibi.com/cabot/; agent@amfibi.com)")); } function testDelayedHit_rss() { $fsdb = &fs_get_db_conn(); $useragents = fs_useragents_table(); $hit = $this->hit(null, "59.115.201.73", "1", "http://firefang.net/blog/rss", "", "Netvibes (http://www.netvibes.com/; 80 subscribers; feedId: 316953)"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit, true); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $this->assertEquals(1, $fsdb->get_var("select count(*) from $useragents")); $res = fs_get_rss_subscribers(1); $this->assertEquals(80, $res); $hit = $this->hit(null, "59.115.201.73", "1", "http://firefang.net/blog/rss", "", "Netvibes (http://www.netvibes.com/; 100 subscribers; feedId: 316953)"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit, true); $this->assertTrue($res, "Failed : $res"); $hit = $this->hit(null, "59.115.201.73", "1", "http://firefang.net/blog/rss", "", "Netvibes (http://www.netvibes.com/; 1 subscribers; feedId: 316954)"); $res = $this->insertHit(FS_COMMIT_MANUAL, $hit, true); $this->assertTrue($res, "Failed : $res"); $this->fs_commit_flush_pending(); $this->assertEquals(1, (int)$fsdb->get_var("select count(*) from $useragents"), "invalid number of useragents"); $res = fs_get_rss_subscribers(1); $this->assertEquals(101, $res, "Failed : $res"); } } ?>