$v = new Schema(array('s1' => $v1)); $t->ok($v['s1'] == $v1, 'Schema implements the \\ArrayAccess interface for the fields'); $t->is($v['s2'], null, 'Schema implements the \\ArrayAccess interface for the fields'); $v = new Schema(array('v1' => $v1)); unset($v['s1']); $t->is($v['s1'], null, 'Schema implements the \\ArrayAccess interface for the fields'); // ->configure() $t->diag('->configure()'); $v = new Schema(array('s1' => $v1, 's2' => $v2)); $t->is($v->getOption('allow_extra_fields'), false, '->configure() sets "allow_extra_fields" option to false by default'); $t->is($v->getOption('filter_extra_fields'), true, '->configure() sets "filter_extra_fields" option to true by default'); $t->is($v->getMessage('extra_fields'), 'Unexpected extra form field named "%field%".', '->configure() has a default error message for the "extra_fields" error'); $v = new Schema(array('s1' => $v1, 's2' => $v2), array('allow_extra_fields' => true, 'filter_extra_fields' => false), array('extra_fields' => 'Extra fields')); $t->is($v->getOption('allow_extra_fields'), true, '->__construct() can override the default value for the "allow_extra_fields" option'); $t->is($v->getOption('filter_extra_fields'), false, '->__construct() can override the default value for the "filter_extra_fields" option'); $t->is($v->getMessage('extra_fields'), 'Extra fields', '->__construct() can override the default message for the "extra_fields" error message'); // ->clean() $t->diag('->clean()'); $v = new Schema(); $t->is($v->clean(null), array(), '->clean() converts null to empty array before validation'); $v = new Schema(array('s1' => $v1, 's2' => $v2)); try { $v->clean('foo'); $t->fail('->clean() throws an \\InvalidArgumentException exception if the first argument is not an array of value'); } catch (\InvalidArgumentException $e) { $t->pass('->clean() throws an \\InvalidArgumentException exception if the first argument is not an array of value'); } $t->is($v->clean(array('s1' => 'foo', 's2' => 'bar')), array('s1' => 'foo', 's2' => 'bar'), '->clean() returns the string unmodified'); try { $v->clean(array('s1' => 'foo', 's2' => 'bar', 'foo' => 'bar')); $t->fail('->clean() throws an ErrorSchema exception if a you give a non existant field');