aggregator.test 22.1 KB
Newer Older
1 2 3
<?php
// $Id$

4 5 6 7 8
/**
 * @file
 * Creates tests for aggregator module.
 */

9 10
class AggregatorTestCase extends DrupalWebTestCase {
  function setUp() {
11
    parent::setUp('aggregator', 'aggregator_test');
12
    $web_user = $this->drupalCreateUser(array('administer news feeds', 'access news feeds', 'create article content'));
13 14 15 16
    $this->drupalLogin($web_user);
  }

  /**
17
   * Create an aggregator feed (simulate form submission on admin/settings/aggregator/add/feed).
18
   *
19 20 21 22
   * @param $feed_url
   *   If given, feed will be created with this URL, otherwise /rss.xml will be used.
   * @return $feed
   *   Full feed object if possible.
23
   *
24
   * @see getFeedEditArray()
25
   */
26 27
  function createFeed($feed_url = NULL) {
    $edit = $this->getFeedEditArray($feed_url);
28
    $this->drupalPost('admin/settings/aggregator/add/feed', $edit, t('Save'));
29 30
    $this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title'])), t('The feed !name has been added.', array('!name' => $edit['title'])));

31
    $feed = db_query("SELECT *  FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $edit['title'], ':url' => $edit['url']))->fetch();
32 33 34 35 36 37 38
    $this->assertTrue(!empty($feed), t('The feed found in database.'));
    return $feed;
  }

  /**
   * Delete an aggregator feed.
   *
39 40
   * @param $feed
   *   Feed object representing the feed.
41 42
   */
  function deleteFeed($feed) {
43
    $this->drupalPost('admin/settings/aggregator/edit/feed/' . $feed->fid, array(), t('Delete'));
44 45 46 47 48 49
    $this->assertRaw(t('The feed %title has been deleted.', array('%title' => $feed->title)), t('Feed deleted successfully.'));
  }

  /**
   * Return a randomly generated feed edit array.
   *
50 51 52 53
   * @param $feed_url
   *   If given, feed will be created with this URL, otherwise /rss.xml will be used.
   * @return
   *   A feed array.
54
   */
55
  function getFeedEditArray($feed_url = NULL) {
56
    $feed_name = $this->randomName(10);
57
    if (!$feed_url) {
58 59 60 61
      $feed_url = url('rss.xml', array(
        'query' => 'feed=' . $feed_name,
        'absolute' => TRUE,
      ));
62
    }
63 64 65 66 67 68 69 70
    $edit = array(
      'title' => $feed_name,
      'url' => $feed_url,
      'refresh' => '900',
    );
    return $edit;
  }

71 72
  /**
   * Return the count of the randomly created feed array.
73 74
   *
   * @return
75 76 77 78 79 80 81 82
   *   Number of feed items on default feed created by createFeed().
   */
  function getDefaultFeedItemCount() {
    // Our tests are based off of rss.xml, so let's find out how many elements should be related.
    $feed_count = db_query_range('SELECT COUNT(*) FROM {node} n WHERE n.promote = 1 AND n.status = 1', 0, variable_get('feed_default_items', 10))->fetchField();
    return $feed_count > 10 ? 10 : $feed_count;
  }

83
  /**
84
   * Update feed items (simulate click to admin/settings/aggregator/update/$fid).
85
   *
86 87 88 89
   * @param $feed
   *   Feed object representing the feed.
   * @param $expected_count
   *   Expected number of feed items.
90
   */
91
  function updateFeedItems(&$feed, $expected_count) {
92
    // First, let's ensure we can get to the rss xml.
93 94
    $this->drupalGet($feed->url);
    $this->assertResponse(200, t('!url is reachable.', array('!url' => $feed->url)));
95

96
    // Refresh the feed (simulated link click).
97
    $this->drupalGet('admin/settings/aggregator/update/' . $feed->fid);
98

99
    // Ensure we have the right number of items.
100
    $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid));
101 102
    $items = array();
    $feed->items = array();
103
    foreach ($result as $item) {
104 105 106
      $feed->items[] = $item->iid;
    }
    $feed->item_count = count($feed->items);
107
    $this->assertEqual($expected_count, $feed->item_count, t('Total items in feed equal to the total items in database (!val1 != !val2)', array('!val1' => $expected_count, '!val2' => $feed->item_count)));
108 109 110 111 112
  }

  /**
   * Confirm item removal from a feed.
   *
113 114
   * @param $feed
   *   Feed object representing the feed.
115 116
   */
  function removeFeedItems($feed) {
117
    $this->drupalPost('admin/settings/aggregator/remove/' . $feed->fid, array(), t('Remove items'));
118 119 120
    $this->assertRaw(t('The news items from %title have been removed.', array('%title' => $feed->title)), t('Feed items removed.'));
  }

