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:
Sam Minnée 2020-10-09 10:33:51 +13:00 committed by GitHub
parent bb7cf17e3c
commit c5d676fa4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 7 deletions

View File

@ -1052,8 +1052,8 @@ class FormTest extends FunctionalTest
);
$this->assertContains(
'<input type="text" name="SomeFrenchNumericField" value="9 876,5432" ',
$body,
'<input type="text" name="SomeFrenchNumericField" value="9 876,5432" ',
$this->clean($body),
'Our reloaded form should contain a SomeFrenchNumericField with the value "9 876,5432"'
);
@ -1064,8 +1064,8 @@ class FormTest extends FunctionalTest
);
$this->assertContains(
'<input type="text" name="SomeFrenchMoneyField[Amount]" value="9 876,54" ',
$body,
'<input type="text" name="SomeFrenchMoneyField[Amount]" value="9 876,54" ',
$this->clean($body),
'Our reloaded form should contain a SomeFrenchMoneyField[Amount] with the value "9 876,54"'
);
@ -1108,4 +1108,23 @@ class FormTest extends FunctionalTest
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('&nbsp;', null, 'UTF-8'),
html_entity_decode('&#8239;', null, 'UTF-8'), // narrow non-breaking space
],
' ',
trim($input)
);
}
}

View File

@ -13,16 +13,23 @@ class NumericFieldTest extends SapphireTest
/**
* 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
*
* @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)
{
$nbsp = html_entity_decode('&nbsp;', null, 'UTF-8');
return str_replace(' ', $nbsp, trim($input));
return str_replace(
[
html_entity_decode('&nbsp;', null, 'UTF-8'),
html_entity_decode('&#8239;', null, 'UTF-8'), // narrow non-breaking space
],
' ',
trim($input)
);
}
/**