You are here

function NotificationsTemplatesTests::diffTexts in Notifications 6.4

Same name and namespace in other branches
  1. 6.2 tests/notifications_templates.test \NotificationsTemplatesTests::diffTexts()
  2. 6.3 tests/notifications_templates.test \NotificationsTemplatesTests::diffTexts()
  3. 7 tests/notifications_templates.test \NotificationsTemplatesTests::diffTexts()
1 call to NotificationsTemplatesTests::diffTexts()
NotificationsTemplatesTests::compareTexts in tests/notifications_templates.test

File

tests/notifications_templates.test, line 227

Class

NotificationsTemplatesTests
Class for testing notifications templates and message composition.

Code

function diffTexts($text1, $text2) {
  $diff = array();
  foreach ($text1 as $key => $value) {
    if (!isset($text2[$key])) {
      $diff[] = array(
        $key,
        str_replace("\n", '\\n', $value),
        '--',
      );
    }
    elseif (is_array($value)) {
      if ($compare = $this
        ->compareTexts($value, $text2[$key])) {
        $diff[] = array(
          $key,
          array(
            'data' => $compare,
            'colspan' => 2,
          ),
        );
      }
    }
    elseif ($value != $text2[$key]) {
      $diff[] = array(
        $key,
        str_replace("\n", '\\n', $value),
        str_replace("\n", '\\n', $text2[$key]),
      );
    }
  }
  return $diff;
}