121 122
  /**
   * Add and remove feed items and ensure that the count is zero.
123 124
   *
   * @param $feed
125
   *   Feed object representing the feed.
126
   * @param $expected_count
127 128 129 130 131 132 133 134 135 136
   *   Expected number of feed items.
   */
  function updateAndRemove($feed, $expected_count) {
    $this->updateFeedItems($feed, $expected_count);
    $this->assertText('There is new syndicated content from');
    $this->removeFeedItems($feed);
    $count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField();
    $this->assertTrue($count == 0);
  }

137 138 139
  /**
   * Pull feed categories from aggregator_category_feed table.
   *
140 141
   * @param $feed
   *   Feed object representing the feed.
142 143 144
   */
  function getFeedCategories($feed) {
    // add the categories to the feed so we can use them
145 146
    $result = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(':fid' => $feed->fid));
    foreach ($result as $category) {
147 148 149 150 151 152 153
      $feed->categories[] = $category->cid;
    }
  }

  /**
   * Check if the feed name and url is unique.
   *
154 155 156 157 158 159
   * @param $feed_name
   *   String containing the feed name to check.
   * @param $feed_url
   *   String containing the feed url to check.
   * @return
   *   TRUE if feed is unique.
160 161
   */
  function uniqueFeed($feed_name, $feed_url) {
162
    $result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed_name, ':url' => $feed_url))->fetchField();
163 164
    return (1 == $result);
  }
165 166 167 168 169 170 171 172 173 174

  /**
   * Create a valid OPML file from an array of feeds.
   *
   * @param $feeds
   *   An array of feeds.
   * @return
   *   Path to valid OPML file.
   */
  function getValidOpml($feeds) {
175 176 177 178
    // Properly escape URLs so that XML parsers don't choke on them.
    foreach ($feeds as &$feed) {
      $feed['url'] = htmlspecialchars($feed['url']);
    }
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    /**
     * Does not have an XML declaration, must pass the parser.
     */
    $opml = <<<EOF
<opml version="1.0">
  <head></head>
  <body>
    <!-- First feed to be imported. -->
    <outline text="{$feeds[0]['title']}" xmlurl="{$feeds[0]['url']}" />

    <!-- Second feed. Test string delimitation and attribute order. -->
    <outline xmlurl='{$feeds[1]['url']}' text='{$feeds[1]['title']}'/>

    <!-- Test for duplicate URL and title. -->
    <outline xmlurl="{$feeds[0]['url']}" text="Duplicate URL"/>
    <outline xmlurl="http://duplicate.title" text="{$feeds[1]['title']}"/>

    <!-- Test that feeds are only added with required attributes. -->
    <outline text="{$feeds[2]['title']}" />
    <outline xmlurl="{$feeds[2]['url']}" />
  </body>
</opml>
EOF;

    $path = file_directory_path() . '/valid-opml.xml';
204
    return file_unmanaged_save_data($opml, $path);
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
  }

  /**
   * Create an invalid OPML file.
   *
   * @return
   *   Path to invalid OPML file.
   */
  function getInvalidOpml() {
    $opml = <<<EOF
<opml>
  <invalid>
</opml>
EOF;

    $path = file_directory_path() . '/invalid-opml.xml';
221
    return file_unmanaged_save_data($opml, $path);
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
  }

  /**
   * Create a valid but empty OPML file.
   *
   * @return
   *   Path to empty OPML file.
   */
  function getEmptyOpml() {
    $opml = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<opml version="1.0">
  <head></head>
  <body>
    <outline text="Sample text" />
    <outline text="Sample text" url="Sample URL" />
  </body>
</opml>
EOF;

    $path = file_directory_path() . '/empty-opml.xml';
243
    return file_unmanaged_save_data($opml, $path);
244
  }
