You are here

function FeedAPIOPMLTestsCase::testFeedAPI_Node_Import_Form in FeedAPI 6

Checks the OPML import form.

File

tests/feedapi_opml.test, line 36

Class

FeedAPIOPMLTestsCase
Class for testing FeedAPI OPML support.

Code

function testFeedAPI_Node_Import_Form() {
  $opml = <<<EOT
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- OPML generated by UserLand Frontier v9.0 on Fri, 23 Jul 2004 23:41:33 GMT -->
<opml version="1.1">
\t<head>
\t\t<title>ourFavoriteFeedsData.top100</title>
\t\t<dateCreated>Fri, 02 Jan 2004 12:59:58 GMT</dateCreated>
\t\t<dateModified>Fri, 23 Jul 2004 23:41:32 GMT</dateModified>
\t\t<ownerName>Dave Winer</ownerName>
\t\t<ownerEmail>dave@userland.com</ownerEmail>
\t\t<expansionState></expansionState>
\t\t<vertScrollState>1</vertScrollState>
\t\t<windowTop>20</windowTop>
\t\t<windowLeft>0</windowLeft>
\t\t<windowBottom>120</windowBottom>
\t\t<windowRight>147</windowRight>
\t\t</head>
\t<body>
\t\t<outline title="Scripting News" count="580" xmlUrl="http://www.scripting.com/rss.xml"/>
\t\t<outline title="Wired News" count="546" xmlUrl="http://www.wired.com/news_drop/netcenter/netcenter.rdf"/>
\t\t</body>
\t</opml>
EOT;
  $parsers = $this
    ->get_parsers();
  foreach ($parsers as $parser) {
    $this
      ->create_type($parser);
    $this
      ->feedapi_user();
    $this
      ->drupalGet('admin/content/feed/import_opml');
    $this
      ->assertResponse(200, 'The OPML import form is accessible.');
    $this
      ->assertText(t('OPML File'), 'The retrieved page contains the OPML form.');
    $this
      ->drupalPost('admin/content/feed/import_opml', array(), 'Import');
    $this
      ->assertText(t('Data could not be retrieved, invalid or empty file.'), 'The error message appears when the empty OPML import form is submitted.');
    $opml_filename = file_directory_temp() . '/' . md5($opml);
    file_put_contents($opml_filename, $opml);
    $edit['files[opml]'] = $opml_filename;
    $edit['feed_type'] = $this->info->type;
    $edit['override_title'] = TRUE;
    $edit['override_body'] = FALSE;
    $this
      ->drupalPost('admin/content/feed/import_opml', $edit, 'Import');
    $nid = db_result(db_query("SELECT n.nid FROM {node} n LEFT JOIN {feedapi} f ON n.nid = f.nid WHERE f.url = '%s' ORDER BY nid DESC", 'http://www.scripting.com/rss.xml'));
    $node = node_load($nid);
    $this
      ->assertTrue(is_object($node), 'The first entry of OPML can be loaded as a node.');
    node_delete($nid);
    unlink($opml_filename);
  }
}