public function testAfterReg() { $this->CI = set_controller('ajax/register'); //全局变量 侵入 $data_success_with_invite = array('phone' => '18810556559', 'password' => '123456', 'smsCode' => '123456', 'verifycode' => '1234', 'invite_uid' => '2'); //全局变量 侵入 foreach ($data_success_with_invite as $key => $value) { $_GET[$key] = $value; } // 图片验证码 1234 $this->CI->session->set_userdata('auth_code', $this->authcode); // 短信验证码 123456 $this->CI->session->set_userdata('smsCode', $this->smscode); // 引入 safe_md5(),用于校验 cookie 中的md5 $this->CI->load->helper('string'); $_COOKIE['phone_send'] = safe_md5($data_success_with_invite['phone']); // init $this->CI->ajax->warnings = array(); $this->CI->ajax->errors = array(); $this->CI->ajax->successes = array(); // ob 忽略输出 // ob_start(); $this->CI->do_reg(); ob_end_clean(); $status = $this->CI->ajax->status_code; $mes = ''; $this->assertEquals(200, $status); }
public function testMd5() { $text = 123; $md5 = md5($text . '-www.guangxindai.com-guangxin-md5-key' . date('Ymd')); $help_text = safe_md5($text); $this->assertEquals($help_text, $md5); }
/** * @dataProvider regFormProvider */ public function testRegWithOutLogin($input_data, $expect_status, $mes_key, $expect_message) { // ob 忽略输出 // ob_start(); $this->CI = set_controller('ajax/register'); // ob_end_clean(); $this->CI->session->set_userdata('LOGINuser_id', ''); //全局变量 侵入 foreach ($input_data as $key => $value) { $_GET[$key] = $value; } // 图片验证码 1234 $this->CI->session->set_userdata('auth_code', $this->authcode); // 短信验证码 123456 $this->CI->session->set_userdata('smsCode', $this->smscode); // 引入 safe_md5(),用于校验 cookie 中的md5 $this->CI->load->helper('string'); $_COOKIE['phone_send'] = safe_md5($input_data['phone']); // init $this->CI->ajax->warnings = array(); $this->CI->ajax->errors = array(); $this->CI->ajax->successes = array(); // ob 忽略输出 // ob_start(); $this->CI->do_reg(); // ob_end_clean(); $status = $this->CI->ajax->status_code; $mes = ''; if (count($this->CI->ajax->errors) != 0) { $mes = $this->CI->ajax->errors[$mes_key]; } if (count($this->CI->ajax->successes) != 0) { $mes = $this->CI->ajax->successes[$mes_key]; } // 断言 $this->assertEquals($expect_status, $status); $this->assertEquals($expect_message, $mes); }