245 246

  function getRSS091Sample() {
247
    return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'aggregator') . '/tests/aggregator_test_rss091.xml';
248
  }
249 250 251

  function createSampleNodes() {
    // Post 5 articles.
252
    for ($i = 0; $i < 5; $i++) {
253 254
      $edit = array();
      $edit['title'] = $this->randomName();
255
      $edit['body[0][value]'] = $this->randomName();
256 257 258
      $this->drupalPost('node/add/article', $edit, t('Save'));
    }
  }
259 260 261
}

class AddFeedTestCase extends AggregatorTestCase {
262
  public static function getInfo() {
263
    return array(
264 265 266
      'name' => 'Add feed functionality',
      'description' => 'Add feed test.',
      'group' => 'Aggregator'
267 268 269 270 271 272 273 274 275 276
    );
  }

  /**
   * Create a feed, ensure that it is unique, check the source, and delete the feed.
   */
  function testAddFeed() {
    $feed = $this->createFeed();

    // Check feed data.
277
    $this->assertEqual($this->getUrl(), url('admin/settings/aggregator/add/feed', array('absolute' => TRUE)), t('Directed to correct url.'));
278 279 280
    $this->assertTrue($this->uniqueFeed($feed->title, $feed->url), t('The feed is unique.'));

    // Check feed source.
281
    $this->drupalGet('aggregator/sources/' . $feed->fid);
282 283 284 285 286 287 288 289 290
    $this->assertResponse(200, t('Feed source exists.'));
    $this->assertText($feed->title, t('Page title'));

    // Delete feed.
    $this->deleteFeed($feed);
  }
}

class UpdateFeedTestCase extends AggregatorTestCase {
291
  public static function getInfo() {
292
    return array(
293 294 295
      'name' => 'Update feed functionality',
      'description' => 'Update feed test.',
      'group' => 'Aggregator'
296 297 298 299 300 301 302
    );
  }

  /**
   * Create a feed and attempt to update it.
   */
  function testUpdateFeed() {
303 304 305
    $remamining_fields = array('title', 'url', '');
    foreach ($remamining_fields as $same_field) {
      $feed = $this->createFeed();
306

307 308 309 310 311 312
      // Get new feed data array and modify newly created feed.
      $edit = $this->getFeedEditArray();
      $edit['refresh'] =  1800; // Change refresh value.
      if (isset($feed->{$same_field})) {
        $edit[$same_field] = $feed->{$same_field};
      }
313
      $this->drupalPost('admin/settings/aggregator/edit/feed/' . $feed->fid, $edit, t('Save'));
314 315 316
      $this->assertRaw(t('The feed %name has been updated.', array('%name' => $edit['title'])), t('The feed %name has been updated.', array('%name' => $edit['title'])));

      // Check feed data.
317
      $this->assertEqual($this->getUrl(), url('admin/settings/aggregator/', array('absolute' => TRUE)));
318 319 320 321 322 323 324 325 326 327 328
      $this->assertTrue($this->uniqueFeed($edit['title'], $edit['url']), t('The feed is unique.'));

      // Check feed source.
      $this->drupalGet('aggregator/sources/' . $feed->fid);
      $this->assertResponse(200, t('Feed source exists.'));
      $this->assertText($edit['title'], t('Page title'));

      // Delete feed.
      $feed->title = $edit['title']; // Set correct title so deleteFeed() will work.
      $this->deleteFeed($feed);
    }
329 330 331 332
  }
}

class RemoveFeedTestCase extends AggregatorTestCase {
333
  public static function getInfo() {
334
    return array(
335 336 337
      'name' => 'Remove feed functionality',
      'description' => 'Remove feed test.',
      'group' => 'Aggregator'
338 339 340 341 342 343 344 345 346 347 348 349 350
    );
  }

