public function testGetOrCreate() { $_SERVER['HTTP_USER_AGENT'] = fake_uagent(); $device = $this->device_model->getOrCreate($this->test_data->the_gateway->serial, $this->test_data->the_user->id, $this->test_data->the_device->mac); $this->assertEquals($device->id, $this->test_data->the_device->id); $device = $this->device_model->getOrCreate($this->test_data->the_gateway->serial, $this->test_data->the_user->id, fake_mac()); $this->assertNotEquals($device->id, $this->test_data->the_device->id); print_r($this->device_model->load($device->id)); }
public function testAdd() { $ret = $this->loginrequest_model->add(array('serial' => 'not exists', 'mac' => $this->test_data->the_device->mac)); $this->assertEquals($ret, -1); $the_request_id = $this->loginrequest_model->add(array('serial' => $this->test_data->the_gateway->serial, 'mac' => $this->test_data->the_device->mac)); $the_request = $this->loginrequest_model->load($the_request_id); $this->assertEquals($the_request->device_id, $this->test_data->the_device->id); $the_request_id = $this->loginrequest_model->add(array('serial' => $this->test_data->the_gateway->serial, 'mac' => fake_mac())); $the_request = $this->loginrequest_model->load($the_request_id); $this->assertNotEquals($the_request->device_id, $this->test_data->the_device->id); }
function fake_gateway($owner_id, $name = null, $id = 1000, $serial = null) { $CI =& get_instance(); $CI->load->library('uuid'); $the_serial = $serial ? $serial : $CI->uuid->get(); $the_name = $name ? $name : 'Gateway[' . $id . ']'; return (object) array('id' => $id, 'owner_id' => $owner_id, 'name' => $the_name, 'serial' => $the_serial, 'mac' => fake_mac(), 'ip' => ip2long(fake_ip())); }