public function AggregatorTestBase::getValidOpml in Drupal 8
Same name in this branch
- 8 core/modules/aggregator/src/Tests/AggregatorTestBase.php \Drupal\aggregator\Tests\AggregatorTestBase::getValidOpml()
- 8 core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php \Drupal\Tests\aggregator\Functional\AggregatorTestBase::getValidOpml()
Creates a valid OPML file from an array of feeds.
Parameters
array $feeds: An array of feeds.
Return value
string Path to valid OPML file.
File
- core/
modules/ aggregator/ src/ Tests/ AggregatorTestBase.php, line 268
Class
- AggregatorTestBase
- Defines a base class for testing the Aggregator module.
Namespace
Drupal\aggregator\TestsCode
public function getValidOpml(array $feeds) {
// Properly escape URLs so that XML parsers don't choke on them.
foreach ($feeds as &$feed) {
$feed['url[0][value]'] = Html::escape($feed['url[0][value]']);
}
/**
* 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[0][value]'</span>]}" xmlurl="{<span class="php-variable">$feeds</span>[<span class="php-constant">0</span>][<span class="php-string">'url[0][value]'</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[0][value]'</span>]}' text='{<span class="php-variable">$feeds</span>[<span class="php-constant">1</span>][<span class="php-string">'title[0][value]'</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[0][value]'</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[0][value]'</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[0][value]'</span>]}" />
<outline xmlurl="{<span class="php-variable">$feeds</span>[<span class="php-constant">2</span>][<span class="php-string">'url[0][value]'</span>]}" />
</body>
</opml>
EOF;
$path = 'public://valid-opml.xml';
// Add the UTF-8 byte order mark.
return \Drupal::service('file_system')
->saveData(chr(239) . chr(187) . chr(191) . $opml, $path);
}