View source
<?php
require_once dirname(__FILE__) . '/feeds_xpathparser.test';
class FeedsXPathParserXMLTestCase extends FeedsXPathParserWebTestCase {
public static function getInfo() {
return array(
'name' => 'XML Parser',
'description' => 'Regression tests for Feeds XPath XML parser.',
'group' => 'Feeds XPath Parser',
);
}
public function test() {
$this
->createImporterConfiguration('XPathXML', 'xpath_xml');
$importer_url = $this->feeds_base . '/xpath_xml/settings/FeedsXPathParserXML';
$this
->setPlugin('xpath_xml', 'FeedsXPathParserXML');
$this
->drupalGet($importer_url);
$this
->assertText('FeedsXPathParser: No mappings are defined. Define mappings here.');
$this
->addMappings('xpath_xml', array(
array(
'source' => 'xpathparser:0',
'target' => 'title',
'unique' => FALSE,
),
array(
'source' => 'xpathparser:1',
'target' => 'guid',
'unique' => TRUE,
),
array(
'source' => 'xpathparser:2',
'target' => 'body',
'unique' => FALSE,
),
));
$edit = array(
'xpath[context]' => '//entry',
'xpath[sources][xpathparser:0]' => 'title',
'xpath[sources][xpathparser:1]' => 'id',
'xpath[sources][xpathparser:2]' => 'id',
);
$this
->postAndCheck($importer_url, $edit, 'Save', 'Your changes have been saved.');
$path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_xpathparser') . '/tests/feeds_xpathparser/';
$nid = $this
->createFeedNode('xpath_xml', $path . 'sample_atom_feed.xml', 'Testing XPath XML Parser');
$feed_node_edit_url = 'node/' . $nid . '/edit';
$this
->assertText('Created 3 Story nodes.');
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('There is no new content.');
$this
->drupalGet('node');
$this
->assertText('Atom-Powered Robots Run Amok');
$this
->assertText('My dog Jack is the best.');
$this
->assertText('Physics is cool.');
$edit = array(
'feeds[FeedsXPathParserXML][xpath][exp][debug][xpathparser:0]' => TRUE,
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath XML Parser has been updated.');
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('<title>Atom-Powered Robots Run Amok</title>');
$this
->assertText('<title>My dog Jack is the best.</title>');
$this
->assertText('<title>Physics is cool.</title>');
$this
->assertText('There is no new content.');
$edit = array(
'feeds[FeedsXPathParserXML][xpath][exp][debug][xpathparser:0]' => FALSE,
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath XML Parser has been updated.');
$this
->setSettings('xpath_xml', 'FeedsNodeProcessor', array(
'update_existing' => 2,
));
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $path . 'sample_atom_feed_updated.xml',
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath XML Parser has been updated.');
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('Updated 1 Story node.');
$this
->drupalGet('node');
$this
->assertText('Atom-Powered Robots Run Amok');
$this
->assertText('My dog Jack is the best.');
$this
->assertText('Physics is really cool.');
$this
->assertNoText('Physics is cool.');
$this
->drupalGet('node/4');
$this
->assertText('Physics is really cool.');
$this
->setSettings('xpath_xml', 'FeedsNodeProcessor', array(
'update_existing' => 1,
));
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $path . 'sample_atom_feed.xml',
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath XML Parser has been updated.');
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('Updated 1 Story node.');
$this
->drupalGet('node');
$this
->assertText('Atom-Powered Robots Run Amok');
$this
->assertText('My dog Jack is the best.');
$this
->assertText('Physics is cool.');
$this
->assertNoText('Physics is really cool.');
$this
->drupalGet('node/4');
$this
->assertText('Physics is cool.');
$edit = array(
'feeds[FeedsXPathParserXML][xpath][context]' => '/foo',
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:0]' => 'bar',
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:1]' => 'baz',
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:2]' => 'wee',
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath XML Parser has been updated.');
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('There is no new content.');
$edit = array(
'feeds[FeedsXPathParserXML][xpath][context]' => 'sdf asf',
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:0]' => 'asdf[sadfas asdf]',
);
$this
->drupalPost($feed_node_edit_url, $edit, 'Save');
$this
->assertText('There was an error with the XPath selector: Invalid expression');
$this
->assertText('There was an error with the XPath selector: Invalid predicate');
$this
->assertFieldByXPath('//input[@id="edit-feeds-FeedsXPathParserXML-xpath-context"][1]/@class', 'form-text required error');
$this
->assertFieldByXPath('//input[@id="edit-feeds-FeedsXPathParserXML-xpath-sources-xpathparser:0"][1]/@class', 'form-text error');
$edit = array(
'feeds[FeedsXPathParserXML][xpath][context]' => '//entry',
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:0]' => 'title',
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:1]' => 'id',
'feeds[FeedsXPathParserXML][xpath][sources][xpathparser:2]' => 'id',
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath XML Parser has been updated.');
$edit = array(
'xpath[context]' => '//tr',
'xpath[sources][xpathparser:0]' => 'booya',
'xpath[sources][xpathparser:1]' => 'boyz',
'xpath[sources][xpathparser:2]' => 'woot',
);
$this
->postAndCheck($importer_url, $edit, 'Save', 'Your changes have been saved.');
$this
->drupalGet($feed_node_edit_url);
$this
->assertFieldByName('feeds[FeedsXPathParserXML][xpath][context]', '//tr');
$this
->assertFieldByName('feeds[FeedsXPathParserXML][xpath][sources][xpathparser:0]', 'booya');
$this
->assertFieldByName('feeds[FeedsXPathParserXML][xpath][sources][xpathparser:1]', 'boyz');
$this
->assertFieldByName('feeds[FeedsXPathParserXML][xpath][sources][xpathparser:2]', 'woot');
$this
->assertText('Field guid is mandatory and considered unique: only one item per guid value will be created.');
$this
->setSettings('xpath_xml', 'FeedsXPathParserXML', array(
'xpath[allow_override]' => FALSE,
));
$this
->drupalGet($feed_node_edit_url);
$this
->assertNoText('XPath Parser Settings');
$this
->assertNoField('xpath[context]');
}
public function testVariables() {
$this
->createImporterConfiguration();
$this
->setPlugin('syndication', 'FeedsXPathParserXML');
$importer_url = $this->feeds_base . '/syndication/settings/FeedsXPathParserXML';
$this
->addMappings('syndication', array(
array(
'source' => 'xpathparser:0',
'target' => 'title',
'unique' => FALSE,
),
array(
'source' => 'xpathparser:1',
'target' => 'guid',
'unique' => TRUE,
),
array(
'source' => 'xpathparser:2',
'target' => 'body',
'unique' => FALSE,
),
));
$edit = array(
'xpath[context]' => '//entry',
'xpath[sources][xpathparser:0]' => 'title',
'xpath[sources][xpathparser:1]' => 'id',
'xpath[sources][xpathparser:2]' => 'link/@$title',
);
$this
->postAndCheck($importer_url, $edit, 'Save', 'Your changes have been saved.');
$path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_xpathparser') . '/tests/feeds_xpathparser/';
$nid = $this
->createFeedNode('syndication', $path . 'rewrite_test.xml', 'Testing XPath XML Parser');
$feed_node_edit_url = 'node/' . $nid . '/edit';
$this
->assertText('Created 3 Story nodes.');
$this
->drupalGet('node');
}
}