/**
  * Tests MyValidator->mobile()
  */
 public function testMobile()
 {
     //该单元测试用例采用等价类的方式测试,黑盒测试
     //划分依据  正常 (电信 移动 联通)号码 , 加地址位置正常号码, 非地理位置正常号码,  非号码但是11位数字, 非11位数字
     // 非号码11位数字+地理位置号, 非地理位置非号码11位数字,非11位数字非地理位置,
     // 字符, 字符数字混合, 数字空格混合
     // unit1 正常-电信
     $this->MyValidator->setValue("13312341234");
     $this->assertEquals(1, $this->MyValidator->mobile());
     // unit2 正常-移动
     $this->MyValidator->setValue("15112341234");
     $this->assertEquals(1, $this->MyValidator->mobile());
     // unit3 正常-联通
     $this->MyValidator->setValue("13212341234");
     $this->assertEquals(1, $this->MyValidator->mobile());
     // unit4 +地理位置
     $this->MyValidator->setValue("8613212341234");
     $this->assertEquals(1, $this->MyValidator->mobile());
     // unit4.1 +地理位置
     $this->MyValidator->setValue("86+13212341234");
     $this->assertEquals(1, $this->MyValidator->mobile());
     // unit5 +非地理位置
     $this->MyValidator->setValue("86113212341234");
     $this->assertEquals(0, $this->MyValidator->mobile());
     // unit6 + 非号码但是11位
     $this->MyValidator->setValue("11111111111");
     $this->assertEquals(0, $this->MyValidator->mobile());
     // unit7 + 非11位
     $this->MyValidator->setValue("1331255273");
     $this->assertEquals(0, $this->MyValidator->mobile());
     // unit8 + 非号码但是11位+地理位置
     $this->MyValidator->setValue("8611111111111");
     $this->assertEquals(0, $this->MyValidator->mobile());
     // unit9 + 非号码非地理位置
     $this->MyValidator->setValue("8511111111111");
     $this->assertEquals(0, $this->MyValidator->mobile());
     // unit10 + 非11位非地理位置
     $this->MyValidator->setValue("851111111");
     $this->assertEquals(0, $this->MyValidator->mobile());
     // unit11 + 字符
     $this->MyValidator->setValue("asdfghjkutr");
     $this->assertEquals(0, $this->MyValidator->mobile());
     // unit12 + 字符数字
     $this->MyValidator->setValue("151fghjkutr");
     $this->assertEquals(0, $this->MyValidator->mobile());
     // unit13 + 数字空格
     $this->MyValidator->setValue("1518731 035");
     $this->assertEquals(0, $this->MyValidator->mobile());
 }
Beispiel #2
0
function valdate($arr)
{
    $object = new MyValidator();
    $result = "";
    // email
    if ($arr["email"] == null || $arr["email"] == "") {
        $result["status"] = false;
        $result["email"] = "没有填写";
        return $result;
    } else {
        $object->setEmail($arr["email"]);
        if ($object->email()) {
            $result["email"] = "正确";
        } else {
            $result["status"] = false;
            $result["email"] = "邮件格式错误";
            return $result;
        }
    }
    // mobile 手机
    if ($arr["mobile"] == null || $arr["mobile"] == "") {
        $result["status"] = false;
        $result["mobile"] = "没有填写";
        return $result;
    } else {
        $object->setMobile($arr["mobile"]);
        if ($object->mobile()) {
            $result["mobile"] = "正确";
        } else {
            $result["status"] = false;
            $result["mobile"] = "手机格式错误";
            return $result;
        }
    }
    // tel 座机
    if ($arr["tel"] == null || $arr["tel"] == "") {
        $result["status"] = false;
        $result["tel"] = "没有填写";
        return $result;
    } else {
        $object->setTel($arr["tel"]);
        if ($object->telephone()) {
            $result["tel"] = "正确";
        } else {
            $result["status"] = false;
            $result["tel"] = "座机格式错误";
            return $result;
        }
    }
    // number
    if ($arr["number"] == null || $arr["number"] == "") {
        $result["status"] = false;
        $result["number"] = "没有填写";
        return $result;
    } else {
        $object->setNumber($arr["number"]);
        if ($object->number()) {
            $result["number"] = "正确";
        } else {
            $result["status"] = false;
            $result["number"] = "数字格式错误";
            return $result;
        }
    }
    $result["status"] = true;
    return $result;
}