You are here

public function TextimagePregMatchTestCase::testOffsetArgument in Textimage 7.3

Same name and namespace in other branches
  1. 7.2 tests/textimage_preg_match.test \TextimagePregMatchTestCase::testOffsetArgument()

Performs the tests for the offset argument.

File

tests/textimage_preg_match.test, line 36
Textimage - unit test case script.

Class

TextimagePregMatchTestCase
Checks that drupal_preg_match() function works as expected.

Code

public function testOffsetArgument() {
  $matches = array();

  // Character 'п' is 2 bytes long and preg_match() would start from the
  // second 'п' character and not from the first 'z'.
  $result = drupal_preg_match('/п/u', 'ппzz', $matches, NULL, 2);
  $this
    ->assertFalse($result, t('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 = drupal_preg_match('/.*$/u', 'пzz', $matches, NULL, 1);
  $this
    ->assertTrue($result && $matches[0] === 'zz', t('String was matched using character-based offset.'));
}