diff --git a/layouts/joomla/form/field/email.php b/layouts/joomla/form/field/email.php
index 3ee9827cc0ae3..96327272a2948 100644
--- a/layouts/joomla/form/field/email.php
+++ b/layouts/joomla/form/field/email.php
@@ -51,15 +51,15 @@
$attributes = array(
$spellcheck ? '' : 'spellcheck="false"',
!empty($size) ? 'size="' . $size . '"' : '',
- $disabled ? 'disabled' : '',
- $readonly ? 'readonly' : '',
+ $disabled ? 'disabled="disabled"' : '',
+ $readonly ? 'readonly="readonly"' : '',
$onchange ? 'onchange="' . $onchange . '"' : '',
$autocomplete,
$multiple ? 'multiple' : '',
!empty($maxLength) ? 'maxlength="' . $maxLength . '"' : '',
strlen($hint) ? 'placeholder="' . $hint . '"' : '',
- $required ? 'required aria-required="true"' : '',
- $autofocus ? 'autofocus' : '',
+ $required ? 'required="required" aria-required="true"' : '',
+ $autofocus ? 'autofocus="autofocus"' : '',
);
// Including fallback code for HTML5 non supported browsers.
diff --git a/layouts/joomla/form/field/text.php b/layouts/joomla/form/field/text.php
index 0731041b229e1..d581bc0879b80 100644
--- a/layouts/joomla/form/field/text.php
+++ b/layouts/joomla/form/field/text.php
@@ -61,15 +61,15 @@
$attributes = array(
!empty($class) ? 'class="' . $class . '"' : '',
!empty($size) ? 'size="' . $size . '"' : '',
- $disabled ? 'disabled' : '',
- $readonly ? 'readonly' : '',
+ $disabled ? 'disabled="disabled"' : '',
+ $readonly ? 'readonly="readonly"' : '',
$list,
strlen($hint) ? 'placeholder="' . $hint . '"' : '',
$onchange ? ' onchange="' . $onchange . '"' : '',
!empty($maxLength) ? $maxLength : '',
- $required ? 'required aria-required="true"' : '',
+ $required ? 'required="required" aria-required="true"' : '',
$autocomplete,
- $autofocus ? ' autofocus' : '',
+ $autofocus ? ' autofocus="autofocus"' : '',
$spellcheck ? '' : 'spellcheck="false"',
!empty($inputmode) ? 'inputmode="' . $inputmode . '"' : '',
!empty($pattern) ? 'pattern="' . $pattern . '"' : '',
diff --git a/libraries/joomla/form/fields/text.php b/libraries/joomla/form/fields/text.php
index 1f0026cac8496..541d17ff212d9 100644
--- a/libraries/joomla/form/fields/text.php
+++ b/libraries/joomla/form/fields/text.php
@@ -184,19 +184,22 @@ protected function getOptions()
{
$options = array();
- foreach ($this->element->children() as $option)
+ if (isset($this->element))
{
- // Only add elements.
- if ($option->getName() != 'option')
+ foreach ($this->element->children() as $option)
{
- continue;
- }
+ // Only add elements.
+ if ($option->getName() != 'option')
+ {
+ continue;
+ }
- // Create a new option object based on the element.
- $options[] = JHtml::_(
- 'select.option', (string) $option['value'],
- JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)), 'value', 'text'
- );
+ // Create a new option object based on the element.
+ $options[] = JHtml::_(
+ 'select.option', (string) $option['value'],
+ JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)), 'value', 'text'
+ );
+ }
}
return $options;
diff --git a/tests/unit/suites/libraries/joomla/form/fields/JFormFieldEmailTest.php b/tests/unit/suites/libraries/joomla/form/fields/JFormFieldEmailTest.php
index ab529a5734801..3067c637d7ed0 100644
--- a/tests/unit/suites/libraries/joomla/form/fields/JFormFieldEmailTest.php
+++ b/tests/unit/suites/libraries/joomla/form/fields/JFormFieldEmailTest.php
@@ -91,11 +91,9 @@ public function testGetInput($data, $expected)
TestReflection::setValue($formField, $attr, $value);
}
- $replaces = array("\n", "\r"," ", "\t");
-
- $this->assertEquals(
- str_replace($replaces, '', $expected),
- str_replace($replaces, '', TestReflection::invoke($formField, 'getInput')),
+ $this->assertXmlStringEqualsXmlString(
+ TestReflection::invoke($formField, 'getInput'),
+ $expected,
'Line:' . __LINE__ . ' The field with no value and no checked attribute did not produce the right html'
);
}
diff --git a/tests/unit/suites/libraries/joomla/form/fields/JFormFieldTextTest.php b/tests/unit/suites/libraries/joomla/form/fields/JFormFieldTextTest.php
index 54c212d9cfd6a..e41a29e683e99 100644
--- a/tests/unit/suites/libraries/joomla/form/fields/JFormFieldTextTest.php
+++ b/tests/unit/suites/libraries/joomla/form/fields/JFormFieldTextTest.php
@@ -128,11 +128,9 @@ public function testGetInputNoValue($data, $expected)
TestReflection::setValue($formField, $attr, $value);
}
- $replaces = array("\n", "\r"," ", "\t");
-
- $this->assertEquals(
- str_replace($replaces, '', TestReflection::invoke($formField, 'getInput')),
- str_replace($replaces, '', $expected),
+ $this->assertXmlStringEqualsXmlString(
+ TestReflection::invoke($formField, 'getInput'),
+ $expected,
'Line:' . __LINE__ . ' The field did not produce the right html'
);
}
diff --git a/tests/unit/suites/libraries/joomla/form/fields/TestHelpers/JHtmlFieldEmail-helper-dataset.php b/tests/unit/suites/libraries/joomla/form/fields/TestHelpers/JHtmlFieldEmail-helper-dataset.php
index aafa4873e7869..072fe1800405f 100644
--- a/tests/unit/suites/libraries/joomla/form/fields/TestHelpers/JHtmlFieldEmail-helper-dataset.php
+++ b/tests/unit/suites/libraries/joomla/form/fields/TestHelpers/JHtmlFieldEmail-helper-dataset.php
@@ -58,7 +58,7 @@ class JHtmlFieldEmailTest_DataSet
'name' => 'myTestName',
'disabled' => true,
),
- '',
+ '',
),
'Readonly' => array(
@@ -67,7 +67,7 @@ class JHtmlFieldEmailTest_DataSet
'name' => 'myTestName',
'readonly' => true,
),
- '',
+ '',
),
'Hint' => array(
@@ -94,7 +94,7 @@ class JHtmlFieldEmailTest_DataSet
'name' => 'myTestName',
'autofocus' => true,
),
- '',
+ '',
),
'Spellcheck' => array(
@@ -130,7 +130,7 @@ class JHtmlFieldEmailTest_DataSet
'name' => 'myTestName',
'required' => true,
),
- '',
+ '',
),
);
diff --git a/tests/unit/suites/libraries/joomla/form/fields/TestHelpers/JHtmlFieldText-helper-dataset.php b/tests/unit/suites/libraries/joomla/form/fields/TestHelpers/JHtmlFieldText-helper-dataset.php
index 3816223cfe5e3..b89d4d65f3df5 100644
--- a/tests/unit/suites/libraries/joomla/form/fields/TestHelpers/JHtmlFieldText-helper-dataset.php
+++ b/tests/unit/suites/libraries/joomla/form/fields/TestHelpers/JHtmlFieldText-helper-dataset.php
@@ -58,7 +58,7 @@ class JHtmlFieldTextTest_DataSet
'name' => 'myTestName',
'disabled' => true,
),
- '',
+ '',
),
'Readonly' => array(
@@ -67,7 +67,7 @@ class JHtmlFieldTextTest_DataSet
'name' => 'myTestName',
'readonly' => true,
),
- '',
+ '',
),
'Hint' => array(
@@ -94,7 +94,7 @@ class JHtmlFieldTextTest_DataSet
'name' => 'myTestName',
'autofocus' => true,
),
- '',
+ '',
),
'Spellcheck' => array(
@@ -130,7 +130,7 @@ class JHtmlFieldTextTest_DataSet
'name' => 'myTestName',
'required' => true,
),
- '',
+ '',
),
);