You are here

class FeedAPI_Aggregator_Tests in FeedAPI 5

Class for testing feedapi_aggregator. It also tests FeedAPI and Common Syndication Parser.

Hierarchy

Expanded class hierarchy of FeedAPI_Aggregator_Tests

File

feedapi_aggregator/tests/feedapi_aggregator.module.test, line 7

View source
class FeedAPI_Aggregator_Tests extends DrupalTestCase {
  function get_info() {
    return array(
      'name' => 'FeedAPI Aggregator basic functions',
      'desc' => "Refresh a feed and find out if it's okay. Uses Common Syndication Parser for parsing and downloading.",
      'group' => 'FeedAPI',
    );
  }

  /**
   * Add a content-type, create a feed and refresh it.
   * Check if everything seems ok
   * Delete the feed
   * Check if the rubbish is purged as well.
   * @todo currently it doesn't test the categorizing facility of feedapi_aggregator
   */
  function testFeedAPI_Aggregator_Refresh_Feed() {

    // Create a new content-type for creating the feed node
    $info->type = 'aggreg_' . $this
      ->randomName();
    $info->name = 'Feed' . str_replace('_', ' ', $this
      ->randomName());
    $info->description = t('Aggregates RSS or Atom feeds.');
    $info->module = 'node';
    $info->has_title = TRUE;
    $info->title_label = t('Title');
    $info->has_body = TRUE;
    $info->body_label = t('Body');
    $info->min_word_count = 0;
    $info->custom = TRUE;
    node_type_save($info);

    // Adding default FeedAPI settings
    variable_set('feedapi_settings_' . $info->type, unserialize('a:3:{s:7:"enabled";s:1:"1";s:7:"parsers";a:2:{s:16:"parser_simplepie";a:3:{s:7:"enabled";s:1:"0";s:6:"weight";s:1:"0";s:4:"test";s:1:"3";}s:25:"parser_common_syndication";a:3:{s:7:"enabled";s:1:"1";s:6:"weight";s:2:"-2";s:6:"tester";s:1:"3";}}s:10:"processors";a:2:{s:12:"feedapi_node";a:4:{s:6:"weight";s:1:"0";s:12:"content_type";s:5:"story";s:9:"node_date";s:4:"feed";s:7:"promote";s:1:"3";}s:18:"feedapi_aggregator";a:3:{s:7:"enabled";s:1:"1";s:6:"weight";s:1:"0";s:5:"block";s:1:"3";}}}'));

    // Login with a user who has FeedAPI rights
    $user = $this
      ->drupalCreateUserRolePerm(array(
      'administer feedapi',
      'advanced feedapi options',
      'administer nodes',
      'access news feeds',
      "create {$info->type} content",
    ));
    $this
      ->drupalLoginUser($user);

    // Create the feed node
    // Make the URL unique. It's not impossible that someone add this feed URL to the DB prior.
    $feed_url = "http://novaak.net/rss.xml?" . $this
      ->randomName();
    $edit = array(
      'feedapi[feedapi_url]' => $feed_url,
    );
    $this
      ->drupalPostRequest('node/add/' . $info->type, $edit, 'Submit');
    $this
      ->assertText(t('Link to site'), 'The feed node is created.');

    // Check if the entry is in the DB
    $nid = db_result(db_query("SELECT nid FROM {feedapi} WHERE url = '%s'", $feed_url));
    $this
      ->assertEqual(is_numeric($nid), TRUE, 'The feed node is in the database');
    $feed_node = node_load(array(
      'nid' => $nid,
    ));
    $this
      ->assertEqual(is_object($feed_node->feed), TRUE, 'The feed can be loaded.');

    // Disable feed item expiring
    $settings = feedapi_get_settings($info->type, $nid);
    $settings['items_delete'] = FEEDAPI_NEVER_DELETE_OLD;
    _feedapi_store_settings(array(
      'nid' => $nid,
    ), $settings);

    // Source page before refreshing
    $this
      ->drupalGet(url("aggregator/sources/{$nid}", NULL, NULL, TRUE));
    $this
      ->assertText("Currently there is no news item in this category/feed.", 'The source\'s page is empty before refreshing.');

    // Refresh the feed
    $this
      ->drupalGet(url("node/{$nid}/refresh", NULL, NULL, TRUE));
    $this
      ->assertText("11 new item(s) were saved. 0 existing item(s) were updated", 'The proper number of items were created.');
    $this
      ->drupalGet(url("aggregator/sources/{$nid}", NULL, NULL, TRUE));
    $this
      ->assertText("This is the Openads presentation that we missed in Barcelona", 'The third news title can be read at the source page.');

    // Check the feed items
    $num_of_items = db_result(db_query("SELECT COUNT(*) FROM {feedapi_aggregator_item} WHERE feed_nid = %d", $nid));
    $this
      ->assertEqual($num_of_items, 11, 'The proper number of items can be found in the database.');

    // Admin overview page loads and the feed can be found there with the correct number of items
    $this
      ->drupalGet(url("admin/content/feed", NULL, NULL, TRUE));
    $this
      ->assertText('DrupalCon Barcelona 2007 -', 'The admin overview page contains the feed title.');

    // Temporary solution. Now purging is commented out in feedapi.module because of possible timeouts
    feedapi_invoke('purge', $feed_node->feed);

    // Remove the unwanted rubbish
    node_delete($nid);

    // Check if the news items are deleted as well
    $item_remain = db_result(db_query("SELECT COUNT(*) FROM {feedapi_aggregator_item} WHERE feed_nid = %d", $nid));
    $this
      ->assertEqual($item_remain, 0, 'All the news items are deleted from the database.');
    node_types_rebuild();

    // Remove temporary content-type
    node_type_delete($info->type);

    // Make sure that the variable if loaded from the DB
    variable_init();

    // Check if the type deletion occurs variable deletion
    $this
      ->assertIdentical(FALSE, variable_get('feedapi_settings_' . $info->type, FALSE), 'The content-type\'s setting variable is successfully deleted.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$_cleanupModules property
DrupalTestCase::$_cleanupRoles property
DrupalTestCase::$_cleanupUsers property
DrupalTestCase::$_cleanupVariables property
DrupalTestCase::$_content property
DrupalTestCase::assertCopy function Will trigger a pass if both parameters refer to different objects. Fail otherwise.
DrupalTestCase::assertEqual function Will trigger a pass if the two parameters have the same value only. Otherwise a fail.
DrupalTestCase::assertError function Confirms that an error has occurred and optionally that the error text matches exactly.
DrupalTestCase::assertErrorPattern function Confirms that an error has occurred and that the error text matches a Perl regular expression.
DrupalTestCase::assertIdentical function Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail.
DrupalTestCase::assertIsA function Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct.
DrupalTestCase::assertNoErrors function Confirms that no errors have occurred so far in the test method.
DrupalTestCase::assertNotA function Type and class mismatch test. Will pass if class name or underling type does not match the one specified.
DrupalTestCase::assertNotEqual function Will trigger a pass if the two parameters have a different value. Otherwise a fail.
DrupalTestCase::assertNotIdentical function Will trigger a pass if the two parameters have the different value or different type.
DrupalTestCase::assertNotNull function Will be true if the value is set.
DrupalTestCase::assertNoUnwantedPattern function Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found.
DrupalTestCase::assertNoUnwantedRaw function Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise.
DrupalTestCase::assertNull function Will be true if the value is null.
DrupalTestCase::assertReference function Will trigger a pass if both parameters refer to the same object. Fail otherwise.
DrupalTestCase::assertWantedPattern function Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise.
DrupalTestCase::assertWantedRaw function Will trigger a pass if the raw text is found on the loaded page Fail otherwise.
DrupalTestCase::clickLink function Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does…
DrupalTestCase::drupalCheckAuth function @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site.
DrupalTestCase::drupalCreateRolePerm function Create a role / perm combination specified by permissions
DrupalTestCase::drupalCreateUserRolePerm function Creates a user / role / permissions combination specified by permissions
DrupalTestCase::drupalGet function @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::drupalGetContent function @TODO: needs documentation
DrupalTestCase::drupalLoginUser function Logs in a user with the internal browser
DrupalTestCase::drupalModuleDisable function Disables a drupal module
DrupalTestCase::drupalModuleEnable function Enables a drupal module
DrupalTestCase::drupalPostRequest function Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser
DrupalTestCase::drupalRawPost function @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::DrupalTestCase function
DrupalTestCase::drupalVariableSet function Set a druapl variable and keep track of the changes for tearDown()
DrupalTestCase::randomName function Generates a random string, to be used as name or whatever
DrupalTestCase::run function Just some info for the reporter
DrupalTestCase::tearDown function tearDown implementation, setting back switched modules etc 1
FeedAPI_Aggregator_Tests::get_info function
FeedAPI_Aggregator_Tests::testFeedAPI_Aggregator_Refresh_Feed function Add a content-type, create a feed and refresh it. Check if everything seems ok Delete the feed Check if the rubbish is purged as well. @todo currently it doesn't test the categorizing facility of feedapi_aggregator