Skip to content
Browse files

Fixing unit test

  • Loading branch information...
1 parent 9c38584 commit cc815eba55ae85d3210a97545d030bdff1104737 @chdemko committed Dec 14, 2011
View
2 libraries/joomla/form/form.php
@@ -1655,7 +1655,7 @@ protected function loadField($element, $group = null, $value = null)
{
// Make sure there is a valid JXMLElement.
if (!($element instanceof JXMLElement))
- {
+ {var_dump('ici');
return false;
}
View
9 libraries/joomla/form/formfield.php
@@ -369,7 +369,14 @@ public function setup(&$element, $value, $group = null)
$this->id = $this->getId($id, $this->fieldname);
// Set the field default value.
- $this->value = $value;
+ if ($this->multiple && is_string($value))
+ {
+ $this->value = json_decode($value, true);
+ }
+ else
+ {
+ $this->value = $value;
+ }
return true;
}
View
11 tests/suite/joomla/form/JFormDataHelper.php
@@ -396,6 +396,17 @@ class="inputbox"
default="DEFAULT_KEY"
translate_default="true"
type="text"/>
+
+ <field
+ name="preset"
+ preset="presetvalue"
+ type="text"/>
+
+ <field
+ name="presetdefault"
+ preset="presetvalue"
+ default="defaultvalue"
+ type="text"/>
</fields>
</form>';
View
44 tests/suite/joomla/form/JFormTest.php
@@ -7,6 +7,7 @@
* @license GNU General Public License version 2 or later; see LICENSE
*/
+require_once JPATH_PLATFORM . '/joomla/filter/filterinput.php';
/**
* Test class for JForm.
*
@@ -1368,9 +1369,48 @@ public function testLoadField()
);
// Test correct usage.
+ $fields = $form->getXML()->xpath('//field[@name="title"]');
+ $this->assertThat(
+ $form->loadField($fields[0]) instanceof JFormField,
+ $this->isTrue(),
+ 'Line:'.__LINE__.' Title field must be found.'
+ );
+
+ // Test preset attribute with value equal to null
+ $fields = $form->getXML()->xpath('//field[@name="preset"]');
+ $field = $form->loadField($fields[0]);
+ $this->assertThat(
+ $field->value,
+ $this->equalTo('presetvalue'),
+ 'Line:'.__LINE__.' Preset value should be used.'
+ );
- $field = $form->getField('title');
- $field = $form->loadField($field);
+ // Test preset attribute with value equal to ''
+ $form->setValue('preset', null, '');
+ $field = $form->loadField($fields[0]);
+ $this->assertThat(
+ $field->value,
+ $this->equalTo(''),
+ 'Line:'.__LINE__.' Preset value should not be used.'
+ );
+
+ // Test preset attribute with value equal to null and existence of 'default' attribute
+ $fields = $form->getXML()->xpath('//field[@name="presetdefault"]');
+ $field = $form->loadField($fields[0]);
+ $this->assertThat(
+ $field->value,
+ $this->equalTo('presetvalue'),
+ 'Line:'.__LINE__.' Preset value should be used.'
+ );
+
+ // Test preset attribute with value equal to '' and existence of 'default' attribute
+ $form->setValue('presetdefault', null, '');
+ $field = $form->loadField($fields[0]);
+ $this->assertThat(
+ $field->value,
+ $this->equalTo('defaultvalue'),
+ 'Line:'.__LINE__.' Default value should be used.'
+ );
}
/**

0 comments on commit cc815eb

Please sign in to comment.
Something went wrong with that request. Please try again.