  /**
   * Remove a feed and ensure that all it services are removed.
   */
  function testRemoveFeed() {
    $feed = $this->createFeed();

    // Delete feed.
    $this->deleteFeed($feed);

    // Check feed source.
351
    $this->drupalGet('aggregator/sources/' . $feed->fid);
352 353 354
    $this->assertResponse(404, t('Deleted feed source does not exists.'));

    // Check database for feed.
355
    $result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed->title, ':url' => $feed->url))->fetchField();
356 357 358 359 360
    $this->assertFalse($result, t('Feed not found in database'));
  }
}

class UpdateFeedItemTestCase extends AggregatorTestCase {
361
  public static function getInfo() {
362
    return array(
363 364 365
      'name' => 'Update feed item functionality',
      'description' => 'Update feed items from a feed.',
      'group' => 'Aggregator'
366 367 368 369
    );
  }

  /**
370
   * Test running "update items" from the 'admin/settings/aggregator' page.
371 372
   */
  function testUpdateFeedItem() {
373 374
    $this->createSampleNodes();

375 376 377
    // Create a feed and test updating feed items if possible.
    $feed = $this->createFeed();
    if (!empty($feed)) {
378
      $this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
379 380 381 382 383
      $this->removeFeedItems($feed);
    }

    // Delete feed.
    $this->deleteFeed($feed);
384 385 386 387

    // Test updating feed items without valid timestamp information.
    $edit = array(
      'title' => "Feed without publish timestamp",
388
      'url' => $this->getRSS091Sample(),
389
    );
390

391 392 393
    $this->drupalGet($edit['url']);
    $this->assertResponse(array(200), t('URL !url is accessible', array('!url' => $edit['url'])));

394
    $this->drupalPost('admin/settings/aggregator/add/feed', $edit, t('Save'));
395 396
    $this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title'])), t('The feed !name has been added.', array('!name' => $edit['title'])));

397
    $feed = db_query("SELECT * FROM {aggregator_feed} WHERE url = :url", array(':url' => $edit['url']))->fetchObject();
398
    $this->drupalGet('admin/settings/aggregator/update/' . $feed->fid);
399

400
    $before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField();
401 402 403

    // Sleep for 3 second.
    sleep(3);
404 405 406 407 408 409 410 411 412
    db_update('aggregator_feed')
      ->condition('fid', $feed->fid)
      ->fields(array(
        'checked' => 0,
        'hash' => '',
        'etag' => '',
        'modified' => 0,
      ))
      ->execute();
413
    $this->drupalGet('admin/settings/aggregator/update/' . $feed->fid);
414

415
    $after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField();
416 417

    $this->assertTrue($before === $after, t('Publish timestamp of feed item was not updated (!before === !after)', array('!before' => $before, '!after' => $after)));
418 419 420 421
  }
}

class RemoveFeedItemTestCase extends AggregatorTestCase {
422
  public static function getInfo() {
423
    return array(
424 425 426
      'name' => 'Remove feed item functionality',
      'description' => 'Remove feed items from a feed.',
      'group' => 'Aggregator'
427 428 429 430
    );
  }

  /**
431
   * Test running "remove items" from the 'admin/settings/aggregator' page.
432 433
   */
  function testRemoveFeedItem() {
434 435 436 437 438 439 440 441 442 443 444 445 446 447
    // Create a bunch of test feeds.
    $feed_urls = array();
    // No last-modified, no etag.
    $feed_urls[] = url('aggregator/test-feed', array('absolute' => TRUE));
    // Last-modified, but no etag.
    $feed_urls[] = url('aggregator/test-feed/1', array('absolute' => TRUE));
    // No Last-modified, but etag.
    $feed_urls[] = url('aggregator/test-feed/0/1', array('absolute' => TRUE));
    // Last-modified and etag.
    $feed_urls[] = url('aggregator/test-feed/1/1', array('absolute' => TRUE));

    foreach ($feed_urls as $feed_url) {
      $feed = $this->createFeed($feed_url);
      // Update and remove items two times in a row to make sure that removal
448
      // resets all 'modified' information (modified, etag, hash) and allows for
449 450 451 452 453 454 455
      // immediate update.
      $this->updateAndRemove($feed, 2);
      $this->updateAndRemove($feed, 2);
      $this->updateAndRemove($feed, 2);
      // Delete feed.
      $this->deleteFeed($feed);
    }
456 457 458 459
  }
}

