You are here

public function AggregatorTestBase::getValidOpml in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/aggregator/src/Tests/AggregatorTestBase.php \Drupal\aggregator\Tests\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.

1 call to AggregatorTestBase::getValidOpml()
ImportOpmlTest::submitImportForm in core/modules/aggregator/src/Tests/ImportOpmlTest.php
Submits form with invalid, empty, and valid OPML files.

File

core/modules/aggregator/src/Tests/AggregatorTestBase.php, line 245
Contains \Drupal\aggregator\Tests\AggregatorTestBase.

Class

AggregatorTestBase
Defines a base class for testing the Aggregator module.

Namespace

Drupal\aggregator\Tests

Code

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';
  return file_unmanaged_save_data($opml, $path);
}