function AggregatorTestCase::getValidOpml

7.x aggregator.test AggregatorTestCase::getValidOpml($feeds)

Creates a valid OPML file from an array of feeds.


$feeds: An array of feeds.

Return value

Path to valid OPML file.

1 call to AggregatorTestCase::getValidOpml()
ImportOPMLTestCase::submitImportForm in drupal/modules/aggregator/aggregator.test
Submits form with invalid, empty, and valid OPML files.


drupal/modules/aggregator/aggregator.test, line 209
Tests for aggregator.module.


Defines a base class for testing the Aggregator module.


function getValidOpml($feeds) {
  // Properly escape URLs so that XML parsers don't choke on them.
  foreach ($feeds as &$feed) {
    $feed['url'] = htmlspecialchars($feed['url']);
   * Does not have an XML declaration, must pass the parser.
  $opml = <<<EOF
<opml version="1.0">
    <!-- 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']}" />

  $path = 'public://valid-opml.xml';
  return file_unmanaged_save_data($opml, $path);