class CategorizeFeedItemTestCase extends AggregatorTestCase {
460
  public static function getInfo() {
461
    return array(
462 463 464
      'name' => 'Categorize feed item functionality',
      'description' => 'Test feed item categorization.',
      'group' => 'Aggregator'
465 466 467 468 469 470 471 472
    );
  }

  /**
   * If a feed has a category, make sure that the children inherit that
   * categorization.
   */
  function testCategorizeFeedItem() {
473 474
    $this->createSampleNodes();

475
    // Simulate form submission on "admin/settings/aggregator/add/category".
476
    $edit = array('title' => $this->randomName(10), 'description' => '');
477
    $this->drupalPost('admin/settings/aggregator/add/category', $edit, t('Save'));
478 479
    $this->assertRaw(t('The category %title has been added.', array('%title' => $edit['title'])), t('The category %title has been added.', array('%title' => $edit['title'])));

480
    $category = db_query("SELECT * FROM {aggregator_category} WHERE title = :title", array(':title' => $edit['title']))->fetch();
481 482 483
    $this->assertTrue(!empty($category), t('The category found in database.'));

    $link_path = 'aggregator/categories/' . $category->cid;
484
    $menu_link = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $link_path))->fetch();
485 486
    $this->assertTrue(!empty($menu_link), t('The menu link associated with the category found in database.'));

487
    $feed = $this->createFeed();
488 489 490 491 492 493
    db_insert('aggregator_category_feed')
      ->fields(array(
        'cid' => $category->cid,
        'fid' => $feed->fid,
      ))
      ->execute();
494
    $this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
495
    $this->getFeedCategories($feed);
496
    $this->assertTrue(!empty($feed->categories), t('The category found in the feed.'));
497 498 499 500

    // For each category of a feed, ensure feed items have that category, too.
    if (!empty($feed->categories) && !empty($feed->items)) {
      foreach ($feed->categories as $category) {
501 502 503 504 505
        $categorized_count = db_select('aggregator_category_item')
          ->condition('iid', $feed->items, 'IN')
          ->countQuery()
          ->execute()
          ->fetchField();
506

507 508 509 510 511 512 513 514
        $this->assertEqual($feed->item_count, $categorized_count, t('Total items in feed equal to the total categorized feed items in database'));
      }
    }

    // Delete feed.
    $this->deleteFeed($feed);
  }
}
515 516

class ImportOPMLTestCase extends AggregatorTestCase {
517
  public static function getInfo() {
518
    return array(
519 520 521
      'name' => 'Import feeds from OPML functionality',
      'description' => 'Test OPML import.',
      'group' => 'Aggregator',
522 523 524 525 526 527 528
    );
  }

  /**
   * Open OPML import form.
   */
  function openImportForm() {
529
    db_delete('aggregator_category')->execute();
530

531
    $category = $this->randomName(10);
532
    $cid = db_insert('aggregator_category')
533 534 535 536 537
      ->fields(array(
        'title' => $category,
        'description' => '',
      ))
      ->execute();
538

539
    $this->drupalGet('admin/settings/aggregator/add/opml');
540 541 542 543
    $this->assertText('A single OPML document may contain a collection of many feeds.', t('Looking for help text.'));
    $this->assertFieldByName('files[upload]', '', t('Looking for file upload field.'));
    $this->assertFieldByName('remote', '', t('Looking for remote URL field.'));
    $this->assertFieldByName('refresh', '', t('Looking for refresh field.'));
544
    $this->assertFieldByName("category[$cid]", $cid, t('Looking for category field.'));
545 546 547 548 549 550
  }

