public function TextUtilityTest::testOffsetArgument in Image Effects 8.3
Same name and namespace in other branches
- 8 tests/src/Unit/TextUtilityTest.php \Drupal\Tests\image_effects\Unit\TextUtilityTest::testOffsetArgument()
- 8.2 tests/src/Unit/TextUtilityTest.php \Drupal\Tests\image_effects\Unit\TextUtilityTest::testOffsetArgument()
Performs the tests for the offset argument.
File
- tests/
src/ Unit/ TextUtilityTest.php, line 18
Class
- TextUtilityTest
- Tests the UTF-8 character-based wrapper of the preg_match function.
Namespace
Drupal\Tests\image_effects\UnitCode
public function testOffsetArgument() {
$matches = [];
// Character 'п' is 2 bytes long and preg_match() would start from the
// second 'п' character and not from the first 'z'.
$result = TextUtility::unicodePregMatch('/п/u', 'ппzz', $matches, NULL, 2);
$this
->assertEquals(0, $result, 'String was skipped using character-based offset.');
// Again, character 'п' is 2 bytes long and we skip 1 character, so
// preg_match() would fail, because the string with byte offset 1 is not a
// valid UTF-8 string.
$result = TextUtility::unicodePregMatch('/.*$/u', 'пzz', $matches, NULL, 1);
$this
->assertTrue($result && $matches[0] === 'zz', 'String was matched using character-based offset.');
}