function MachineNameControllerTest::providerTestMachineNameController
Same name in other branches
- 9 core/modules/system/tests/src/Unit/Transliteration/MachineNameControllerTest.php \Drupal\Tests\system\Unit\Transliteration\MachineNameControllerTest::providerTestMachineNameController()
- 10 core/modules/system/tests/src/Unit/Transliteration/MachineNameControllerTest.php \Drupal\Tests\system\Unit\Transliteration\MachineNameControllerTest::providerTestMachineNameController()
Data provider for testMachineNameController().
Return value
array An array containing:
- An array of request parameters.
- The expected content of the JSONresponse.
See also
testMachineNameController()
File
-
core/
modules/ system/ tests/ src/ Unit/ Transliteration/ MachineNameControllerTest.php, line 55
Class
- MachineNameControllerTest
- Tests that the machine name controller can transliterate strings as expected.
Namespace
Drupal\Tests\system\Unit\TransliterationCode
public function providerTestMachineNameController() {
$valid_data = [
[
[
'text' => 'Bob',
'langcode' => 'en',
],
'"Bob"',
],
[
[
'text' => 'Bob',
'langcode' => 'en',
'lowercase' => TRUE,
],
'"bob"',
],
[
[
'text' => 'Bob',
'langcode' => 'en',
'replace' => 'Alice',
'replace_pattern' => 'Bob',
],
'"Alice"',
],
[
[
'text' => 'Bob',
'langcode' => 'en',
'replace' => 'Alice',
'replace_pattern' => 'Tom',
],
'"Bob"',
],
[
[
'text' => 'Äwesome',
'langcode' => 'en',
'lowercase' => TRUE,
],
'"awesome"',
],
[
[
'text' => 'Äwesome',
'langcode' => 'de',
'lowercase' => TRUE,
],
'"aewesome"',
],
// Tests special characters replacement in the input text.
[
[
'text' => 'B?!"@\\/-ob@e',
'langcode' => 'en',
'lowercase' => TRUE,
'replace' => '_',
'replace_pattern' => '[^a-z0-9_.]+',
],
'"b_ob_e"',
],
// Tests @ character in the replace_pattern regex.
[
[
'text' => 'Bob@e\\0',
'langcode' => 'en',
'lowercase' => TRUE,
'replace' => '_',
'replace_pattern' => '[^a-z0-9_.@]+',
],
'"bob@e_0"',
],
// Tests null byte in the replace_pattern regex.
[
[
'text' => 'Bob',
'langcode' => 'en',
'lowercase' => TRUE,
'replace' => 'fail()',
'replace_pattern' => ".*@e\x00",
],
'"bob"',
],
[
[
'text' => 'Bob@e',
'langcode' => 'en',
'lowercase' => TRUE,
'replace' => 'fail()',
'replace_pattern' => ".*@e\x00",
],
'"fail()"',
],
];
$valid_data = array_map(function ($data) {
if (isset($data[0]['replace_pattern'])) {
$data[0]['replace_token'] = 'token-' . $data[0]['replace_pattern'];
}
return $data;
}, $valid_data);
return $valid_data;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.