  /**
   * Submit form filled with invalid fields.
   */
  function validateImportFormFields() {
551
    $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
552 553

    $form = array();
554
    $this->drupalPost('admin/settings/aggregator/add/opml', $form, t('Import'));
555 556 557 558 559 560 561
    $this->assertRaw(t('You must <em>either</em> upload a file or enter a URL.'), t('Error if no fields are filled.'));

    $path = $this->getEmptyOpml();
    $form = array(
      'files[upload]' => $path,
      'remote' => file_create_url($path),
    );
562
    $this->drupalPost('admin/settings/aggregator/add/opml', $form, t('Import'));
563 564 565
    $this->assertRaw(t('You must <em>either</em> upload a file or enter a URL.'), t('Error if both fields are filled.'));

    $form = array('remote' => 'invalidUrl://empty');
566
    $this->drupalPost('admin/settings/aggregator/add/opml', $form, t('Import'));
567 568
    $this->assertText(t('This URL is not valid.'), t('Error if the URL is invalid.'));

569
    $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
570 571 572 573 574 575 576
    $this->assertEqual($before, $after, t('No feeds were added during the three last form submissions.'));
  }

  /**
   * Submit form with invalid, empty and valid OPML files.
   */
  function submitImportForm() {
577
    $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
578 579

    $form['files[upload]'] = $this->getInvalidOpml();
580
    $this->drupalPost('admin/settings/aggregator/add/opml', $form, t('Import'));
581 582 583
    $this->assertText(t('No new feed has been added.'), t('Attempting to upload invalid XML.'));

    $form = array('remote' => file_create_url($this->getEmptyOpml()));
584
    $this->drupalPost('admin/settings/aggregator/add/opml', $form, t('Import'));
585 586
    $this->assertText(t('No new feed has been added.'), t('Attempting to load empty OPML from remote URL.'));

587
    $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
588 589
    $this->assertEqual($before, $after, t('No feeds were added during the two last form submissions.'));

590 591 592
    db_delete('aggregator_feed')->execute();
    db_delete('aggregator_category')->execute();
    db_delete('aggregator_category_feed')->execute();
593

594
    $category = $this->randomName(10);
595 596 597 598 599 600 601
    db_insert('aggregator_category')
      ->fields(array(
        'cid' => 1,
        'title' => $category,
        'description' => '',
      ))
      ->execute();
602 603 604 605 606 607 608 609 610

    $feeds[0] = $this->getFeedEditArray();
    $feeds[1] = $this->getFeedEditArray();
    $feeds[2] = $this->getFeedEditArray();
    $form = array(
      'files[upload]' => $this->getValidOpml($feeds),
      'refresh'       => '900',
      'category[1]'   => $category,
    );
611
    $this->drupalPost('admin/settings/aggregator/add/opml', $form, t('Import'));
612 613 614
    $this->assertRaw(t('A feed with the URL %url already exists.', array('%url' => $feeds[0]['url'])), t('Verifying that a duplicate URL was identified'));
    $this->assertRaw(t('A feed named %title already exists.', array('%title' => $feeds[1]['title'])), t('Verifying that a duplicate title was identified'));

615
    $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
616
    $this->assertEqual($after, 2, t('Verifying that two distinct feeds were added.'));
617 618 619

    $feeds_from_db = db_query("SELECT f.title, f.url, f.refresh, cf.cid FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} cf ON f.fid = cf.fid");
    $refresh = $category = TRUE;
620 621 622 623 624
    foreach ($feeds_from_db as $feed) {
      $title[$feed->url] = $feed->title;
      $url[$feed->title] = $feed->url;
      $category = $category && $feed->cid == 1;
      $refresh = $refresh && $feed->refresh == 900;
625 626 627 628 629 630 631 632 633 634 635 636 637 638
    }

    $this->assertEqual($title[$feeds[0]['url']], $feeds[0]['title'], t('First feed was added correctly.'));
    $this->assertEqual($url[$feeds[1]['title']], $feeds[1]['url'], t('Second feed was added correctly.'));
    $this->assertTrue($refresh, t('Refresh times are correct.'));
    $this->assertTrue($category, t('Categories are correct.'));
  }

  function testOPMLImport() {
    $this->openImportForm();
    $this->validateImportFormFields();
    $this->submitImportForm();
  }
}