UpdateFeedItemTest.php 2.43 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\aggregator\Tests\UpdateFeedItemTest.
6 7 8
 */

namespace Drupal\aggregator\Tests;
9
use Drupal\aggregator\Entity\Feed;
10

11
/**
12 13 14
 * Update feed items from a feed.
 *
 * @group aggregator
15
 */
16 17
class UpdateFeedItemTest extends AggregatorTestBase {
  /**
18
   * Tests running "update items" from 'admin/config/services/aggregator' page.
19
   */
20
  public function testUpdateFeedItem() {
21 22 23 24 25 26
    $this->createSampleNodes();

    // Create a feed and test updating feed items if possible.
    $feed = $this->createFeed();
    if (!empty($feed)) {
      $this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
27
      $this->deleteFeedItems($feed);
28 29 30 31 32 33 34
    }

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

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

39
    $this->drupalGet($edit['url[0][value]']);
40
    $this->assertResponse(200);
41

42
    $this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
43
    $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]'])));
44

45
    $fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", array(':url' => $edit['url[0][value]']))->fetchField();
46
    $feed = Feed::load($fid);
47

48
    $feed->refreshItems();
49
    $before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField();
50 51 52 53

    // Sleep for 3 second.
    sleep(3);
    db_update('aggregator_feed')
54
      ->condition('fid', $feed->id())
55 56 57 58 59 60 61
      ->fields(array(
        'checked' => 0,
        'hash' => '',
        'etag' => '',
        'modified' => 0,
      ))
      ->execute();
62
    $feed->refreshItems();
63

64
    $after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField();
65
    $this->assertTrue($before === $after, format_string('Publish timestamp of feed item was not updated (@before === @after)', array('@before' => $before, '@after' => $after)));
66

67
    // Make sure updating items works even after uninstalling a module
68 69
    // that provides the selected plugins.
    $this->enableTestPlugins();
70
    $this->container->get('module_installer')->uninstall(array('aggregator_test'));
71 72
    $this->updateFeedItems($feed);
    $this->assertResponse(200);
73 74
  }
}