UpdateFeedItemTest.php 2.67 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Definition of Drupal\aggregator\Tests\UpdateFeedItemTest.
 */

namespace Drupal\aggregator\Tests;

10 11 12
/**
 * Tests functionality of updating a feed item in the Aggregator module.
 */
13 14 15 16 17 18 19 20 21 22
class UpdateFeedItemTest extends AggregatorTestBase {
  public static function getInfo() {
    return array(
      'name' => 'Update feed item functionality',
      'description' => 'Update feed items from a feed.',
      'group' => 'Aggregator'
    );
  }

  /**
23
   * Tests running "update items" from 'admin/config/services/aggregator' page.
24 25 26 27 28 29 30 31
   */
  function testUpdateFeedItem() {
    $this->createSampleNodes();

    // Create a feed and test updating feed items if possible.
    $feed = $this->createFeed();
    if (!empty($feed)) {
      $this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
32
      $this->deleteFeedItems($feed);
33 34 35 36 37 38 39
    }

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

    // Test updating feed items without valid timestamp information.
    $edit = array(
40 41
      'title[0][value]' => "Feed without publish timestamp",
      'url[0][value]' => $this->getRSS091Sample(),
42 43
    );

44 45
    $this->drupalGet($edit['url[0][value]']);
    $this->assertResponse(array(200), format_string('URL !url is accessible', array('!url' => $edit['url[0][value]'])));
46

47
    $this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
48
    $this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title[0][value]'])), format_string('The feed !name has been added.', array('!name' => $edit['title[0][value]'])));
49

50
    $fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", array(':url' => $edit['url[0][value]']))->fetchField();
51
    $feed = aggregator_feed_load($fid);
52

53
    $feed->refreshItems();
54
    $before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField();
55 56 57 58

    // Sleep for 3 second.
    sleep(3);
    db_update('aggregator_feed')
59
      ->condition('fid', $feed->id())
60 61 62 63 64 65 66
      ->fields(array(
        'checked' => 0,
        'hash' => '',
        'etag' => '',
        'modified' => 0,
      ))
      ->execute();
67
    $feed->refreshItems();
68

69
    $after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField();
70
    $this->assertTrue($before === $after, format_string('Publish timestamp of feed item was not updated (!before === !after)', array('!before' => $before, '!after' => $after)));
71 72 73 74

    // Make sure updating items works even after disabling a module
    // that provides the selected plugins.
    $this->enableTestPlugins();
75
    module_uninstall(array('aggregator_test'));
76 77
    $this->updateFeedItems($feed);
    $this->assertResponse(200);
78 79
  }
}