当前位置: 首页>>代码示例>>PHP>>正文


PHP Jam::validator_rule方法代码示例

本文整理汇总了PHP中Jam::validator_rule方法的典型用法代码示例。如果您正苦于以下问题:PHP Jam::validator_rule方法的具体用法?PHP Jam::validator_rule怎么用?PHP Jam::validator_rule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jam的用法示例。


在下文中一共展示了Jam::validator_rule方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_valid_promo_code

 /**
  * @covers Jam_Validator_Rule_Purchase_Promocode::valid_promo_code
  */
 public function test_valid_promo_code()
 {
     $purchase = Jam::find('purchase', 1);
     $promo_code1 = Jam::find('promo_code', 1);
     $purchase->update_fields(array('promo_code_id' => $promo_code1->get('id')));
     $promo_code2 = Jam::find('promo_code', 2);
     $promo_code3 = Jam::find('promo_code', 3);
     $validator_rule = Jam::validator_rule('purchase_promocode');
     // Invalid code
     $result = $validator_rule->valid_promo_code('asd', $purchase);
     $this->assertNull($result);
     // Already used promocode
     $result = $validator_rule->valid_promo_code($promo_code1->get('code'), $purchase);
     $this->assertEquals($promo_code1, $result);
     // Available promocode
     $result = $validator_rule->valid_promo_code($promo_code2->get('code'), $purchase);
     $this->assertEquals($promo_code2, $result);
     // Check already used promocode
     Jam::find('purchase', 2)->set('promo_code', $promo_code2)->save();
     $result = $validator_rule->valid_promo_code($promo_code2->get('code'), $purchase);
     $this->assertNull($result, 'Already used promocode');
     // Check already used allow_multiple
     Jam::find('purchase', 2)->set('promo_code', $promo_code3)->save();
     $result = $validator_rule->valid_promo_code($promo_code3->get('code'), $purchase);
     $this->assertEquals($promo_code3, $result, 'Should match because its an allow_multiple=TRUE promocode');
 }
开发者ID:openbuildings,项目名称:promotions,代码行数:29,代码来源:PromocodeTest.php

示例2: test_validate

 /**
  * @dataProvider data_validate
  */
 public function test_validate($value, $options, $error, $is_valid)
 {
     $element = Jam::build('test_element');
     Jam::validator_rule('count', $options)->validate($element, 'count', $value);
     if ($is_valid) {
         $this->assertNotHasError($element, 'count', $error);
     } else {
         $this->assertHasError($element, 'count', $error);
     }
 }
开发者ID:Konro1,项目名称:pms,代码行数:13,代码来源:CountTest.php

示例3: test_validate

 /**
  * @dataProvider data_validate
  */
 public function test_validate($value, $accept, $is_valid)
 {
     $element = Jam::build('test_element');
     Jam::validator_rule('accepted', array('accept' => $accept))->validate($element, 'name', $value);
     if ($is_valid) {
         $this->assertNotHasError($element, 'name', 'accepted');
     } else {
         $this->assertHasError($element, 'name', 'accepted');
     }
 }
开发者ID:Konro1,项目名称:pms,代码行数:13,代码来源:AcceptedTest.php

示例4: test_validate

 public function test_validate()
 {
     $element = Jam::find('test_element', 1);
     Jam::validator_rule('unique', array())->validate($element, 'name', $element->name);
     $this->assertNotHasError($element, 'name', 'unique');
     $element2 = Jam::find('test_element', 2);
     Jam::validator_rule('unique', array())->validate($element2, 'url', $element2->url);
     $this->assertHasError($element2, 'url', 'unique');
     $element3 = Jam::find('test_element', 2);
     Jam::validator_rule('unique', array('scope' => 'name'))->validate($element3, 'url', $element3->url);
     $this->assertNotHasError($element3, 'url', 'unique');
 }
开发者ID:Konro1,项目名称:pms,代码行数:12,代码来源:UniqueTest.php

示例5: test_validate

 /**
  * @dataProvider data_validate
  */
 public function test_validate($value, $options, $error, $expected_attributes, $is_valid)
 {
     $element = Jam::build('test_element');
     $validator_rule = Jam::validator_rule('format', $options);
     $this->assertEquals($expected_attributes, $validator_rule->html5_validation());
     $validator_rule->validate($element, 'name', $value);
     if ($is_valid) {
         $this->assertNotHasError($element, 'name', $error);
     } else {
         $this->assertHasError($element, 'name', $error);
     }
 }
开发者ID:Konro1,项目名称:pms,代码行数:15,代码来源:FormatTest.php

示例6: test_validate

 /**
  * @dataProvider data_validate
  */
 public function test_validate($value, $allow_zero, $is_valid)
 {
     $element = Jam::build('test_element');
     $validator_rule = Jam::validator_rule('present');
     $validator_rule->allow_zero = $allow_zero;
     $this->assertEquals(array('required' => TRUE), $validator_rule->html5_validation());
     $validator_rule->validate($element, 'url', $value);
     if ($is_valid) {
         $this->assertNotHasError($element, 'url', 'present');
     } else {
         $this->assertHasError($element, 'url', 'present');
     }
 }
