<?php
// $Id: simplepie.test,v 1.1.2.1 2008/09/01 22:54:08 mustafau Exp $

/**
 * @file
 */

/**
 * SimplePieTestCase class.
 */
class SimplePieTestCase extends DrupalWebTestCase {
  function getInfo() {
    return array(
      'name' => t('SimplePie Core test case'),
      'description' => t('Tests whether SimplePie Core is working or not.'),
      'group' => t('SimplePie Core'),
    );
  }

  /**
   * Implementation of setUp().
   */
  function setUp() {
    parent::setUp('simplepie');
  }

  function getRSS091Sample() {
    $feed = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<rss version="0.91">
  <channel>
    <title>Example</title>
    <link>http://example.com</link>
    <description>Example updates</description>
    <language>en-us</language>
    <copyright>Copyright 2000, Example team.</copyright>
    <managingEditor>editor@example.com</managingEditor>
    <webMaster>webmaster@example.com</webMaster>
    <image>
      <title>Example</title>
      <url>http://example.com/images/druplicon.png</url>
      <link>http://example.com</link>
      <width>88</width>
      <height>100</height>
      <description>Example updates</description>
    </image>
    <item>
      <title>Example turns one</title>
      <link>http://example.com/example-turns-one</link>
      <description>Example turns one.</description>
    </item>
  </channel>
</rss>
EOT;

    $path = file_directory_path() . '/rss091.xml';
    file_save_data($feed, $path);
    return $path;
  }
  
  function testSimplePie() {
    $url = file_create_url($this->getRSS091Sample());
    $this->drupalGet($url);
    $this->assertResponse(array(200), t('URL !url is accessible', array('!url' => $url)));

    $simplepie = simplepie_get($url, FALSE, FALSE);
    $this->assertEqual('Example', $simplepie->get_title(), t('Feed title matches; !title.', array('!title' => $simplepie->get_title())));
  }
}
