You are here

function feeds_tests_feeds_after_parse in Feeds 7.2

Implements hook_feeds_after_parse().

File

tests/feeds_tests.module, line 566
Helper module for Feeds tests.

Code

function feeds_tests_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {

  // Empties the list of items to import in case the test says that there are
  // items in there with encoding issues. These items can not be processed
  // during tests without having a test failure because in < PHP 5.4 that would
  // produce the following warning:
  // > htmlspecialchars(): Invalid multibyte sequence in argument.
  // @see FeedsCSVParserTestCase::testMbstringExtensionDisabled()
  if (variable_get('feeds_tests_feeds_after_parse_empty_items', FALSE)) {

    // Remove all items. No items will be processed.
    $result->items = array();
  }
  if ($source->id == 'user_import') {
    foreach ($result->items as &$item) {
      if (!empty($item['roles']) && strpos($item['roles'], '|')) {

        // Convert roles value to multiple values.
        // @see FeedsCSVtoUsersTest::testRoleTargetWithoutRoleCreation()
        // @see FeedsCSVtoUsersTest::testRoleTargetWithRoleCreation()
        // @see FeedsCSVtoUsersTest::testRoleTargetWithAllowedRoles()
        $item['roles'] = explode('|', $item['roles']);
      }
      if (!empty($item['rids']) && strpos($item['rids'], '|')) {

        // Convert roles value to multiple values.
        // @see FeedsCSVtoUsersTest::testRoleTargetRids()
        $item['rids'] = explode('|', $item['rids']);
      }
    }
  }

  // Casts the 'uid' value to a float to ensure float values don't result into
  // array_flip() warnings when using the value to load an user.
  // @see FeedsRSStoNodesTest::testUidTargetWithFloat()
  if (variable_get('feeds_tests_feeds_after_parse_uid_float_value', FALSE)) {
    foreach ($result->items as &$item) {
      $item['uid'] = (double) $item['uid'];
    }
  }

  // Conditionally set the 'uid' value to the current user.
  // @see FeedsAccountSwitcherTest
  if (variable_get('feeds_tests_set_uid_current_user', FALSE)) {
    foreach ($result->items as &$item) {
      $item['uid'] = $GLOBALS['user']->uid;
    }
  }

  // Conditionally abort the import abruptly.
  // @see FeedsAccountSwitcherTest
  if (variable_get('feeds_tests_trigger_import_disruption', FALSE)) {
    die;
  }
}