开发者ID:openbuildings,项目名称:jam,代码行数:16,代码来源:PresentTest.php

示例7: test_validate

 public function test_validate()
 {
     $element1 = Jam::build('test_element')->load_fields(array('id' => 1, 'name' => 'Part 1'));
     Jam::validator_rule('confirmed', array())->validate($element1, 'name', $element1->name);
     $this->assertNotHasError($element1, 'name', 'confirmed');
     $element2 = Jam::build('test_element')->load_fields(array('id' => 2, 'name' => 'Part 2'));
     $element2->name_confirmation = 'test';
     Jam::validator_rule('confirmed', array())->validate($element2, 'name', $element2->name);
     $this->assertHasError($element2, 'name', 'confirmed');
     $element3 = Jam::build('test_element')->load_fields(array('id' => 2, 'name' => 'Part 2'));
     $element3->name_confirmation = $element3->name;
     Jam::validator_rule('confirmed', array())->validate($element3, 'name', $element3->name);
     $this->assertNotHasError($element3, 'name', 'confirmed');
 }
开发者ID:Konro1,项目名称:pms,代码行数:14,代码来源:ConfirmedTest.php

示例8: test_validate

 /**
  * @dataProvider data_validate
  */
 public function test_validate($value, $options, $errors, $is_valid)
 {
     $element = Jam::build('test_element');
     $validator_rule = Jam::validator_rule('range', $options);
     $validator_rule->validate($element, 'name', new Jam_Range($value));
     if ($is_valid) {
         foreach ((array) $errors as $error) {
             $this->assertNotHasError($element, 'name', $error);
         }
     } else {
         foreach ((array) $errors as $error) {
             $this->assertHasError($element, 'name', $error);
         }
     }
 }
开发者ID:openbuildings,项目名称:jam,代码行数:18,代码来源:RangeTest.php

示例9: __construct

 function __construct(array $attributes, array $options)
 {
     $this->attributes = $attributes;
     if (isset($options['if'])) {
         $this->condition = $options['if'];
         unset($options['if']);
     }
     if (isset($options['unless'])) {
         $this->condition = $options['unless'];
         $this->condition_negative = TRUE;
         unset($options['unless']);
     }
     foreach ($options as $rule => $params) {
         $this->rules[] = $params instanceof Jam_Validator_Rule ? $params : Jam::validator_rule($rule, $params);
     }
 }
开发者ID:Konro1,项目名称:pms,代码行数:16,代码来源:Validator.php

示例10: data_constructor

 public function data_constructor()
 {
     return array(array(array(), array(), array(), NULL, FALSE, array()), array(array('abc'), array(), array('abc'), NULL, FALSE, array()), array(array('abc'), array('present' => TRUE), array('abc'), NULL, FALSE, array(Jam::validator_rule('present'))), array(array('abc'), array('if' => 'abc'), array('abc'), 'abc', FALSE, array()), array(array('abc'), array('unless' => 'abc'), array('abc'), 'abc', TRUE, array()), array(array('abc'), array('unless' => 'abc', 'present' => TRUE, 'format' => array('email' => TRUE)), array('abc'), 'abc', TRUE, array(Jam::validator_rule('present'), Jam::validator_rule('format', array('email' => TRUE)))), array(array('abc', 'qwe'), array('unless' => 'qwe', 'if' => 'abc', 'present' => TRUE, 'format' => array('email' => TRUE)), array('abc', 'qwe'), 'qwe', TRUE, array(Jam::validator_rule('present'), Jam::validator_rule('format', array('email' => TRUE)))), array(array('abc', 'qwe'), array('unless' => 'qwe', 'if' => 'abc', 'present' => TRUE, Jam::validator_rule('numeric', array('greater_than' => 5)), 'format' => array('email' => TRUE)), array('abc', 'qwe'), 'qwe', TRUE, array(Jam::validator_rule('present'), Jam::validator_rule('numeric', array('greater_than' => 5)), Jam::validator_rule('format', array('email' => TRUE)))));
 }
开发者ID:Konro1,项目名称:pms,代码行数:4,代码来源:ValidatorTest.php

示例11: test_multiple_rules

 public function test_multiple_rules()
 {
     // Logo is 127 x 34
     $this->value->source(Upload_Util::combine($this->test_local, 'source', 'logo.gif'))->save_to_temp();
     Jam::validator_rule('uploaded', array('only' => array('png'), 'maximum_size' => '1B', 'exact_height' => 20))->validate($this->model, 'file', $this->value);
     $this->assertHasError($this->model, 'file', 'uploaded_extension');
     $this->assertHasError($this->model, 'file', 'uploaded_maximum_size');
     $this->assertHasError($this->model, 'file', 'uploaded_exact_height');
 }
开发者ID:Konro1,项目名称:pms,代码行数:9,代码来源:UploadedTest.php


注:本文中的Jam::validator_rule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。