function AggregatorTestCase::getValidOpml in Drupal 7
Creates a valid OPML file from an array of feeds.
Parameters
$feeds: An array of feeds.
Return value
Path to valid OPML file.
1 call to AggregatorTestCase::getValidOpml()
- ImportOPMLTestCase::submitImportForm in modules/
aggregator/ aggregator.test - Submits form with invalid, empty, and valid OPML files.
File
- modules/
aggregator/ aggregator.test, line 209 - Tests for aggregator.module.
Class
- AggregatorTestCase
- Defines a base class for testing the Aggregator module.
Code
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">
<head></head>
<body>
<!-- First feed to be imported. -->
<outline text="{<span class="php-variable">$feeds</span>[<span class="php-constant">0</span>][<span class="php-string">'title'</span>]}" xmlurl="{<span class="php-variable">$feeds</span>[<span class="php-constant">0</span>][<span class="php-string">'url'</span>]}" />
<!-- Second feed. Test string delimitation and attribute order. -->
<outline xmlurl='{<span class="php-variable">$feeds</span>[<span class="php-constant">1</span>][<span class="php-string">'url'</span>]}' text='{<span class="php-variable">$feeds</span>[<span class="php-constant">1</span>][<span class="php-string">'title'</span>]}'/>
<!-- Test for duplicate URL and title. -->
<outline xmlurl="{<span class="php-variable">$feeds</span>[<span class="php-constant">0</span>][<span class="php-string">'url'</span>]}" text="Duplicate URL"/>
<outline xmlurl="http://duplicate.title" text="{<span class="php-variable">$feeds</span>[<span class="php-constant">1</span>][<span class="php-string">'title'</span>]}"/>
<!-- Test that feeds are only added with required attributes. -->
<outline text="{<span class="php-variable">$feeds</span>[<span class="php-constant">2</span>][<span class="php-string">'title'</span>]}" />
<outline xmlurl="{<span class="php-variable">$feeds</span>[<span class="php-constant">2</span>][<span class="php-string">'url'</span>]}" />
</body>
</opml>
EOF;
$path = 'public://valid-opml.xml';
return file_unmanaged_save_data($opml, $path);
}