You are here

class FeedsFileHTTPTestCase in Feeds 7.2

HTTP fetcher test class.

Hierarchy

Expanded class hierarchy of FeedsFileHTTPTestCase

File

tests/feeds_fetcher_http.test, line 11
Contains FeedsFileHTTPTestCase.

View source
class FeedsFileHTTPTestCase extends FeedsWebTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Fetcher: HTTP',
      'description' => 'Tests for file http fetcher plugin.',
      'group' => 'Feeds',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    // Include FeedsProcessor.inc so processor related constants are available.
    module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');

    // Do not use curl as that will result into HTTP requests returning a 404.
    variable_set('feeds_never_use_curl', TRUE);
  }

  /**
   * Setup importer to import items from testing/feeds/nodes.csv.
   */
  public function setUpImporter() {

    // Set up an importer.
    $this
      ->createImporterConfiguration('Node import', 'node');
    $this
      ->setSettings('node', NULL, array(
      'content_type' => '',
      'import_period' => 0,
    ));
    $this
      ->setPlugin('node', 'FeedsHTTPFetcher');
    $this
      ->setPlugin('node', 'FeedsCSVParser');
    $this
      ->setSettings('node', 'FeedsNodeProcessor', array(
      'update_existing' => FEEDS_UPDATE_EXISTING,
    ));
    $this
      ->addMappings('node', array(
      0 => array(
        'source' => 'title',
        'target' => 'title',
        'unique' => TRUE,
      ),
      1 => array(
        'source' => 'body',
        'target' => 'body',
      ),
    ));
  }

  /**
   * Configures the evironment so that multiple cron runs are needed to complete
   * an import.
   *
   * @param string $source_url
   *   The URL of the file to import.
   */
  protected function setUpMultipleCronRuns($source_url) {

    // Process 5 items per batch.
    variable_set('feeds_process_limit', 5);

    // Set variable to enforce that only five items get imported per cron run.
    // @see feeds_tests_cron_queue_alter()
    // @see feeds_tests_feeds_after_save()
    variable_set('feeds_tests_feeds_source_import_queue_time', 5);
    variable_set('feeds_tests_feeds_after_save_sleep', 1);

    // Set up importer.
    $this
      ->setUpImporter();

    // Only import during cron runs, not immediately.
    $this
      ->setSettings('node', NULL, array(
      'import_on_create' => FALSE,
    ));

    // Set source file to import.
    $edit = array(
      'feeds[FeedsHTTPFetcher][source]' => $source_url,
    );
    $this
      ->drupalPost('import/node', $edit, t('Schedule import'));

    // Ensure that no nodes have been created yet.
    $this
      ->assertNodeCount(0, 'No nodes have been created yet (actual: @count).');
  }

  /**
   * Returns the file in the Feeds in_progress directory.
   *
   * @return object
   *   The found file.
   *
   * @throws Exception
   *   In case no file was found, so the test can abort without issuing a fatal
   *   error.
   */
  protected function getInProgressFile() {

    // Assert that a file exists in the in_progress dir.
    $files = file_scan_directory('private://feeds/in_progress', '/.*/');
    debug($files);
    $this
      ->assertEqual(1, count($files), 'The feeds "in progress" dir contains one file.');
    if (!count($files)) {

      // Abort test.
      throw new Exception('File not found.');
    }
    return reset($files);
  }

  /**
   * Test the Feed URL form.
   */
  public function testFormValidation() {

    // Set up an importer.
    $id = drupal_strtolower($this
      ->randomName());
    $this
      ->createImporterConfiguration($this
      ->randomString(), $id);

    // Check that by default, we add http:// to the front of the URL.
    $edit = array(
      'feeds[FeedsHTTPFetcher][source]' => 'example.com',
    );
    $this
      ->drupalPost('import/' . $id, $edit, t('Import'));
    $this
      ->assertText(t('There are no new nodes.'));
    $this
      ->assertFieldByName('feeds[FeedsHTTPFetcher][source]', 'http://example.com');
    $this
      ->setSettings($id, 'FeedsHTTPFetcher', array(
      'auto_scheme' => 'feed',
    ));
    $this
      ->drupalPost('import/' . $id, $edit, t('Import'));
    $this
      ->assertText(t('There are no new nodes.'));
    $this
      ->assertFieldByName('feeds[FeedsHTTPFetcher][source]', 'feed://example.com');
    $this
      ->setSettings($id, 'FeedsHTTPFetcher', array(
      'auto_scheme' => '',
    ));
    $this
      ->drupalPost('import/' . $id, $edit, t('Import'));
    $this
      ->assertText(t('The URL example.com is invalid.'));
    $this
      ->assertFieldByName('feeds[FeedsHTTPFetcher][source]', 'example.com');
  }

  /**
   * Tests if the result of a http request can be cached on the file system.
   *
   * When a first request is made, the data is retrieved from the given source
   * url and cached on the file system.
   * On the second request, send to the same source url, the HTTP header
   * "If-Modified-Since" is set. This should result into a 304 HTTP status from
   * the source, as the contents did not change in between. In such case, the
   * data should be retrieved from the cache.
   */
  public function testHttpRequestUsingFileCache() {

    // Include http request functions.
    feeds_include_library('http_request.inc', 'http_request');

    // First request.
    $url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $result = feeds_http_request($url);

    // Assert that the first request was successful and was not retrieved from
    // cache.
    $this
      ->assertEqual(200, $result->code, 'Request status code is 200.');
    $this
      ->assertTrue(empty($result->from_cache), 'Request was not retrieved from cache.');

    // Assert that a file was created.
    $file_url = 'private://feeds/cache/' . hash('sha256', $url);
    $this
      ->assertTrue(file_exists($file_url), format_string('The file @file_url exists.', array(
      '@file_url' => $file_url,
    )));

    // Reset feeds_http_request() static cache.
    drupal_static_reset('feeds_http_request');

    // Write some garbage to the cached file to ensure that the cache is
    // retrieved from that file.
    $garbage = static::randomString(100);
    file_put_contents($file_url, $garbage);

    // Second request.
    $result2 = feeds_http_request($url);

    // Assert that the second request was successful and was retrieved from
    // cache.
    $this
      ->assertEqual(200, $result2->code, 'Request status code is 200.');
    $this
      ->assertTrue(!empty($result2->from_cache), 'Request was retrieved from cache.');
    $this
      ->assertEqual($garbage, $result2->data, 'The cache came from the file cache.');

    // Assert that the file is removed when caches are cleared.
    drupal_flush_all_caches();
    $this
      ->assertFalse(file_exists($file_url), format_string('The file @file_url no longer exists.', array(
      '@file_url' => $file_url,
    )));
  }

  /**
   * Tests if the source is refetched when the cached file is manually removed.
   *
   * A call to feeds_http_request() should always get us data.
   */
  public function testRefetchWhenCachedFileIsRemoved() {

    // Include http request functions.
    feeds_include_library('http_request.inc', 'http_request');

    // First request.
    $url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $result1 = feeds_http_request($url);

    // Assert that the first request was successful and was not retrieved from
    // cache.
    $this
      ->assertEqual(200, $result1->code, 'Request status code is 200.');
    $this
      ->assertTrue(empty($result1->from_cache), 'Request was not retrieved from cache.');

    // Reset feeds_http_request() static cache.
    drupal_static_reset('feeds_http_request');

    // Write some garbage to the cached file to ensure that the cache is
    // retrieved from that file.
    $file_url = 'private://feeds/cache/' . hash('sha256', $url);
    $garbage = static::randomString(100);
    file_put_contents($file_url, $garbage);

    // Second request.
    $result2 = feeds_http_request($url);

    // Assert that the second request was successful and was retrieved from
    // cache.
    $this
      ->assertEqual(200, $result2->code, 'Request status code is 200.');
    $this
      ->assertTrue(!empty($result2->from_cache), 'Request was retrieved from cache.');
    $this
      ->assertEqual($garbage, $result2->data, 'The cache came from the file cache.');

    // Now remove the cached file.
    drupal_unlink($file_url);
    $this
      ->assertFalse(file_exists($file_url), format_string('The file @file_url no longer exists.', array(
      '@file_url' => $file_url,
    )));

    // Third request.
    $result3 = feeds_http_request($url);

    // Assert that the data is refetched, even though the source hasn't changed.
    $this
      ->assertEqual(200, $result3->code, 'Request status code is 200.');
    $this
      ->assertTrue(empty($result3->from_cache), 'Request was not retrieved from cache.');
    $this
      ->assertEqual($result1->data, $result3->data, 'Data is available on the response.');
  }

  /**
   * Tests that the source isn't fetched twice during the same request.
   */
  public function testNoRefetchOnSameRequest() {

    // Include http request functions.
    feeds_include_library('http_request.inc', 'http_request');

    // First request.
    $url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $result1 = feeds_http_request($url);

    // Set flag that the source has changed.
    variable_set('feeds_tests_nodes_changed', TRUE);

    // Second request.
    $result2 = feeds_http_request($url);

    // Assert that the result is exactly the same.
    $this
      ->assertEqual($result1->data, $result2->data, 'The data was retrieved from cache.');

    // Assert that the data *is* refetched (and different) after a cache clear.
    drupal_flush_all_caches();
    drupal_static_reset();
    $result3 = feeds_http_request($url);
    $this
      ->assertNotEqual($result1->data, $result3->data, 'The data is refetched.');
  }

  /**
   * Tests if the data is not cached when the option for caching is disabled.
   */
  public function testHTTPCacheDisabled() {
    $this
      ->setUpImporter();

    // Disable caching HTTP request result.
    $this
      ->setSettings('node', 'FeedsHTTPFetcher', array(
      'cache_http_result' => FALSE,
    ));
    $source_url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $edit = array(
      'feeds[FeedsHTTPFetcher][source]' => $source_url,
    );
    $this
      ->drupalPost('import/node', $edit, t('Import'));
    $this
      ->assertText('Created 9 nodes');

    // Assert that no cache entries were created.
    $number_of_cache_entries = db_query('SELECT COUNT(cid) FROM {cache_feeds_http}')
      ->fetchField();
    $this
      ->assertEqual(0, $number_of_cache_entries, format_string('No cache entries were created in the cache_feeds_http table (actual: @actual).', array(
      '@actual' => $number_of_cache_entries,
    )));

    // Assert that no cache file was created.
    $file_url = 'private://feeds/cache/' . hash('sha256', $source_url);
    $this
      ->assertFalse(file_exists($file_url), format_string('The file @file_url does not exist.', array(
      '@file_url' => $file_url,
    )));
  }

  /**
   * Tests if the data is cached on the file system even when a different cache
   * class is used.
   *
   * This can happen when using Memcache or Redis for all cache bins.
   */
  public function testHTTPCacheOverride() {

    // Revert back to the default cache class.
    variable_set('cache_class_cache_feeds_http', 'DrupalDatabaseCache');

    // Import. We cannot test with a simple feeds_http_request() call here,
    // because there is no way to override a cache class on a single request.
    // @see _cache_get_object().
    $this
      ->setUpImporter();
    $source_url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $edit = array(
      'feeds[FeedsHTTPFetcher][source]' => $source_url,
    );
    $this
      ->drupalPost('import/node', $edit, t('Import'));
    $this
      ->assertText('Created 9 nodes');

    // Assert that the raw data is not saved in the database.
    $count = db_select('cache_feeds_http')
      ->condition('data', '%Title,Body,published,GUID%', 'LIKE')
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertEqual(0, $count, 'Raw source was not saved in the database.');

    // Assert that a file was created.
    $file_url = 'private://feeds/cache/' . hash('sha256', $source_url);
    $this
      ->assertTrue(file_exists($file_url), format_string('The file @file_url exists.', array(
      '@file_url' => $file_url,
    )));
  }

  /**
   * Tests if cached files are cleaned up even when a different cache class is
   * used.
   */
  public function testCachedFilesCleanupOnHTTPCacheOverride() {

    // Revert back to the default cache class.
    variable_set('cache_class_cache_feeds_http', 'DrupalDatabaseCache');

    // Create a real cached file by performing an import.
    $this
      ->setUpImporter();
    $source_url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $edit = array(
      'feeds[FeedsHTTPFetcher][source]' => $source_url,
    );
    $this
      ->drupalPost('import/node', $edit, t('Import'));
    $this
      ->assertText('Created 9 nodes');
    $file_url_with_cache_record = 'private://feeds/cache/' . hash('sha256', $source_url);

    // Write a dummy cached file.
    $dir = 'private://feeds/cache';
    $file_url_no_cache_record = $dir . '/abc123';
    file_prepare_directory($dir, FILE_CREATE_DIRECTORY);
    file_put_contents($file_url_no_cache_record, static::randomString());

    // Trigger cleanup of orphaned cached files.
    variable_del('feeds_sync_cache_feeds_http_last_check');
    $this
      ->cronRun();

    // Assert that the dummy cached file has been cleaned up and the other file
    // still exists.
    $this
      ->assertFalse(file_exists($file_url_no_cache_record), format_string('The file @file_url no longer exists.', array(
      '@file_url' => $file_url_no_cache_record,
    )));
    $this
      ->assertTrue(file_exists($file_url_with_cache_record), format_string('The file @file_url still exists.', array(
      '@file_url' => $file_url_with_cache_record,
    )));
  }

  /**
   * Tests if the cron task for cleaning up cached files are run one at a time.
   */
  public function testCachedFilesCleanupQueue() {
    $queue = DrupalQueue::get('feeds_sync_cache_feeds_http');

    // First, make sure that a queue task is only ran every six hours.
    variable_set('feeds_sync_cache_feeds_http_last_check', REQUEST_TIME);

    // Run cron without executing the queue tasks.
    feeds_cron();

    // Assert that no task was created for cleaning up the files.
    $this
      ->assertEqual(0, $queue
      ->numberOfItems(), 'No task was created for the feeds_sync_cache_feeds_http queue.');

    // Unset last check and run cron.
    variable_del('feeds_sync_cache_feeds_http_last_check');
    feeds_cron();

    // Assert that one task was created for cleaning up the files and that the
    // variable for the last check was updated.
    $this
      ->assertEqual(1, $queue
      ->numberOfItems(), 'One task was created for the feeds_sync_cache_feeds_http queue.');
    $this
      ->assertEqual(REQUEST_TIME, variable_get('feeds_sync_cache_feeds_http_last_check'));

    // Unset last check and run cron again.
    variable_del('feeds_sync_cache_feeds_http_last_check');
    feeds_cron();

    // Assert that there still is one task.
    $this
      ->assertEqual(1, $queue
      ->numberOfItems(), 'One task exists for the feeds_sync_cache_feeds_http queue.');
    $this
      ->assertEqual(REQUEST_TIME, variable_get('feeds_sync_cache_feeds_http_last_check'));
  }

  /**
   * Tests if a source is not refetched on a second import when the source did
   * not change.
   */
  public function testSourceCaching() {
    $this
      ->setUpImporter();
    $source_url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $edit = array(
      'feeds[FeedsHTTPFetcher][source]' => $source_url,
    );
    $this
      ->drupalPost('import/node', $edit, t('Import'));
    $this
      ->assertText('Created 9 nodes');

    // Ensure that the fetched content was cached in a file.
    $file_url = 'private://feeds/cache/' . hash('sha256', $source_url);
    $this
      ->assertTrue(file_exists($file_url), format_string('The file @file_url exists.', array(
      '@file_url' => $file_url,
    )));

    // Overwrite cached file, change one item.
    $csv = file_get_contents($file_url);
    $lines = explode("\n", $csv);
    $lines[3] = '"Nam liber tempor","CHANGED IN CACHED FILE",1151766000,1';
    $csv = implode("\n", $lines);
    $this
      ->verbose('<pre>' . $csv . '</pre>');
    file_put_contents($file_url, $csv);

    // Re-import file. Ensure that the data from the cache was used.
    $this
      ->drupalPost('import/node', $edit, t('Import'));
    $this
      ->assertText('Updated 1 node');

    // Assert that node 3 had changed.
    $node = node_load(3);
    $this
      ->assertEqual('Nam liber tempor', $node->title);
    $this
      ->assertEqual('CHANGED IN CACHED FILE', $node->body[LANGUAGE_NONE][0]['value']);
  }

  /**
   * Tests if the source is refetched on a second import when the source
   * changed.
   */
  public function testChangedSource() {
    $this
      ->setUpImporter();
    $source_url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $edit = array(
      'feeds[FeedsHTTPFetcher][source]' => $source_url,
    );
    $this
      ->drupalPost('import/node', $edit, t('Import'));
    $this
      ->assertText('Created 9 nodes');

    // Ensure that the fetched content was cached in a file.
    $file_url = 'private://feeds/cache/' . hash('sha256', $source_url);
    $this
      ->assertTrue(file_exists($file_url), format_string('The file @file_url exists.', array(
      '@file_url' => $file_url,
    )));

    // Overwrite cached file, change one item.
    $csv = file_get_contents($file_url);
    $lines = explode("\n", $csv);
    $lines[3] = '"Nam liber tempor","CHANGED IN CACHED FILE",1151766000,1';
    $csv = implode("\n", $lines);
    $this
      ->verbose('<pre>' . $csv . '</pre>');
    file_put_contents($file_url, $csv);

    // Set flag that the source has changed.
    variable_set('feeds_tests_nodes_changed', TRUE);

    // Re-import file. Ensure that the content was refetched.
    $this
      ->drupalPost('import/node', $edit, t('Import'));
    $this
      ->assertText('Updated 2 nodes');

    // Assert that node 1 and 4 changed.
    $node = node_load(1);
    $this
      ->assertEqual('Ut wisi enim ad minim veniam', $node->title);
    $this
      ->assertEqual('CHANGED IN SOURCE', $node->body[LANGUAGE_NONE][0]['value']);
    $node = node_load(4);
    $this
      ->assertEqual('Typi non habent', $node->title);
    $this
      ->assertEqual('CHANGED IN SOURCE', $node->body[LANGUAGE_NONE][0]['value']);

    // Assert that node 3 had NOT changed.
    $node = node_load(3);
    $this
      ->assertEqual('Nam liber tempor', $node->title);
    $this
      ->assertNotEqual('CHANGED IN CACHED FILE', $node->body[LANGUAGE_NONE][0]['value']);
  }

  /**
   * Tests that a non-writable cache directory does not result into fatal
   * errors.
   */
  public function testNonWritableCacheDirectory() {

    // Set the cache directory to a non-writable directory.
    variable_set('feeds_http_file_cache_dir', 'file://non-writeable-dir/feeds');
    $this
      ->setUpImporter();
    $source_url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $edit = array(
      'feeds[FeedsHTTPFetcher][source]' => $source_url,
    );
    $this
      ->drupalPost('import/node', $edit, t('Import'));

    // Assert that a message is being displayed and that we are back on the
    // import form.
    $this
      ->assertText("The feeds cache directory (file://non-writeable-dir/feeds) either cannot be created or is not writable. You can change the cache directory by setting the 'feeds_http_file_cache_dir' variable.");
    $this
      ->assertFieldByName('feeds[FeedsHTTPFetcher][source]', $source_url);
  }

  /**
   * Tests importing source that needs multiple cron runs.
   *
   * Make sure that:
   * - The content is not saved in the feeds_source table.
   * - That the source is not refetched while the import has not completed yet.
   */
  public function testImportSourceWithMultipleCronRuns() {
    $source_url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));
    $this
      ->setUpMultipleCronRuns($source_url);

    // Run cron. Five nodes should be imported.
    $this
      ->cronRun();

    // Assert that only one file was created in the in_progress dir.
    $this
      ->getInProgressFile();

    // Assert that five nodes have been created now.
    $this
      ->assertNodeCount(5);

    // Assert that the content is *not* saved in the feeds_source table.
    $source = db_select('feeds_source')
      ->fields('feeds_source', array())
      ->condition('id', 'node')
      ->execute()
      ->fetch();
    $this
      ->assertTrue(strpos($source->fetcher_result, 'Title,Body,published,GUID') === FALSE, 'The content has not been saved in the feeds_source table.');

    // Now change the source to test if the source is not refetched while the
    // import hasn't been finished yet. The following is different:
    // - Items 1 and 4 changed.
    // - Items 2 and 7 were removed.
    variable_set('feeds_tests_nodes_changed', TRUE);

    // Run cron again. Another four nodes should be imported.
    $this
      ->cronRun();
    $this
      ->assertNodeCount(9);

    // Check if the imported nodes match that from the original source.
    $node = node_load(1);
    $this
      ->assertEqual('Ut wisi enim ad minim veniam', $node->title);
    $this
      ->assertTrue(strpos($node->body[LANGUAGE_NONE][0]['value'], 'CHANGE') === FALSE);
    $node = node_load(4);
    $this
      ->assertEqual('Typi non habent', $node->title);
    $this
      ->assertTrue(strpos($node->body[LANGUAGE_NONE][0]['value'], 'CHANGE') === FALSE);
    $node = node_load(7);
    $this
      ->assertEqual('Claritas est etiam', $node->title);
    $node = node_load(9);
    $this
      ->assertEqual('Eodem modo typi', $node->title);
  }

  /**
   * Tests that an import is aborted when the temporary file in the in_progress
   * dir is removed.
   */
  public function testAbortImportWhenTemporaryFileIsDeleted() {
    $source_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/many_nodes_ordered.csv';
    $this
      ->setUpMultipleCronRuns($source_url);

    // Run the first cron.
    $this
      ->cronRun();

    // Assert that five nodes have been created.
    $this
      ->assertNodeCount(5);

    // Remove file.
    $file = $this
      ->getInProgressFile();
    drupal_unlink($file->uri);

    // Run cron again and assert that no more nodes are imported.
    $this
      ->cronRun();
    $this
      ->assertNodeCount(5);
  }

  /**
   * Tests that FeedsHTTPFetcherResult::getRaw() always returns the same result
   * for the same instance, even when caches are cleared in between.
   *
   * Parsers can call this method multiple times on separate requests. When an
   * import did not complete in one run, the source should never be refetched
   * when calling getRaw().
   *
   * When an import is restarted, a new FeedsHTTPFetcherResult is created and in
   * that case the source *should* be refetched.
   */
  public function testFeedsHTTPFetcherResultGetRaw() {

    // Set source file to fetch.
    $source_url = url('testing/feeds/nodes.csv', array(
      'absolute' => TRUE,
    ));

    // Retrieve the raw content.
    $fetcher_result1 = new FeedsHTTPFetcherResult($source_url);
    $raw1 = $fetcher_result1
      ->getRaw();

    // Simulate the case where the import is picked up later. In between caches
    // were cleared, the source was changed by the source provider and the
    // fetcher result was serialized and saved in the database.
    $fetcher_result_serialized = serialize($fetcher_result1);

    // Assert that the raw content was not serialized.
    $this
      ->assertTrue(strpos($fetcher_result_serialized, $raw1) === FALSE, 'The raw data was not saved in the serialized fetcher result.');
    variable_set('feeds_tests_nodes_changed', TRUE);
    drupal_static_reset();
    drupal_flush_all_caches();

    // And retrieve the raw content again.
    $fetcher_result2 = unserialize($fetcher_result_serialized);
    $raw2 = $fetcher_result2
      ->getRaw();

    // Assert that the content didn't change.
    $this
      ->assertEqual($raw1, $raw2, 'The fetcher result returned the same raw data.');

    // Simulate the case where the import has restarted and ensure that the
    // contents *do* change in that case.
    $fetcher_result3 = new FeedsHTTPFetcherResult($source_url);
    $raw3 = $fetcher_result3
      ->getRaw();

    // Assert that the content changed.
    $this
      ->assertNotEqual($raw1, $raw3, 'A new fetcher result returned the other raw data.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1
FeedsFileHTTPTestCase::getInfo public static function
FeedsFileHTTPTestCase::getInProgressFile protected function Returns the file in the Feeds in_progress directory.
FeedsFileHTTPTestCase::setUp public function Sets up a Drupal site for running functional and integration tests. Overrides FeedsWebTestCase::setUp
FeedsFileHTTPTestCase::setUpImporter public function Setup importer to import items from testing/feeds/nodes.csv.
FeedsFileHTTPTestCase::setUpMultipleCronRuns protected function Configures the evironment so that multiple cron runs are needed to complete an import.
FeedsFileHTTPTestCase::testAbortImportWhenTemporaryFileIsDeleted public function Tests that an import is aborted when the temporary file in the in_progress dir is removed.
FeedsFileHTTPTestCase::testCachedFilesCleanupOnHTTPCacheOverride public function Tests if cached files are cleaned up even when a different cache class is used.
FeedsFileHTTPTestCase::testCachedFilesCleanupQueue public function Tests if the cron task for cleaning up cached files are run one at a time.
FeedsFileHTTPTestCase::testChangedSource public function Tests if the source is refetched on a second import when the source changed.
FeedsFileHTTPTestCase::testFeedsHTTPFetcherResultGetRaw public function Tests that FeedsHTTPFetcherResult::getRaw() always returns the same result for the same instance, even when caches are cleared in between.
FeedsFileHTTPTestCase::testFormValidation public function Test the Feed URL form.
FeedsFileHTTPTestCase::testHTTPCacheDisabled public function Tests if the data is not cached when the option for caching is disabled.
FeedsFileHTTPTestCase::testHTTPCacheOverride public function Tests if the data is cached on the file system even when a different cache class is used.
FeedsFileHTTPTestCase::testHttpRequestUsingFileCache public function Tests if the result of a http request can be cached on the file system.
FeedsFileHTTPTestCase::testImportSourceWithMultipleCronRuns public function Tests importing source that needs multiple cron runs.
FeedsFileHTTPTestCase::testNonWritableCacheDirectory public function Tests that a non-writable cache directory does not result into fatal errors.
FeedsFileHTTPTestCase::testNoRefetchOnSameRequest public function Tests that the source isn't fetched twice during the same request.
FeedsFileHTTPTestCase::testRefetchWhenCachedFileIsRemoved public function Tests if the source is refetched when the cached file is manually removed.
FeedsFileHTTPTestCase::testSourceCaching public function Tests if a source is not refetched on a second import when the source did not change.
FeedsWebTestCase::$profile protected property The profile to install as a basis for testing. Overrides DrupalWebTestCase::$profile 1
FeedsWebTestCase::absolute public function Absolute path to Drupal root.
FeedsWebTestCase::absolutePath public function Get the absolute directory path of the feeds module.
FeedsWebTestCase::addMappings public function Adds mappings to a given configuration.
FeedsWebTestCase::assertFieldByXPath protected function Overrides DrupalWebTestCase::assertFieldByXPath(). Overrides DrupalWebTestCase::assertFieldByXPath
FeedsWebTestCase::assertFieldDisabled protected function Asserts that a field in the current page is disabled.
FeedsWebTestCase::assertFieldEnabled protected function Asserts that a field in the current page is enabled.
FeedsWebTestCase::assertNodeCount protected function Asserts that the given number of nodes exist.
FeedsWebTestCase::assertPlugins public function Assert a feeds configuration's plugins.
FeedsWebTestCase::changeNodeAuthor protected function Changes the author of a node and asserts the change in the UI.
FeedsWebTestCase::copyDir public function Copies a directory.
FeedsWebTestCase::createFeedNode public function Create a test feed node. Test user has to have sufficient permissions:.
FeedsWebTestCase::createFeedNodes public function Batch create a variable amount of feed nodes. All will have the same URL configured.
FeedsWebTestCase::createImporterConfiguration public function Create an importer configuration.
FeedsWebTestCase::downloadExtractSimplePie public function Download and extract SimplePIE.
FeedsWebTestCase::editFeedNode public function Edit the configuration of a feed node to test update behavior.
FeedsWebTestCase::generateOPML public function Generate an OPML test feed.
FeedsWebTestCase::getCurrentMappings public function Gets an array of current mappings from the feeds_importer config.
FeedsWebTestCase::getNid public function Helper function, retrieves node id from a URL.
FeedsWebTestCase::importFile public function Import a file through the import form. Assumes FeedsFileFetcher in place.
FeedsWebTestCase::importURL public function Import a URL through the import form. Assumes FeedsHTTPFetcher in place.
FeedsWebTestCase::mappingExists public function Determines if a mapping exists for a given importer.
FeedsWebTestCase::removeMappings public function Remove mappings from a given configuration.
FeedsWebTestCase::setPlugin public function Choose a plugin for a importer configuration and assert it.
FeedsWebTestCase::setSettings public function Set importer or plugin settings.