public function FeedsXPathParseHTMLTestCase::test in Feeds XPath Parser 6
Same name and namespace in other branches
- 7 tests/feeds_xpathparser_parser_html.test \FeedsXPathParseHTMLTestCase::test()
Run tests.
File
- tests/
feeds_xpathparser_parser_html.test, line 29
Class
- FeedsXPathParseHTMLTestCase
- Test single feeds.
Code
public function test() {
$this
->createImporterConfiguration('XPath', 'xpath');
$this
->setPlugin('xpath', 'FeedsXPathParserHTML');
$this
->addMappings('xpath', array(
array(
'source' => 'xpathparser:0',
'target' => 'title',
'unique' => FALSE,
),
array(
'source' => 'xpathparser:1',
'target' => 'url',
'unique' => TRUE,
),
));
// Set importer default settings.
$importer_url = $this->feeds_base . '/xpath/settings/FeedsXPathParserHTML';
$edit = array(
'xpath[context]' => '//tr[starts-with(@class, "odd ") or starts-with(@class, "even ")]',
'xpath[sources][xpathparser:0]' => 'td[1]/a',
'xpath[sources][xpathparser:1]' => 'td[1]/a/@href',
);
$this
->postAndCheck($importer_url, $edit, 'Save', 'Your changes have been saved.');
// Test import.
$path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_xpathparser') . '/tests/feeds_xpathparser/';
$nid = $this
->createFeedNode('xpath', $path . 'issues_drupal.org.htm', 'Testing XPath HTML Parser');
$feed_node_edit_url = 'node/' . $nid . '/edit';
$this
->assertText('Created 29 Story nodes.');
// Import again, this verifies url field was mapped correctly.
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('There is no new content.');
// Assert accuracy of aggregated content. I find humor in using our own
// issue queue to run tests against.
$this
->drupalGet('node');
$this
->assertText('Xpath Functions');
$this
->assertText('Unable to upload .html files');
$this
->assertText('Import to multiple content types');
$this
->assertText('Parser includes tags in mapped output');
$this
->assertText('Errors');
$this
->assertText('Loop through HTML - all data is in one node?');
$this
->assertText('Patch: add encoding options for PHP tidy feature');
$this
->assertText('Import and Maintain 1300+ Node Items');
$this
->assertText('Documentation update');
$this
->assertText('An HTTP error 404 occured');
$this
->assertText('Does it work with Feeds Image Grabber');
$this
->assertText('Node published date not being correctly mapped (set to 1 Jan 1970)');
$this
->assertText('fields to fill xpath not displayed in importer interface except for "body"');
$this
->assertText('parsing link field');
$this
->assertText('Error when switching to XML Parser');
$this
->assertText('Duplicate content even if "unique target" is set');
$this
->assertText('Labels/field names become meaningless with Data Processor');
$this
->assertText('Xpath namespace help');
$this
->assertText('warning: mysql_real_escape_string()');
$this
->assertText('Feeds XPath Parser: warning: Invalid argument');
$this
->assertText('What am I missing? FeedsXPathParser: No mappings are defined.');
$this
->assertText('CDATA in tag not producing text');
$this
->assertText('Cant map empty fields');
$this
->assertText('Support literal XPath expressions');
$this
->assertText('adding a prefix to a parsed xml value.');
$this
->assertText('Mapping on import');
$this
->assertText('Feeds XPath Parser: HTML parser example for number expressions');
$this
->assertText("I dont want to define any field queries");
$this
->assertText("Document // and other syntax for this module a little better");
// Test debugging.
$edit = array(
'feeds[FeedsXPathParserHTML][xpath][exp][debug][xpathparser:0]' => TRUE,
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath HTML Parser has been updated.');
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('<a href="http://drupal.org/node/976478">Xpath Functions</a>');
$this
->assertText('<a href="http://drupal.org/node/1048030">Unable to upload .html files</a>');
$this
->assertText('<a href="http://drupal.org/node/1050310">Import to multiple content types</a>');
$this
->assertText('<a href="http://drupal.org/node/1047788">Parser includes tags in mapped output</a>');
$this
->assertText('<a href="http://drupal.org/node/1043608">Errors</a>');
$this
->assertText('<a href="http://drupal.org/node/1044546">Loop through HTML - all data is in one node?</a>');
$this
->assertText('<a href="http://drupal.org/node/1043728">Patch: add encoding options for PHP tidy feature</a>');
$this
->assertText('<a href="http://drupal.org/node/1040132">Import and Maintain 1300+ Node Items</a>');
$this
->assertText('<a href="http://drupal.org/node/1043604">Documentation update</a>');
$this
->assertText('<a href="http://drupal.org/node/1039492">An HTTP error 404 occured</a>');
$this
->assertText('<a href="http://drupal.org/node/1042048">Does it work with Feeds Image Grabber</a>');
$this
->assertText('<a href="http://drupal.org/node/961158">Node published date not being correctly mapped (set to 1 Jan 1970)</a>');
$this
->assertText('<a href="http://drupal.org/node/1021474">fields to fill xpath not displayed in importer interface except for "body"</a>');
$this
->assertText('<a href="http://drupal.org/node/1040530">parsing link field</a>');
$this
->assertText('<a href="http://drupal.org/node/1038912">Error when switching to XML Parser</a>');
$this
->assertText('<a href="http://drupal.org/node/1032340">Duplicate content even if "unique target" is set</a>');
$this
->assertText('<a href="http://drupal.org/node/982102">Labels/field names become meaningless with Data Processor</a>');
$this
->assertText('<a href="http://drupal.org/node/1034758">Xpath namespace help</a>');
$this
->assertText('<a href="http://drupal.org/node/908458">warning: mysql_real_escape_string()</a>');
$this
->assertText('<a href="http://drupal.org/node/869076">Feeds XPath Parser: warning: Invalid argument</a>');
$this
->assertText('<a href="http://drupal.org/node/991386">What am I missing? FeedsXPathParser: No mappings are defined.</a>');
$this
->assertText('<a href="http://drupal.org/node/990972">CDATA in tag not producing text</a>');
$this
->assertText('<a href="http://drupal.org/node/989948">Cant map empty fields</a>');
$this
->assertText('<a href="http://drupal.org/node/973324">Support literal XPath expressions</a>');
$this
->assertText('<a href="http://drupal.org/node/958344">adding a prefix to a parsed xml value.</a>');
$this
->assertText('<a href="http://drupal.org/node/914216">Mapping on import</a>');
$this
->assertText('<a href="http://drupal.org/node/863714">Feeds XPath Parser: HTML parser example for number expressions</a>');
$this
->assertText('<a href="http://drupal.org/node/915856">I dont want to define any field queries</a>');
$this
->assertText('<a href="http://drupal.org/node/950150">Document // and other syntax for this module a little better</a>');
$this
->assertText('There is no new content.');
// Turn debugging off.
$edit = array(
'feeds[FeedsXPathParserHTML][xpath][exp][debug][xpathparser:0]' => FALSE,
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath HTML Parser has been updated.');
// Test that overriding default settings works.
$edit = array(
'feeds[FeedsXPathParserHTML][xpath][context]' => '/foo',
'feeds[FeedsXPathParserHTML][xpath][sources][xpathparser:0]' => 'bar',
'feeds[FeedsXPathParserHTML][xpath][sources][xpathparser:1]' => 'baz',
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath HTML Parser has been updated.');
// Assert the we don't create an empty node when XPath values don't return anything.
// That happened at one point.
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('There is no new content.');
// Test that validation works.
$edit = array(
'feeds[FeedsXPathParserHTML][xpath][context]' => 'sdf asf',
'feeds[FeedsXPathParserHTML][xpath][sources][xpathparser:0]' => 'asdf[sadfas asdf]',
);
$this
->drupalPost($feed_node_edit_url, $edit, 'Save');
// Check for valid error messages.
$this
->assertText('There was an error with the XPath selector: Invalid expression');
$this
->assertText('There was an error with the XPath selector: Invalid predicate');
// Make sure the fields are errored out correctly. I.e. we have red outlines.
$this
->assertFieldByXPath('//input[@id="edit-feeds-FeedsXPathParserHTML-xpath-context"][1]/@class', 'form-text required error');
$this
->assertFieldByXPath('//input[@id="edit-feeds-FeedsXPathParserHTML-xpath-sources-xpathparser:0"][1]/@class', 'form-text error');
// Put the values back so we can test inheritance if the form was changed
// and then changed back.
$edit = array(
'feeds[FeedsXPathParserHTML][xpath][context]' => '//tr[starts-with(@class, "odd ") or starts-with(@class, "even ")]',
'feeds[FeedsXPathParserHTML][xpath][sources][xpathparser:0]' => 'td[1]/a',
'feeds[FeedsXPathParserHTML][xpath][sources][xpathparser:1]' => 'td[1]/a/@href',
);
$this
->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Page Testing XPath HTML Parser has been updated.');
// Change importer defaults.
$edit = array(
'xpath[context]' => '//tr',
'xpath[sources][xpathparser:0]' => 'booya',
'xpath[sources][xpathparser:1]' => 'boyz',
);
$this
->postAndCheck($importer_url, $edit, 'Save', 'Your changes have been saved.');
// Make sure the changes propigated.
$this
->drupalGet($feed_node_edit_url);
$this
->assertFieldByName('feeds[FeedsXPathParserHTML][xpath][context]', '//tr');
$this
->assertFieldByName('feeds[FeedsXPathParserHTML][xpath][sources][xpathparser:0]', 'booya');
$this
->assertFieldByName('feeds[FeedsXPathParserHTML][xpath][sources][xpathparser:1]', 'boyz');
// Check that our help text is present.
$this
->assertText('Field url is mandatory and considered unique: only one item per url value will be created.');
}