first import
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for FeedsXPathParserXML.inc.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test single feeds.
|
||||
*/
|
||||
class FeedsXPathParserWebTestCase extends FeedsWebTestCase {
|
||||
|
||||
/**
|
||||
* Set up test.
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp('feeds_xpathparser');
|
||||
|
||||
// Set the front page to show 30 nodes so we can easily see what is aggregated.
|
||||
$edit = array('default_nodes_main' => 30);
|
||||
$this->drupalPost('admin/config/system/site-information', $edit, 'Save configuration');
|
||||
|
||||
// Set the teaser length display to unlimited otherwise tests looking for
|
||||
// text on nodes will fail.
|
||||
$edit = array('fields[body][type]' => 'text_default');
|
||||
$this->drupalPost('admin/structure/types/manage/article/display/teaser', $edit, 'Save');
|
||||
|
||||
// Generalize across my version of feeds and the standard one.
|
||||
$items = feeds_ui_menu();
|
||||
if (isset($items['admin/structure/feeds/%feeds_importer/edit'])) {
|
||||
$this->feeds_base = 'admin/structure/feeds';
|
||||
}
|
||||
else {
|
||||
$this->feeds_base = 'admin/structure/feeds/edit';
|
||||
}
|
||||
}
|
||||
|
||||
function postAndCheck($url, $edit, $button, $saved_text) {
|
||||
$this->drupalPost($url, $edit, $button);
|
||||
$this->assertText($saved_text);
|
||||
$this->drupalGet($url);
|
||||
foreach ($edit as $key => $value) {
|
||||
$this->assertFieldByName($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
|
||||
<title>albino</title>
|
||||
<link albino="http://example.org/"/>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<author>
|
||||
<name>John Doe</name>
|
||||
</author>
|
||||
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
||||
|
||||
<entry>
|
||||
<title>bear</title>
|
||||
<link bear="http://example.org/2003/12/13/atom03"/>
|
||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<summary>Some text.</summary>
|
||||
</entry>
|
||||
|
||||
<!-- Empty entry here intentionally. See #1189192.-->
|
||||
<entry>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<title>cook</title>
|
||||
<link cook="http://example.org/2003/12/13/atom04"/>
|
||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b</id>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<summary>Some text.</summary>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<title>physics</title>
|
||||
<link physics="http://example.org/2003/12/13/atom05"/>
|
||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6c</id>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<summary>Some text.</summary>
|
||||
</entry>
|
||||
|
||||
</feed>
|
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
|
||||
<title>Example Atom Feed</title>
|
||||
<link href="http://example.org/"/>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<author>
|
||||
<name>John Doe</name>
|
||||
</author>
|
||||
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
||||
|
||||
<entry>
|
||||
<title>Atom-Powered Robots Run Amok</title>
|
||||
<link href="http://example.org/2003/12/13/atom03"/>
|
||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<summary>Some text.</summary>
|
||||
</entry>
|
||||
|
||||
<!-- Empty entry here intentionally. See #1189192.-->
|
||||
<entry>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<title>My dog Jack is the best.</title>
|
||||
<link href="http://example.org/2003/12/13/atom04"/>
|
||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b</id>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<summary>Some text.</summary>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<title>Physics is cool.</title>
|
||||
<link href="http://example.org/2003/12/13/atom05"/>
|
||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6c</id>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<summary>Some text.</summary>
|
||||
</entry>
|
||||
|
||||
</feed>
|
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
|
||||
<title>Example Atom Feed</title>
|
||||
<link href="http://example.org/"/>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<author>
|
||||
<name>John Doe</name>
|
||||
</author>
|
||||
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
||||
|
||||
<entry>
|
||||
<title>Atom-Powered Robots Run Amok</title>
|
||||
<link href="http://example.org/2003/12/13/atom03"/>
|
||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<summary>Some text.</summary>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<title>My dog Jack is the best.</title>
|
||||
<link href="http://example.org/2003/12/13/atom04"/>
|
||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b</id>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<summary>Some text.</summary>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<title>Physics is really cool.</title>
|
||||
<link href="http://example.org/2003/12/13/atom05"/>
|
||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6c</id>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<summary>Some text.</summary>
|
||||
</entry>
|
||||
|
||||
</feed>
|
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Test</title>
|
||||
<style type="text/css">bla bla</style>
|
||||
</head>
|
||||
<body>bla bla</body>
|
||||
</html>
|
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for FeedsXPathParser.inc.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test single feeds.
|
||||
*/
|
||||
class FeedsXPathParseHTMLTestCase extends FeedsXPathParserWebTestCase {
|
||||
|
||||
/**
|
||||
* Describe this test.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'HTML Parser',
|
||||
'description' => 'Regression tests for Feeds XPath HTML parser.',
|
||||
'group' => 'Feeds XPath Parser',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run tests.
|
||||
*/
|
||||
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, t('Save'), t('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(t('Created 29 nodes'));
|
||||
|
||||
// Import again, this verifies url field was mapped correctly.
|
||||
$this->drupalPost('node/' . $nid . '/import', array(), t('Import'));
|
||||
$this->assertText(t('There are no new nodes'));
|
||||
|
||||
// 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, t('Save'), 'Basic page Testing XPath HTML Parser has been updated.');
|
||||
$this->drupalPost('node/' . $nid . '/import', array(), t('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(t('There are no new nodes'));
|
||||
// Turn debugging off.
|
||||
$edit = array(
|
||||
'feeds[FeedsXPathParserHTML][xpath][exp][debug][xpathparser:0]' => FALSE,
|
||||
);
|
||||
$this->postAndCheck($feed_node_edit_url, $edit, t('Save'), 'Basic 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, t('Save'), 'Basic 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(), t('Import'));
|
||||
$this->assertText(t('There are no new nodes'));
|
||||
|
||||
// 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-xpathparser0"][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, t('Save'), t('Basic 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, t('Save'), t('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');
|
||||
|
||||
//Cleanup
|
||||
$this->drupalPost("node/$nid/delete-items", array(), t('Delete'));
|
||||
$this->assertText(t('Deleted 29 nodes'));
|
||||
|
||||
$this->_testGetRaw($importer_url);
|
||||
}
|
||||
|
||||
|
||||
public function _testGetRaw($importer_url) {
|
||||
// Change importer defaults.
|
||||
$edit = array(
|
||||
'xpath[context]' => '/html',
|
||||
'xpath[sources][xpathparser:0]' => 'head/title',
|
||||
'xpath[sources][xpathparser:1]' => '*',
|
||||
'xpath[rawXML][xpathparser:1]' => TRUE,
|
||||
);
|
||||
$this->postAndCheck($importer_url, $edit, t('Save'), t('Your changes have been saved.'));
|
||||
$path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_xpathparser') . '/tests/feeds_xpathparser/';
|
||||
$nid = $this->createFeedNode('xpath', $path . 'simple.html', 'Testing GetRaw');
|
||||
$feed_node_edit_url = "node/$nid/edit";
|
||||
$this->assertText(t('Created 1 node'));
|
||||
$url = 'node/' . $nid + 1 . '/edit';
|
||||
$this->drupalGet($url);
|
||||
}
|
||||
}
|
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for FeedsXPathParserXML.inc.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test single feeds.
|
||||
*/
|
||||
class FeedsXPathParserXMLTestCase extends FeedsXPathParserWebTestCase {
|
||||
|
||||
/**
|
||||
* Describe this test.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'XML Parser',
|
||||
'description' => 'Regression tests for Feeds XPath XML parser.',
|
||||
'group' => 'Feeds XPath Parser',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run tests.
|
||||
*/
|
||||
public function test() {
|
||||
$this->createImporterConfiguration('XPathXML', 'xpath_xml');
|
||||
|
||||
$this->setPlugin('xpath_xml', 'FeedsXPathParserXML');
|
||||
$importer_url = $this->feeds_base . '/xpath_xml/settings/FeedsXPathParserXML';
|
||||
// Check help message.
|
||||
$this->drupalGet($importer_url);
|
||||
$this->assertText('No XPath mappings are defined.');
|
||||
|
||||
$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,
|
||||
),
|
||||
)
|
||||
);
|
||||
// Set importer default settings.
|
||||
$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.');
|
||||
|
||||
// Test import.
|
||||
$path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_xpathparser') . '/tests/feeds_xpathparser/';
|
||||
// We use an atom feed so that we can test that default namespaces are being
|
||||
// applied appropriately.
|
||||
$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 nodes');
|
||||
|
||||
// Import again, this verifies url field was mapped correctly.
|
||||
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
|
||||
$this->assertText('There are no new nodes');
|
||||
|
||||
// Assert accuracy of aggregated content. I find humor in using our own
|
||||
// issue queue to run tests against.
|
||||
$this->drupalGet('node');
|
||||
$this->assertText('Atom-Powered Robots Run Amok');
|
||||
$this->assertText('My dog Jack is the best.');
|
||||
$this->assertText('Physics is cool.');
|
||||
|
||||
// Test debugging.
|
||||
$edit = array(
|
||||
'feeds[FeedsXPathParserXML][xpath][exp][debug][xpathparser:0]' => TRUE,
|
||||
);
|
||||
$this->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Basic 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 are no new nodes.');
|
||||
|
||||
// Turn debugging off.
|
||||
$edit = array(
|
||||
'feeds[FeedsXPathParserXML][xpath][exp][debug][xpathparser:0]' => FALSE,
|
||||
);
|
||||
$this->postAndCheck($feed_node_edit_url, $edit, 'Save', 'Basic page Testing XPath XML Parser has been updated.');
|
||||
|
||||
// Check if update existing nodes works.
|
||||
$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', 'Basic page Testing XPath XML Parser has been updated.');
|
||||
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
|
||||
$this->assertText('Updated 1 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.'); // The one that changed.
|
||||
$this->assertNoText('Physics is cool.'); // Make sure the old node is changed.
|
||||
// Be extra sure we updated.
|
||||
$this->drupalGet('node/4');
|
||||
$this->assertText('Physics is really cool.');
|
||||
|
||||
// Check if replace existing nodes works.
|
||||
$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', 'Basic page Testing XPath XML Parser has been updated.');
|
||||
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
|
||||
$this->assertText('Updated 1 node.');
|
||||
$this->drupalGet('node');
|
||||
$this->assertText('Atom-Powered Robots Run Amok');
|
||||
$this->assertText('My dog Jack is the best.');
|
||||
$this->assertText('Physics is cool.'); // The one that changed.
|
||||
$this->assertNoText('Physics is really cool.'); // Make sure the old node is changed.
|
||||
// Be extra sure we updated.
|
||||
$this->drupalGet('node/4');
|
||||
$this->assertText('Physics is cool.');
|
||||
|
||||
// Test that overriding default settings works.
|
||||
$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', 'Basic page Testing XPath XML 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 are no new nodes.');
|
||||
|
||||
// Test that validation works.
|
||||
$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');
|
||||
// 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-feedsxpathparserxml-xpath-context"][1]/@class', 'form-text required error');
|
||||
$this->assertFieldByXPath('//input[@id="edit-feeds-feedsxpathparserxml-xpath-sources-xpathparser0"][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[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', 'Basic page Testing XPath XML Parser has been updated.');
|
||||
|
||||
// Change importer defaults.
|
||||
$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.');
|
||||
|
||||
// Make sure the changes propigated.
|
||||
$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');
|
||||
// Check that our message comes out correct.
|
||||
$this->assertText('Field guid is mandatory and considered unique: only one item per guid value will be created.');
|
||||
|
||||
// Check that allow_override works as expected.
|
||||
$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]');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test variable substitution.
|
||||
*/
|
||||
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,
|
||||
),
|
||||
)
|
||||
);
|
||||
// Set importer default settings.
|
||||
$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.');
|
||||
|
||||
// Test import.
|
||||
$path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_xpathparser') . '/tests/feeds_xpathparser/';
|
||||
// We use an atom feed so that we can test that default namespaces are being
|
||||
// applied appropriately.
|
||||
$nid = $this->createFeedNode('syndication', $path . 'rewrite_test.xml', 'Testing XPath XML Parser');
|
||||
$feed_node_edit_url = 'node/' . $nid . '/edit';
|
||||
$this->assertText('Created 3 nodes');
|
||||
$this->drupalGet('node');
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test cases for the xpath query parser.
|
||||
*/
|
||||
class FeedsXPathParserQueryParserTestCase extends DrupalUnitTestCase {
|
||||
/**
|
||||
* Describe this test.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => t('Query Parser'),
|
||||
'description' => t('Unit tests for the query parser inside Feeds XPath Parser.'),
|
||||
'group' => t('Feeds XPath Parser'),
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
module_load_include('inc', 'feeds_xpathparser', 'FeedsXPathParserQueryParser');
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
$parser = new FeedsXPathParserQueryParser('cow');
|
||||
$this->assertEqual($parser->getQuery(), '__default__:cow');
|
||||
$parser = new FeedsXPathParserQueryParser('/cow');
|
||||
$this->assertEqual($parser->getQuery(), '/__default__:cow');
|
||||
$parser = new FeedsXPathParserQueryParser('/cow/barn');
|
||||
$this->assertEqual($parser->getQuery(), '/__default__:cow/__default__:barn');
|
||||
$parser = new FeedsXPathParserQueryParser('/cow/barn[@id = "asdfsaf"]');
|
||||
$this->assertEqual($parser->getQuery(), '/__default__:cow/__default__:barn[@id = "asdfsaf"]');
|
||||
$parser = new FeedsXPathParserQueryParser('/cow/barn[@id=chair]');
|
||||
$this->assertEqual($parser->getQuery(), '/__default__:cow/__default__:barn[@id=__default__:chair]');
|
||||
$parser = new FeedsXPathParserQueryParser('/cow:asdf');
|
||||
$this->assertEqual($parser->getQuery(), '/cow:asdf');
|
||||
$parser = new FeedsXPathParserQueryParser('@cow');
|
||||
$this->assertEqual($parser->getQuery(), '@cow');
|
||||
$parser = new FeedsXPathParserQueryParser('starts-with(@id, "cat")');
|
||||
$this->assertEqual($parser->getQuery(), 'starts-with(@id, "cat")');
|
||||
$parser = new FeedsXPathParserQueryParser('starts-with(cat/dog/fire:breather, "cat")');
|
||||
$this->assertEqual($parser->getQuery(), 'starts-with(__default__:cat/__default__:dog/fire:breather, "cat")');
|
||||
$parser = new FeedsXPathParserQueryParser('//state[@id = ../city[name="CityName"]/state_id]/name');
|
||||
$this->assertEqual($parser->getQuery(), '//__default__:state[@id = ../__default__:city[__default__:name="CityName"]/__default__:state_id]/__default__:name');
|
||||
$parser = new FeedsXPathParserQueryParser('attribute::lang');
|
||||
$this->assertEqual($parser->getQuery(), 'attribute::lang');
|
||||
$parser = new FeedsXPathParserQueryParser('child::book');
|
||||
$this->assertEqual($parser->getQuery(), 'child::__default__:book');
|
||||
$parser = new FeedsXPathParserQueryParser('child::*');
|
||||
$this->assertEqual($parser->getQuery(), 'child::*');
|
||||
$parser = new FeedsXPathParserQueryParser('child::text()');
|
||||
$this->assertEqual($parser->getQuery(), 'child::text()');
|
||||
$parser = new FeedsXPathParserQueryParser('ancestor-or-self::book');
|
||||
$this->assertEqual($parser->getQuery(), 'ancestor-or-self::__default__:book');
|
||||
$parser = new FeedsXPathParserQueryParser('child::*/child::price');
|
||||
$this->assertEqual($parser->getQuery(), 'child::*/child::__default__:price');
|
||||
$parser = new FeedsXPathParserQueryParser("/asdfasfd[@id = 'a' or @id='b']");
|
||||
$this->assertEqual($parser->getQuery(), "/__default__:asdfasfd[@id = 'a' or @id='b']");
|
||||
// Go! difficult xpath queries from stack overflow.
|
||||
$parser = new FeedsXPathParserQueryParser("id('yui-gen2')/x:div[3]/x:div/x:a[1]");
|
||||
$this->assertEqual($parser->getQuery(), "id('yui-gen2')/x:div[3]/x:div/x:a[1]");
|
||||
$parser = new FeedsXPathParserQueryParser("/descendant::a[@class='buttonCheckout']");
|
||||
$this->assertEqual($parser->getQuery(), "/descendant::__default__:a[@class='buttonCheckout']");
|
||||
$parser = new FeedsXPathParserQueryParser("//a[@href='javascript:void(0)']");
|
||||
$this->assertEqual($parser->getQuery(), "//__default__:a[@href='javascript:void(0)']");
|
||||
$parser = new FeedsXPathParserQueryParser('//*/@attribute');
|
||||
$this->assertEqual($parser->getQuery(), '//*/@attribute');
|
||||
$parser = new FeedsXPathParserQueryParser('/descendant::*[attribute::attribute]');
|
||||
$this->assertEqual($parser->getQuery(), '/descendant::*[attribute::attribute]');
|
||||
$parser = new FeedsXPathParserQueryParser('//Event[not(System/Level = preceding::Level) or not(System/Task = preceding::Task)]');
|
||||
$this->assertEqual($parser->getQuery(), '//__default__:Event[not(__default__:System/__default__:Level = preceding::__default__:Level) or not(__default__:System/__default__:Task = preceding::__default__:Task)]');
|
||||
$parser = new FeedsXPathParserQueryParser("section[@type='cover']/line/@page");
|
||||
$this->assertEqual($parser->getQuery(), "__default__:section[@type='cover']/__default__:line/@page");
|
||||
$parser = new FeedsXPathParserQueryParser('/articles/article/*[name()="title" or name()="short"]');
|
||||
$this->assertEqual($parser->getQuery(), '/__default__:articles/__default__:article/*[name()="title" or name()="short"]');
|
||||
$parser = new FeedsXPathParserQueryParser("/*/article[@id='2']/*[self::title or self::short]");
|
||||
$this->assertEqual($parser->getQuery(), "/*/__default__:article[@id='2']/*[self::__default__:title or self::__default__:short]");
|
||||
$parser = new FeedsXPathParserQueryParser('not(/asdfasfd/asdfasf//asdfasdf) | /asdfasf/sadfasf/@asdf');
|
||||
$this->assertEqual($parser->getQuery(), 'not(/__default__:asdfasfd/__default__:asdfasf//__default__:asdfasdf) | /__default__:asdfasf/__default__:sadfasf/@asdf');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user