Sync to master branch.

This commit is contained in:
Wilmer Arambula
2023-10-31 14:32:05 -03:00
16 changed files with 1112 additions and 130 deletions

View File

@@ -461,4 +461,66 @@ class StringHelperTest extends TestCase
['', ''],
];
}
public function testMask()
{
// Standard masking
$this->assertSame('12******90', StringHelper::mask('1234567890', 2, 6));
$this->assertSame('a********j', StringHelper::mask('abcdefghij', 1, 8));
$this->assertSame('*************', StringHelper::mask('Hello, World!', 0, 13));
$this->assertSame('************!', StringHelper::mask('Hello, World!', 0, 12));
$this->assertSame('Hello, *orld!', StringHelper::mask('Hello, World!', 7, 1));
$this->assertSame('Saleh Hashemi', StringHelper::mask('Saleh Hashemi', 0, 0));
// Different Mask Character
$this->assertSame('12######90', StringHelper::mask('1234567890', 2, 6, '#'));
// Positions outside the string
$this->assertSame('1234567890', StringHelper::mask('1234567890', 20, 6));
$this->assertSame('1234567890', StringHelper::mask('1234567890', -20, 6));
// Negative values for start
$this->assertSame('1234****90', StringHelper::mask('1234567890', -6, 4));
// type-related edge case
$this->assertSame('1234****90', StringHelper::mask(1234567890, -6, 4));
// Multibyte characters
$this->assertSame('你**', StringHelper::mask('你好吗', 1, 2));
$this->assertSame('你好吗', StringHelper::mask('你好吗', 4, 2));
// Special characters
$this->assertSame('em**l@email.com', StringHelper::mask('email@email.com', 2, 2));
$this->assertSame('******email.com', StringHelper::mask('email@email.com', 0, 6));
}
/**
* @param string $string
* @param string $start
* @param string $end
* @param string $expectedResult
* @dataProvider dataProviderFindBetween
*/
public function testFindBetween($string, $start, $end, $expectedResult)
{
$this->assertSame($expectedResult, StringHelper::findBetween($string, $start, $end));
}
public function dataProviderFindBetween()
{
return [
['hello world hello', ' hello', ' world', null], // end before start
['This is a sample string', ' is ', ' string', 'a sample'], // normal case
['startendstart', 'start', 'end', ''], // end before start
['startmiddleend', 'start', 'end', 'middle'], // normal case
['startend', 'start', 'end', ''], // end immediately follows start
['multiple start start end end', 'start ', ' end', 'start end'], // multiple starts and ends
['', 'start', 'end', null], // empty string
['no delimiters here', 'start', 'end', null], // no start and end
['start only', 'start', 'end', null], // start found but no end
['end only', 'start', 'end', null], // end found but no start
['spécial !@#$%^&*()', 'spé', '&*()', 'cial !@#$%^'], // Special characters
['من صالح هاشمی هستم', 'من ', ' هستم', 'صالح هاشمی'], // other languages
];
}
}