mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Avoid test failure on use of narrow-NBSP (#9725)
For whatever reason (different locale version) my local dev env uses narrow-NBSPs (Unicode 8239) rather than regular NBSP in its localised strings. This patch makes the tests robust against this difference. Note that this occurred running the tests in Lando. Co-authored-by: Robbie Averill <robbie@averill.co.nz>
This commit is contained in:
parent
bb7cf17e3c
commit
c5d676fa4e
@ -1052,8 +1052,8 @@ class FormTest extends FunctionalTest
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
'<input type="text" name="SomeFrenchNumericField" value="9 876,5432" ',
|
'<input type="text" name="SomeFrenchNumericField" value="9 876,5432" ',
|
||||||
$body,
|
$this->clean($body),
|
||||||
'Our reloaded form should contain a SomeFrenchNumericField with the value "9 876,5432"'
|
'Our reloaded form should contain a SomeFrenchNumericField with the value "9 876,5432"'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1064,8 +1064,8 @@ class FormTest extends FunctionalTest
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
'<input type="text" name="SomeFrenchMoneyField[Amount]" value="9 876,54" ',
|
'<input type="text" name="SomeFrenchMoneyField[Amount]" value="9 876,54" ',
|
||||||
$body,
|
$this->clean($body),
|
||||||
'Our reloaded form should contain a SomeFrenchMoneyField[Amount] with the value "9 876,54"'
|
'Our reloaded form should contain a SomeFrenchMoneyField[Amount] with the value "9 876,54"'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1108,4 +1108,23 @@ class FormTest extends FunctionalTest
|
|||||||
new FieldList()
|
new FieldList()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In some cases and locales, validation expects non-breaking spaces.
|
||||||
|
* This homogenises narrow and regular NBSPs to a regular space character
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @return string The input value, with all non-breaking spaces replaced with spaces
|
||||||
|
*/
|
||||||
|
protected function clean($input)
|
||||||
|
{
|
||||||
|
return str_replace(
|
||||||
|
[
|
||||||
|
html_entity_decode(' ', null, 'UTF-8'),
|
||||||
|
html_entity_decode(' ', null, 'UTF-8'), // narrow non-breaking space
|
||||||
|
],
|
||||||
|
' ',
|
||||||
|
trim($input)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,23 @@ class NumericFieldTest extends SapphireTest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* In some cases and locales, validation expects non-breaking spaces.
|
* In some cases and locales, validation expects non-breaking spaces.
|
||||||
|
* This homogenises narrow and regular NBSPs to a regular space character
|
||||||
*
|
*
|
||||||
* Duplicates non-public NumericField::clean method
|
* Duplicates non-public NumericField::clean method
|
||||||
*
|
*
|
||||||
* @param string $input
|
* @param string $input
|
||||||
* @return string The input value, with all spaces replaced with non-breaking spaces
|
* @return string The input value, with all non-breaking spaces replaced with spaces
|
||||||
*/
|
*/
|
||||||
protected function clean($input)
|
protected function clean($input)
|
||||||
{
|
{
|
||||||
$nbsp = html_entity_decode(' ', null, 'UTF-8');
|
return str_replace(
|
||||||
return str_replace(' ', $nbsp, trim($input));
|
[
|
||||||
|
html_entity_decode(' ', null, 'UTF-8'),
|
||||||
|
html_entity_decode(' ', null, 'UTF-8'), // narrow non-breaking space
|
||||||
|
],
|
||||||
|
' ',
|
||||||
|
trim($input)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user