You are here

protected function PathautoTestHelper::path_load in Pathauto 6

Same name and namespace in other branches
  1. 6.2 pathauto.test \PathautoTestHelper::path_load()

Backport of Drupal 7's path_load() function.

3 calls to PathautoTestHelper::path_load()
PathautoLocaleTestCase::testLanguageAliases in ./pathauto.test
Test that when an English node is updated, its old English alias is updated and its newer French alias is left intact.
PathautoTestHelper::assertAliasExists in ./pathauto.test
PathautoTestHelper::assertNoAliasExists in ./pathauto.test

File

./pathauto.test, line 107
Functionality tests for Pathauto.

Class

PathautoTestHelper
Helper test class with some added functions for testing.

Code

protected function path_load($conditions) {
  if (is_numeric($conditions)) {
    $conditions = array(
      'pid' => $conditions,
    );
  }
  elseif (is_string($conditions)) {
    $conditions = array(
      'src' => $conditions,
    );
  }

  // Adjust for some D7 {url_alias} column name changes so we can keep
  // the test files in sync.
  if (isset($conditions['source'])) {
    $conditions['src'] = $conditions['source'];
    unset($conditions['source']);
  }
  if (isset($conditions['alias'])) {
    $conditions['dst'] = $conditions['alias'];
    unset($conditions['alias']);
  }
  $args = array();
  $schema = drupal_get_schema_unprocessed('system', 'url_alias');
  foreach ($conditions as $field => $value) {
    $field_type = $schema['fields'][$field]['type'];
    if (is_array($value)) {
      $conditions[$field] = "{$field} = " . db_placeholders($value, $field_type);
      $args = array_merge($args, $value);
    }
    else {
      $placeholder = db_type_placeholder($field_type);
      $conditions[$field] = "{$field} = {$placeholder}";
      $args[] = $value;
    }
  }
  $sql = "SELECT * FROM {url_alias} WHERE " . implode(' AND ', $conditions);
  return db_fetch_array(db_query_range($sql, $args, 0, 1));
}