You are here

feeds_parser_sitemap.test in Feeds 6

Same filename and directory in other branches
  1. 7.2 tests/feeds_parser_sitemap.test
  2. 7 tests/feeds_parser_sitemap.test

Tests for plugins/FeedsSitemapParser.inc

File

tests/feeds_parser_sitemap.test
View source
<?php

module_load_include('test', 'feeds', 'tests/feeds');

/**
 * @file
 * Tests for plugins/FeedsSitemapParser.inc
 */

/**
 * Test Sitemap parser.
 */
class FeedsSitemapParserTestCase extends FeedsWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Sitemap parser',
      'description' => 'Regression tests for Sitemap XML format parser.',
      'group' => 'Feeds',
    );
  }

  /**
   * Run tests.
   */
  public function test() {
    $this
      ->createImporterConfiguration('Sitemap', 'sitemap');
    $this
      ->setPlugin('sitemap', 'FeedsSitemapParser');
    $this
      ->addMappings('sitemap', array(
      array(
        'source' => 'changefreq',
        'target' => 'title',
        'unique' => FALSE,
      ),
      array(
        'source' => 'priority',
        'target' => 'body',
        'unique' => FALSE,
      ),
      array(
        'source' => 'lastmod',
        'target' => 'created',
        'unique' => FALSE,
      ),
      array(
        'source' => 'url',
        'target' => 'url',
        'unique' => TRUE,
      ),
      array(
        'source' => 'url',
        'target' => 'guid',
        'unique' => TRUE,
      ),
    ));
    $path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/';
    $nid = $this
      ->createFeedNode('sitemap', $path . 'sitemap-example.xml', 'Testing Sitemap Parser');
    $this
      ->assertText('Created 5 Story nodes.');

    // Assert DB status.
    $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}"));
    $this
      ->assertEqual($count, 5, 'Accurate number of items in database.');

    // Check items against known content of feed.
    $result = db_query('SELECT * FROM {feeds_node_item} WHERE feed_nid = %d ORDER BY nid', $nid);

    // Check first item.
    date_default_timezone_set('GMT');
    $item = db_fetch_object($result);
    $node = node_load($item->nid);
    $this
      ->assertEqual($node->title, 'monthly', 'Feed item 1 changefreq is correct.');
    $this
      ->assertEqual($node->body, '0.8', 'Feed item 1 priority is correct.');
    $this
      ->assertEqual($node->created, strtotime('2005-01-01'), 'Feed item 1 lastmod is correct.');
    $this
      ->assertEqual($node->feeds_node_item->url, 'http://www.example.com/', 'Feed item 1 url is correct.');
    $this
      ->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 1 guid is correct.');

    // Check second item.
    $item = db_fetch_object($result);
    $node = node_load($item->nid);
    $this
      ->assertEqual($node->title, 'weekly', 'Feed item 2 changefreq is correct.');
    $this
      ->assertEqual($node->body, '', 'Feed item 2 priority is correct.');

    // $node->created is... recently
    $this
      ->assertEqual($node->feeds_node_item->url, 'http://www.example.com/catalog?item=12&desc=vacation_hawaii', 'Feed item 2 url is correct.');
    $this
      ->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 2 guid is correct.');

    // Check third item.
    $item = db_fetch_object($result);
    $node = node_load($item->nid);
    $this
      ->assertEqual($node->title, 'weekly', 'Feed item 3 changefreq is correct.');
    $this
      ->assertEqual($node->body, '', 'Feed item 3 priority is correct.');
    $this
      ->assertEqual($node->created, strtotime('2004-12-23'), 'Feed item 3 lastmod is correct.');
    $this
      ->assertEqual($node->feeds_node_item->url, 'http://www.example.com/catalog?item=73&desc=vacation_new_zealand', 'Feed item 3 url is correct.');
    $this
      ->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 3 guid is correct.');

    // Check fourth item.
    $item = db_fetch_object($result);
    $node = node_load($item->nid);
    $this
      ->assertEqual($node->title, '', 'Feed item 4 changefreq is correct.');
    $this
      ->assertEqual($node->body, '0.3', 'Feed item 4 priority is correct.');
    $this
      ->assertEqual($node->created, strtotime('2004-12-23T18:00:15+00:00'), 'Feed item 4 lastmod is correct.');
    $this
      ->assertEqual($node->feeds_node_item->url, 'http://www.example.com/catalog?item=74&desc=vacation_newfoundland', 'Feed item 4 url is correct.');
    $this
      ->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 1 guid is correct.');

    // Check fifth item.
    $item = db_fetch_object($result);
    $node = node_load($item->nid);
    $this
      ->assertEqual($node->title, '', 'Feed item 5 changefreq is correct.');
    $this
      ->assertEqual($node->body, '', 'Feed item 5 priority is correct.');
    $this
      ->assertEqual($node->created, strtotime('2004-11-23'), 'Feed item 5 lastmod is correct.');
    $this
      ->assertEqual($node->feeds_node_item->url, 'http://www.example.com/catalog?item=83&desc=vacation_usa', 'Feed item 5 url is correct.');
    $this
      ->assertEqual($node->feeds_node_item->url, $node->feeds_node_item->guid, 'Feed item 5 guid is correct.');

    // Check for more items.
    $item = db_fetch_object($result);
    $this
      ->assertFalse($item, 'Correct number of feed items recorded.');
  }

}

Classes

Namesort descending Description
FeedsSitemapParserTestCase Test Sitemap parser.