Exemplo n.º 1
0
 protected function getConfig()
 {
     if (!isset($this->_config)) {
         $this->_config = array();
         // Load the config
         foreach ($this->value as $config) {
             $datatable_config_dir = \Clips\clips_config('pagination_config_dir');
             if ($datatable_config_dir) {
                 $datatable_config_dir = $datatable_config_dir[0];
                 $p = \Clips\path_join($datatable_config_dir, $config . '.json');
                 if (file_exists($p)) {
                     $this->_config[$config] = \Clips\parse_json(file_get_contents($p));
                 }
             }
         }
     }
     return $this->_config;
 }
Exemplo n.º 2
0
    public function testValidate()
    {
        $arr = array('password' => 'password', 'remember_me' => true, 'age' => -1);
        $json = <<<TEXT
[
        {
                "field": "username",
                "rules": [
\t\t\t\t\t"required"
\t\t\t\t],
\t\t\t\t"messages": {
\t\t\t\t\t"required": "This username field must be set!"
\t\t\t\t}
        },
        {
                "field": "age",
                "rules": [
\t\t\t\t\t{
\t\t\t\t\t\t"type": "number",
\t\t\t\t\t\t"min": 20,
\t\t\t\t\t\t"max": 40
\t\t\t\t\t},
\t\t\t\t\t"required"
\t\t\t\t],
\t\t\t\t"messages": {
\t\t\t\t\t"required": "This age field must be set!"
\t\t\t\t}
        },
        {
                "field": "password",
                "rules": [
\t\t\t\t\t"required"
\t\t\t\t],
\t\t\t\t"messages": {
\t\t\t\t\t"required": "This password field must be set"
\t\t\t\t}
        },
        {
                "field": "regex",
\t\t\t\t"rules": {
\t\t\t\t\t"regex": "^abc.*z\$"
\t\t\t\t}
        },
        {
                "field": "remember_me"
        }
]
TEXT;
        $errors = $this->validator->validate($arr, Clips\parse_json($json));
        var_dump($errors);
        $this->assertEquals(count($errors), 2);
        $arr['age'] = 100;
        $errors = $this->validator->validate($arr, Clips\parse_json($json));
        $this->assertEquals(count($errors), 2);
        $arr['age'] = 'test';
        $errors = $this->validator->validate($arr, Clips\parse_json($json));
        $this->assertEquals(count($errors), 2);
        $arr['regex'] = 'az';
        $errors = $this->validator->validate($arr, Clips\parse_json($json));
        $this->assertEquals(count($errors), 3);
        $arr['regex'] = 'abcdefgz';
        $errors = $this->validator->validate($arr, Clips\parse_json($json));
        $this->assertEquals(count($errors), 2);
    }