Ejemplo n.º 1
0
 public function testIsValueEmpty()
 {
     $field = new InputField('field1', 'field1');
     $this->assertEquals($field->isValueEmpty(), true, 'Null value');
     $field->setValue('');
     $this->assertEquals($field->isValueEmpty(), true, 'Empty string');
     $field->setValue('test');
     $this->assertEquals($field->isValueEmpty(), false, 'Non-empty string');
 }
 public function testValidDomainWithoutIgnoringSurroundingSpaces()
 {
     $rule = new ValidDomainFormatRule('this field contains no valid domain', true, false);
     $field = new InputField('test', 'test');
     $field->setValue(' www.abc.ch ');
     $this->assertSame($rule->validate($field), false, 'Illegal surrounding spaces');
 }
 public function testDifferentFloatFormats()
 {
     $rule = new FloatValueRule('Not a valid float value');
     $field = new InputField('test', 'test');
     $field->setValue('abc');
     $this->assertSame(false, $rule->validate($field), 'String alphabetic value');
     $field->setValue('103');
     $this->assertSame(true, $rule->validate($field), 'String numeric value');
     $field->setValue(103);
     $this->assertSame(true, $rule->validate($field), 'Int numeric value');
     $field->setValue('');
     $this->assertSame(true, $rule->validate($field), 'Empty value');
     $field->setValue('10.3');
     $this->assertSame(true, $rule->validate($field), 'String float value');
     $field->setValue(10.3);
     $this->assertSame(true, $rule->validate($field), 'Float value');
     $field->setValue('10,3');
     $this->assertSame(true, $rule->validate($field), 'String float value with comma');
     $field->setValue('10:3');
     $this->assertSame(false, $rule->validate($field), 'Invalid decimal separator');
     $field->setValue('1\'000,35');
     $this->assertSame(true, $rule->validate($field), 'Float with period as thousand separator and comma as decimal separator');
     $field->setValue('1\'000.35');
     $this->assertSame(true, $rule->validate($field), 'Float with period as thousand separator and point as decimal separator');
     $field->setValue('1.000,35');
     $this->assertSame(true, $rule->validate($field), 'Float with point as thousand separator and comma as decimal separator');
 }
Ejemplo n.º 4
0
 public function testMaxLengthRuleSingleValue()
 {
     $rule = new MaxLengthRule(2, 'too long');
     $field = new InputField('test', 'test');
     $field->setValue('abc');
     $this->assertSame($rule->validate($field), false);
     $field->setValue('ab');
     $this->assertSame($rule->validate($field), true);
     $field->setValue('');
     $this->assertSame($rule->validate($field), true);
 }
Ejemplo n.º 5
0
 public function testRequiredRuleSingleValue()
 {
     $rule = new RequiredRule('this field is required');
     $field = new InputField('test', 'test');
     $field->setValue('abc');
     $this->assertSame($rule->validate($field), true, 'Not empty');
     $field->setValue('');
     $this->assertSame($rule->validate($field), false, 'Empty string');
     $field->setValue(null);
     $this->assertSame($rule->validate($field), false, 'Empty (null)');
 }
Ejemplo n.º 6
0
 public function testMinLengthRuleSingleValue()
 {
     $rule = new MinLengthRule(2, 'too short');
     $field = new InputField('test', 'test');
     $field->setValue('abc');
     $this->assertSame($rule->validate($field), true, 'Long enough');
     $field->setValue('ab');
     $this->assertSame($rule->validate($field), true, 'On boundaries');
     $field->setValue('');
     $this->assertSame($rule->validate($field), true, 'Zero length');
     $field->setValue(null);
     $this->assertSame($rule->validate($field), true, 'Zero length');
 }
 public function testValueBetweenRuleSingleValueString()
 {
     $rule = new ValueBetweenRule('a', 'd', 'The value has to be between "a" and "d"');
     $field = new InputField('test', 'test');
     $field->setValue('9');
     $this->assertSame($rule->validate($field), false, 'Value 9');
     $field->setValue('a');
     $this->assertSame($rule->validate($field), true, 'Value a');
     $field->setValue('d');
     $this->assertSame($rule->validate($field), true, 'Value d');
     $field->setValue('z');
     $this->assertSame($rule->validate($field), false, 'Value z');
 }
 public function testMultipleValues()
 {
     $rule = new ValidValueRule(array('foo', 42), 'This not a valid value');
     $field = new InputField('test', 'test');
     $field->setValue('');
     $this->assertSame($rule->validate($field), true, 'Empty field');
     $field->setValue(array());
     $this->assertSame($rule->validate($field), true, 'Empty field');
     $field->setValue('bar');
     $this->assertSame($rule->validate($field), false, 'Invalid value');
     $field->setValue(array('bar', 'foo', 42));
     $this->assertSame($rule->validate($field), false, 'Invalid values');
     $field->setValue('foo');
     $this->assertSame($rule->validate($field), true, 'Valid value');
     $field->setValue(array('foo', 42));
     $this->assertSame($rule->validate($field), true, 'Valid values');
 }
 /**
  * @param RightGroup $rightGroup
  */
 protected function prepareEditRightGroupForm(RightGroup $rightGroup)
 {
     if ($this->form instanceof CmsForm) {
         return;
     }
     $lang = $this->cmsController->getLocaleHandler()->getLanguage();
     $checkOptionsRights = array();
     $options = array();
     $allModules = $this->moduleModel->getAllModules();
     foreach ($allModules as $mod) {
         if (isset($mod->manifest_content->rights) === false || count((array) $mod->manifest_content->rights) === 0) {
             continue;
         }
         $optionsTemp = array();
         foreach ($mod->manifest_content->rights as $key => $label) {
             $checkOptionsRights[$key] = $key;
             $optionsTemp[$key] = isset($label->{$lang}) ? $label->{$lang} : $label->en;
         }
         $options[isset($mod->manifest_content->name->{$lang}) ? $mod->manifest_content->name->{$lang} : $mod->manifest_content->name->en] = $optionsTemp;
     }
     $this->form = new CmsForm();
     $this->form->setInputData(array_merge($_POST, $_GET));
     $fldName = new InputField('name', 'Name');
     $fldName->setValue($rightGroup->getGroupName());
     $fldName->addRule(new RequiredRule($this->translator->_d('backend', 'Please insert a group name')));
     $fldKey = new InputField('key', 'Key');
     $fldKey->setValue($rightGroup->getGroupKey());
     $fldKey->addRule(new RequiredRule($this->translator->_d('backend', 'Please insert a group key')));
     $fldRoot = new OptionsField('root', 'Root', array(1 => $this->translator->_d('backend', 'This group has root rights')));
     $fldRoot->setValue(array((int) $rightGroup->isRoot()));
     $fldRoot->setOptionsFieldRenderer(new CheckboxOptionsFieldRenderer());
     $fldRights = new OptionsField('rights', 'Rights', $checkOptionsRights);
     $fldRights->setOptionsFieldRenderer(new RightsOptionsFieldRenderer($options));
     $fldRights->setValue($rightGroup->getRights());
     $this->form->addFields(array($fldName, $fldKey, $fldRoot, $fldRights));
 }