public function testGetRandId() { CM_Db_Db::insert('test', array('foo', 'bar'), array(array('foo1', 'bar1'), array('foo2', 'bar2'), array('foo3', 'bar3'))); $id = CM_Db_Db::getRandId('test', 'id'); $this->assertGreaterThanOrEqual(1, $id); $id = CM_Db_Db::getRandId('test', 'id', '`id` = 2'); $this->assertEquals(2, $id); }
public function testFindByIp() { $cityId1 = CM_Db_Db::getRandId('cm_model_location_city', 'id'); CM_Db_Db::insert('cm_model_location_ip', array('id' => $cityId1, 'level' => CM_Model_Location::LEVEL_CITY, 'ipStart' => 1, 'ipEnd' => 5)); $cityId2 = CM_Db_Db::getRandId('cm_model_location_city', 'id'); CM_Db_Db::insert('cm_model_location_ip', array('id' => $cityId2, 'level' => CM_Model_Location::LEVEL_CITY, 'ipStart' => 123456789, 'ipEnd' => 223456789)); $countryId1 = CM_Db_Db::getRandId('cm_model_location_country', 'id'); CM_Db_Db::insert('cm_model_location_ip', array('id' => $countryId1, 'level' => CM_Model_Location::LEVEL_COUNTRY, 'ipStart' => 10, 'ipEnd' => 15)); $countryId2 = CM_Db_Db::getRandId('cm_model_location_country', 'id'); CM_Db_Db::insert('cm_model_location_ip', array('id' => $countryId2, 'level' => CM_Model_Location::LEVEL_COUNTRY, 'ipStart' => 1234567890, 'ipEnd' => 2234567890)); $this->assertEquals(new CM_Model_Location(CM_Model_Location::LEVEL_CITY, $cityId1), CM_Model_Location::findByIp(3)); $this->assertNull(CM_Model_Location::findByIp(6)); $this->assertEquals(new CM_Model_Location(CM_Model_Location::LEVEL_CITY, $cityId2), CM_Model_Location::findByIp(223456700)); $this->assertNull(CM_Model_Location::findByIp(223456800)); $this->assertEquals(new CM_Model_Location(CM_Model_Location::LEVEL_COUNTRY, $countryId1), CM_Model_Location::findByIp(12)); $this->assertNull(CM_Model_Location::findByIp(16)); $this->assertEquals(new CM_Model_Location(CM_Model_Location::LEVEL_COUNTRY, $countryId2), CM_Model_Location::findByIp(2234567870)); $this->assertNull(CM_Model_Location::findByIp(2234567900)); }