public function NameUnitTestCase::testGetInvalidTokens in Name Field 7
Same name and namespace in other branches
- 6 tests/name.test \NameUnitTestCase::testGetInvalidTokens()
Test name_format().
File
- tests/
name.test, line 86 - Tests for the name module.
Class
Code
public function testGetInvalidTokens() {
$names = array(
'given' => array(
'components' => array(
'given' => 'John',
),
'tests' => array(
// Test that only the given name creates a entry.
// Title.
't' => '',
// Given name.
'g' => 'John',
// Escaped letter.
'\\g' => 'g',
// Preferred name.
'p' => 'John',
// Preferred name without fallback.
'q' => '',
// Middle name(s)
'm' => '',
// Family name.
'f' => '',
// Credentials.
'c' => '',
// Generational suffix.
's' => '',
// First letter of the preferred or given.
'w' => 'J',
// First letter of the preferred without fallback.
'v' => '',
// First letter given.
'x' => 'J',
// First letter middle.
'y' => '',
// First letter family.
'z' => '',
// Either the given or family name. Given name is given preference.
'e' => 'John',
// Either the given or family name. Family name is given preference.
'E' => 'John',
// Combination test.
// Using a single space.
'g f' => 'John ',
// Separator 1.
'gif' => 'John ',
// Separator 2.
'gjf' => 'John, ',
// Separator 3.
'gkf' => 'John',
'f g' => ' John',
'fig' => ' John',
'fjg' => ', John',
'fkg' => 'John',
't g t' => ' John ',
'tigit' => ' John ',
'tjgjt' => ', John, ',
'tkgkt' => 'John',
// Modifier entries.
// Lowercase.
'Lg' => 'john',
// Uppercase.
'Ug' => 'JOHN',
// First letter to uppercase.
'Fg' => 'John',
// First letter of all words to uppercase.
'Gg' => 'John',
// lowercase, first letter to uppercase.
'LF(g)' => 'John',
// lowercase, first letter of all words to uppercase.
'LG(g)' => 'John',
// lowercase, first letter to uppercase.
'LFg' => 'John',
// lowercase, first letter of all words to uppercase.
'LGg' => 'John',
// Trims whitespace around the next token.
'Tg' => 'John',
// check_plain.
'Sg' => 'John',
// Conditional entries.
// Brackets.
'(((g)))' => 'John',
// Brackets - mismatched.
'(g))()(' => 'John)(',
// Insert the token if both the surrounding tokens are not empty.
'g+ f' => 'John',
// Insert the token, if and only if the next token after it is not empty.
'g= f' => 'John',
// Skip the token, if and only if the next token after it is not empty.
'g^ f' => 'John ',
// Uses only the first one.
's|c|g|m|f|t' => 'John',
// Uses the previous token unless empty, otherwise it uses this token.
'g|f' => 'John',
// Real world examples.
// Full name with a comma-space before credentials.
'L(t= g= m= f= s=,(= c))' => ' john',
// Full name with a comma-space before credentials. ucfirst does not work on a whitespace.
'TS(LF(t= g= m= f= s)=,(= c))' => 'john',
// Full name with a comma-space before credentials.
'L(t+ g+ m+ f+ s+,(= c))' => 'john',
// Full name with a comma-space before credentials.
'TS(LF(t+ g+ m+ f+ s)+,(= c))' => 'John',
),
),
'full' => array(
'components' => array(
'title' => 'MR.',
'given' => 'JoHn',
'middle' => 'pEter',
'family' => 'dOE',
'generational' => 'sR',
'credentials' => 'b.Sc, pHd',
'preferred' => 'peTe',
),
// MR. JoHn pEter dOE sR b.Sc, pHd.
'tests' => array(
// Test that only the given name creates a entry.
// Title.
't' => 'MR.',
// Given name.
'g' => 'JoHn',
// Preferred name.
'p' => 'peTe',
// Preferred name without fallback.
'q' => 'peTe',
// Middle name(s)
'm' => 'pEter',
// Family name.
'f' => 'dOE',
// Credentials.
'c' => 'b.Sc, pHd',
// Generational suffix.
's' => 'sR',
// First letter of the preferred or given.
'w' => 'p',
// First letter of the preferred without fallback.
'v' => 'p',
// First letter given.
'x' => 'J',
// First letter middle.
'y' => 'p',
// First letter family.
'z' => 'd',
// Either the given or family name. Given name is given preference.
'e' => 'JoHn',
// Either the given or family name. Family name is given preference.
'E' => 'dOE',
// Combination test.
// Using a single space.
'g f' => 'JoHn dOE',
// Separator 1.
'gif' => 'JoHn dOE',
// Separator 2.
'gjf' => 'JoHn, dOE',
// Separator 3.
'gkf' => 'JoHndOE',
'f g' => 'dOE JoHn',
'fig' => 'dOE JoHn',
'fjg' => 'dOE, JoHn',
'fkg' => 'dOEJoHn',
't g t' => 'MR. JoHn MR.',
'tigit' => 'MR. JoHn MR.',
'tjgjt' => 'MR., JoHn, MR.',
'tkgkt' => 'MR.JoHnMR.',
// Modifier entries.
// Lowercase.
'L(t g m f s c)' => 'mr. john peter doe sr b.sc, phd',
// Uppercase.
'U(t g m f s c)' => 'MR. JOHN PETER DOE SR B.SC, PHD',
// First letter to uppercase.
'F(t g m f s c)' => 'MR. JoHn pEter dOE sR b.Sc, pHd',
// First letter of all words to uppercase.
'G(t g m f s c)' => 'MR. JoHn PEter DOE SR B.Sc, PHd',
// First letter to uppercase.
'LF(t g m f s c)' => 'Mr. john peter doe sr b.sc, phd',
// First letter of all words to uppercase.
'LG(t g m f s c)' => 'Mr. John Peter Doe Sr B.sc, Phd',
// Trims whitespace around the next token.
'T(t g m f s c)' => 'MR. JoHn pEter dOE sR b.Sc, pHd',
// check_plain.
'S(t g m f s c)' => 'MR. JoHn pEter dOE sR b.Sc, pHd',
// Conditional entries.
// Brackets.
'(((t g m f s c)))' => 'MR. JoHn pEter dOE sR b.Sc, pHd',
// Brackets - mismatched.
'(t g m f s c))()(' => 'MR. JoHn pEter dOE sR b.Sc, pHd)(',
// Insert the token, if and only if the next token after it is not empty.
't= g= m= f= s= c' => 'MR. JoHn pEter dOE sR b.Sc, pHd',
// Uses the previous token unless empty, otherwise it uses this token.
'g|m|f' => 'JoHn',
// Uses the previous token unless empty, otherwise it uses this token.
'm|f|g' => 'pEter',
// Uses only the first one.
's|c|g|m|f|t' => 'sR',
// Real world examples.
// Full name with a comma-space before credentials.
'L(t= g= m= f= s=,(= c))' => 'mr. john peter doe sr, b.sc, phd',
// Full name with a comma-space before credentials.
'TS(LG(t= g= m= f= s)=,LG(= c))' => 'Mr. John Peter Doe Sr, B.sc, Phd',
// Full name including preferred name (nickname).
// Note G only works on a space boundary.
'TS(LG(((t+ig+i(=\\(q-\\)))+im)+if)+iLG(s))' => 'Mr. John (pete) Peter Doe Sr',
),
),
);
foreach ($names as $title => $info) {
$this
->assertNameFormats($info['components'], NULL, NULL, $info['tests']);
}
}