Development

Changeset 6945

You must first sign up to be able to contribute.

Changeset 6945

Show
Ignore:
Timestamp:
01/05/08 14:16:30 (9 months ago)
Author:
fabien
Message:

added code tests for all validators

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/validator/sfValidatorSchemaForEach.class.php

    r6196 r6945  
    1010 
    1111/** 
    12  *  
     12 * sfValidatorSchemaForEach wraps a validator multiple times in a single validator. 
    1313 * 
    1414 * @package    symfony 
  • branches/1.1/test/unit/validator/sfValidatorBooleanTest.php

    r5816 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(16, new lime_output_color()); 
     13$t = new lime_test(17, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorBoolean(); 
     
    3939  $v->clean('astring'); 
    4040  $t->fail('->clean() throws an error if the input value is not a true or a false value'); 
     41  $t->skip('', 1); 
    4142} 
    4243catch (sfValidatorError $e) 
    4344{ 
    4445  $t->pass('->clean() throws an error if the input value is not a true or a false value'); 
     46  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    4547} 
    4648 
  • branches/1.1/test/unit/validator/sfValidatorCSRFTokenTest.php

    r6197 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(4, new lime_output_color()); 
     13$t = new lime_test(5, new lime_output_color()); 
    1414 
    1515// __construct() 
     
    3535  $v->clean('another'); 
    3636  $t->fail('->clean() throws an sfValidatorError if the token is not valid'); 
     37  $t->skip('', 1); 
    3738} 
    3839catch (sfValidatorError $e) 
    3940{ 
    4041  $t->pass('->clean() throws an sfValidatorError if the token is not valid'); 
     42  $t->is($e->getCode(), 'csrf_attack', '->clean() throws a sfValidatorError'); 
    4143} 
    4244 
  • branches/1.1/test/unit/validator/sfValidatorCallbackTest.php

    r6197 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(5, new lime_output_color()); 
     13$t = new lime_test(6, new lime_output_color()); 
    1414 
    1515function clean_test($validator, $value) 
     
    4343{ 
    4444  $v->clean('bar'); 
    45   $t->fail('->clean() calls our validator callback'); 
     45  $t->fail('->clean() throws a sfValidatorError'); 
     46  $t->skip('', 1); 
    4647} 
    4748catch (sfValidatorError $e) 
    4849{ 
    49   $t->pass('->clean() calls our validator callback'); 
     50  $t->pass('->clean() throws a sfValidatorError'); 
     51  $t->is($e->getCode(), 'must_be_foo', '->clean() throws a sfValidatorError'); 
    5052} 
    5153 
  • branches/1.1/test/unit/validator/sfValidatorChoiceManyTest.php

    r5882 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(6, new lime_output_color()); 
     13$t = new lime_test(8, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorChoiceMany(array('choices' => array('foo', 'bar'))); 
     
    2525  $v->clean('foobar'); 
    2626  $t->fail('->clean() throws an sfValidatorError if the value is not an expected value'); 
     27  $t->skip('', 1); 
    2728} 
    2829catch (sfValidatorError $e) 
    2930{ 
    3031  $t->pass('->clean() throws an sfValidatorError if the value is not an expected value'); 
     32  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    3133} 
    3234 
     
    3537  $v->clean(array('foobar', 'bar')); 
    3638  $t->fail('->clean() throws an sfValidatorError if the value is not an expected value'); 
     39  $t->skip('', 1); 
    3740} 
    3841catch (sfValidatorError $e) 
    3942{ 
    4043  $t->pass('->clean() throws an sfValidatorError if the value is not an expected value'); 
     44  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    4145} 
    4246 
  • branches/1.1/test/unit/validator/sfValidatorChoiceTest.php

    r6197 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(6, new lime_output_color()); 
     13$t = new lime_test(7, new lime_output_color()); 
    1414 
    1515function choice_callable() 
     
    4141  $v->clean('foobar'); 
    4242  $t->fail('->clean() throws an sfValidatorError if the value is not an expected value'); 
     43  $t->skip('', 1); 
    4344} 
    4445catch (sfValidatorError $e) 
    4546{ 
    4647  $t->pass('->clean() throws an sfValidatorError if the value is not an expected value'); 
     48  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    4749} 
    4850 
  • branches/1.1/test/unit/validator/sfValidatorDateTest.php

    r6875 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(26, new lime_output_color()); 
     13$t = new lime_test(29, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorDate(); 
     
    3030  $v->clean('This is not a date'); 
    3131  $t->fail('->clean() throws a sfValidatorError if the date is a string and is not parsable by strtotime'); 
     32  $t->skip('', 1); 
    3233} 
    3334catch (sfValidatorError $e) 
    3435{ 
    3536  $t->pass('->clean() throws a sfValidatorError if the date is a string and is not parsable by strtotime'); 
     37  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    3638} 
    3739 
     
    5355{ 
    5456  $t->pass('->clean() throws a sfValidatorError if the date is not valid'); 
     57  $t->skip('', 1); 
    5558} 
    5659try 
     
    5861  $v->clean(array('year' => -2, 'month' => 1, 'day' => 15)); 
    5962  $t->fail('->clean() throws a sfValidatorError if the date is not valid'); 
     63  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    6064} 
    6165catch (sfValidatorError $e) 
     
    7983  $t->pass('->clean() throws a sfValidatorError if the date does not match the regex'); 
    8084  $t->like($e->getMessage(), '/'.preg_quote($v->getOption('date_format'), '/').'/', '->clean() returns the expected date format in the error message'); 
     85  $t->is($e->getCode(), 'bad_format', '->clean() throws a sfValidatorError'); 
    8186} 
    8287 
     
    106111  $v->clean(array('year' => 2005, 'month' => 1, 'day' => 15, 'hour' => 12, 'minute' => '', 'second' => 12)); 
    107112  $t->fail('->clean() throws a sfValidatorError if the time is not valid'); 
     113  $t->skip('', 1); 
    108114} 
    109115catch (sfValidatorError $e) 
  • branches/1.1/test/unit/validator/sfValidatorDecoratorTest.php

    r6197 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(18, new lime_output_color()); 
     13$t = new lime_test(20, new lime_output_color()); 
    1414 
    1515class MyValidator extends sfValidatorDecorator 
     
    3030  $v->clean(null); 
    3131  $t->fail('->clean() throws a sfValidatorError if the value is required'); 
    32   $t->skip(); 
     32  $t->skip('', 1); 
    3333} 
    3434catch (sfValidatorError $e) 
     
    8282  $v->clean(null); 
    8383  $t->fail('->clean() throws a sfValidatorError if the value is required'); 
     84  $t->skip('', 1); 
    8485} 
    8586catch (sfValidatorError $e) 
    8687{ 
    8788  $t->pass('->clean() throws a sfValidatorError if the value is required'); 
     89  $t->is($e->getCode(), 'required', '->clean() throws a sfValidatorError'); 
    8890} 
    8991 
     
    9294  $v->clean('f'); 
    9395  $t->fail('->clean() throws a sfValidatorError if the wrapped validator failed'); 
     96  $t->skip('', 1); 
    9497} 
    9598catch (sfValidatorError $e) 
    9699{ 
    97100  $t->pass('->clean() throws a sfValidatorError if the wrapped validator failed'); 
     101  $t->is($e->getCode(), 'min_length', '->clean() throws a sfValidatorError'); 
    98102} 
    99103 
  • branches/1.1/test/unit/validator/sfValidatorEmailTest.php

    r5581 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(7, new lime_output_color()); 
     13$t = new lime_test(11, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorEmail(); 
     
    3737    $v->clean($nonUrl); 
    3838    $t->fail('->clean() throws an sfValidatorError if the value is not a valid email'); 
     39    $t->skip('', 1); 
    3940  } 
    4041  catch (sfValidatorError $e) 
    4142  { 
    4243    $t->pass('->clean() throws an sfValidatorError if the value is not a valid email'); 
     44    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    4345  } 
    4446} 
  • branches/1.1/test/unit/validator/sfValidatorFileTest.php

    r6870 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(57, new lime_output_color()); 
     13$t = new lime_test(58, new lime_output_color()); 
    1414 
    1515$tmpDir = sfToolkit::getTmpDir(); 
     
    116116  $v->clean(array('test' => true)); 
    117117  $t->fail('->clean() throws an sfValidatorError if the given value is not well formatted'); 
     118  $t->skip('', 1); 
    118119} 
    119120catch (sfValidatorError $e) 
    120121{ 
    121122  $t->pass('->clean() throws an sfValidatorError if the given value is not well formatted'); 
     123  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    122124} 
    123125$f = $v->clean(array('tmp_name' => $tmpDir.'/test.txt')); 
     
    133135    $v->clean(array('tmp_name' => $tmpDir.'/test.txt', 'error' => $error)); 
    134136    $t->fail('->clean() throws an sfValidatorError if the error code is not UPLOAD_ERR_OK (0)'); 
    135     $t->skip(); 
     137    $t->skip('', 1); 
    136138  } 
    137139  catch (sfValidatorError $e) 
  • branches/1.1/test/unit/validator/sfValidatorIntegerTest.php

    r5816 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(11, new lime_output_color()); 
     13$t = new lime_test(15, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorInteger(); 
     
    2424  $v->clean('not an integer'); 
    2525  $t->fail('->clean() throws a sfValidatorError if the value is not an integer'); 
     26  $t->skip('', 1); 
    2627} 
    2728catch (sfValidatorError $e) 
    2829{ 
    2930  $t->pass('->clean() throws a sfValidatorError if the value is not an integer'); 
     31  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    3032} 
    3133 
     
    3436  $v->clean(12.3); 
    3537  $t->fail('->clean() throws a sfValidatorError if the value is not an integer'); 
     38  $t->skip('', 1); 
    3639} 
    3740catch (sfValidatorError $e) 
    3841{ 
    3942  $t->pass('->clean() throws a sfValidatorError if the value is not an integer'); 
     43  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    4044} 
    4145 
     
    4953  $v->clean(3); 
    5054  $t->fail('"max" option set the maximum number allowed'); 
     55  $t->skip('', 1); 
    5156} 
    5257catch (sfValidatorError $e) 
    5358{ 
    5459  $t->pass('"max" option set the maximum number allowed'); 
     60  $t->is($e->getCode(), 'max', '->clean() throws a sfValidatorError'); 
    5561} 
    5662 
     
    7480  $v->clean('1'); 
    7581  $t->fail('"min" option set the minimum number allowed'); 
     82  $t->skip('', 1); 
    7683} 
    7784catch (sfValidatorError $e) 
    7885{ 
    79   $t->pass('"min_length" option set the minimum number allowed'); 
     86  $t->pass('"min" option set the minimum number allowed'); 
     87  $t->is($e->getCode(), 'min', '->clean() throws a sfValidatorError'); 
    8088} 
    8189 
  • branches/1.1/test/unit/validator/sfValidatorNumberTest.php

    r5816 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(10, new lime_output_color()); 
     13$t = new lime_test(11, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorNumber(); 
     
    6464  $v->clean('1'); 
    6565  $t->fail('"min" option set the minimum number allowed'); 
     66  $t->skip('', 1); 
    6667} 
    6768catch (sfValidatorError $e) 
    6869{ 
    69   $t->pass('"min_length" option set the minimum number allowed'); 
     70  $t->pass('"min" option set the minimum number allowed'); 
     71  $t->is($e->getCode(), 'min', '->clean() throws a sfValidatorError'); 
    7072} 
    7173 
  • branches/1.1/test/unit/validator/sfValidatorRegexTest.php

    r6197 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(4, new lime_output_color()); 
     13$t = new lime_test(5, new lime_output_color()); 
    1414 
    1515// __construct() 
     
    3535  $v->clean('symfony'); 
    3636  $t->fail('->clean() throws an sfValidatorError if the value does not match the pattern'); 
     37  $t->skip('', 1); 
    3738} 
    3839catch (sfValidatorError $e) 
    3940{ 
    4041  $t->pass('->clean() throws an sfValidatorError if the value does not match the pattern'); 
     42  $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    4143} 
    4244 
  • branches/1.1/test/unit/validator/sfValidatorSchemaCompareTest.php

    r6197 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(19, new lime_output_color()); 
     13$t = new lime_test(27, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorSchemaCompare('left', sfValidatorSchemaCompare::EQUAL, 'right'); 
     
    4949    $v->clean($values[0]); 
    5050    $t->fail('->clean() throws an sfValidatorError if the value is the comparison failed'); 
     51    $t->skip('', 1); 
    5152  } 
    5253  catch (sfValidatorError $e) 
    5354  { 
    5455    $t->pass('->clean() throws an sfValidatorError if the value is the comparison failed'); 
     56    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    5557  } 
    5658} 
  • branches/1.1/test/unit/validator/sfValidatorSchemaFilterTest.php

    r6197 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(4, new lime_output_color()); 
     13$t = new lime_test(6, new lime_output_color()); 
    1414 
    1515$v1 = new sfValidatorString(array('min_length' => 2, 'trim' => true)); 
     
    3535  $v->clean(null); 
    3636  $t->fail('->clean() throws a sfValidatorError if the embedded validator failed'); 
     37  $t->skip('', 1); 
    3738} 
    3839catch (sfValidatorError $e) 
    3940{ 
    4041  $t->pass('->clean() throws a sfValidatorError if the embedded validator failed'); 
     42  $t->is($e->getCode(), 'required', '->clean() throws a sfValidatorError'); 
    4143} 
    4244 
     
    4547  $v->clean(array('first_name' => 'f')); 
    4648  $t->fail('->clean() throws a sfValidatorError if the embedded validator failed'); 
     49  $t->skip('', 1); 
    4750} 
    4851catch (sfValidatorError $e) 
    4952{ 
    5053  $t->pass('->clean() throws a sfValidatorError if the embedded validator failed'); 
     54  $t->is($e->getCode(), 'min_length', '->clean() throws a sfValidatorError'); 
    5155} 
  • branches/1.1/test/unit/validator/sfValidatorStringTest.php

    r5816 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(10, new lime_output_color()); 
     13$t = new lime_test(12, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorString(); 
     
    2929  $v->clean('foo'); 
    3030  $t->fail('"max_length" option set the maximum length of the string'); 
     31  $t->skip('', 1); 
    3132} 
    3233catch (sfValidatorError $e) 
    3334{ 
    3435  $t->pass('"max_length" option set the maximum length of the string'); 
     36  $t->is($e->getCode(), 'max_length', '->clean() throws a sfValidatorError'); 
    3537} 
    3638 
     
    5456  $v->clean('fo'); 
    5557  $t->fail('"min_length" option set the minimum length of the string'); 
     58  $t->skip('', 1); 
    5659} 
    5760catch (sfValidatorError $e) 
    5861{ 
    5962  $t->pass('"min_length" option set the minimum length of the string'); 
     63  $t->is($e->getCode(), 'min_length', '->clean() throws a sfValidatorError'); 
    6064} 
    6165 
  • branches/1.1/test/unit/validator/sfValidatorTest.php

    r6197 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(37, new lime_output_color()); 
     13$t = new lime_test(38, new lime_output_color()); 
    1414 
    1515class ValidatorIdentity extends sfValidator 
     
    9999  $t->is($v->clean(''), ''); 
    100100  $t->fail('->clean() throws a sfValidatorError exception if the data does not validate'); 
     101  $t->skip('', 1); 
    101102} 
    102103catch (sfValidatorError $e) 
    103104{ 
    104105  $t->pass('->clean() throws a sfValidatorError exception if the data does not validate'); 
     106  $t->is($e->getCode(), 'required', '->clean() throws a sfValidatorError'); 
    105107} 
    106108$t->is($v->clean('  foo  '), '  foo  ', '->clean() does not trim whitespaces by default'); 
  • branches/1.1/test/unit/validator/sfValidatorUrlTest.php

    r5581 r6945  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(9, new lime_output_color()); 
     13$t = new lime_test(12, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorUrl(); 
     
    3939    $v->clean($nonUrl); 
    4040    $t->fail('->clean() throws an sfValidatorError if the value is not a valid URL'); 
     41    $t->skip('', 1); 
    4142  } 
    4243  catch (sfValidatorError $e) 
    4344  { 
    4445    $t->pass('->clean() throws an sfValidatorError if the value is not a valid URL'); 
     46    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); 
    4547  } 
    4648}