View source
<?php
require_once drupal_get_path('module', 'feedapi') . '/tests/feedapi_test_case.tinc';
class FeedAPINodeTestsCase extends FeedAPITestCase {
public static function getInfo() {
return array(
'name' => t('FeedAPI Node basic functions'),
'description' => t('Refresh a feed and find out if it\'s okay. Uses normal node submit form and simplified too. Uses both parsers.'),
'group' => t('FeedAPI'),
);
}
function testFeedAPI_Node() {
$parsers_ok = $this
->get_parsers();
$this
->assertEqual(count($parsers_ok) > 0, TRUE, 'FeedAPI has at least one parser.');
foreach ($parsers_ok as $parser) {
$this
->create_type($parser);
$settings = feedapi_get_settings($this->info->type);
$this
->assertEqual($settings['parsers'][$parser]['enabled'], TRUE, $parser . ' parser is enabled for the content-type ' . $this->info->type);
$this
->feedapi_user();
$feed_url = $this
->testFileURL('test_feed.rss');
$edit = array(
'feedapi[feedapi_url]' => $feed_url,
);
$this
->drupalPost('node/add/' . $this->info->type, $edit, 'Save');
$this
->assertText(t('Link to site'), 'The node is created.');
$nid = db_result(db_query("SELECT nid FROM {feedapi} WHERE url = '%s'", $feed_url));
$vid = db_result(db_query_range("SELECT vid FROM {feedapi} WHERE nid = %d ORDER by vid DESC", $nid, 1, 1));
$this
->assertEqual(is_numeric($nid), TRUE, 'The feed node is in the database');
$feed_node = node_load(array(
'nid' => $nid,
));
$this
->assertEqual(is_object($feed_node->feed), TRUE, 'The feed can be loaded.');
$this
->drupalGet('admin/content/feed');
$this
->assertText('Radiovaticana.org', 'The admin overview page contains the feed title.');
$settings = feedapi_get_settings($this->info->type, $nid);
$settings['items_delete'] = FEEDAPI_NEVER_DELETE_OLD;
_feedapi_store_settings(array(
'vid' => $vid,
), $settings);
$this
->drupalGet("node/{$nid}/refresh");
$notification = t("%new new item(s) were saved. %updated existing item(s) were updated.", array(
"%new" => 10,
"%updated" => 0,
));
$notification = str_replace('<em>', '', $notification);
$notification = str_replace('</em>', '', $notification);
$this
->assertText($notification, 'The proper number of items were created');
$this
->drupalGet('admin/content/feed');
$this
->assertText('10');
$result = db_query("SELECT fi.nid FROM {feedapi_node_item} fi JOIN {feedapi_node_item_feed} ff ON ff.feed_item_nid = fi.nid WHERE ff.feed_nid = %d", $nid);
$types = array();
$author_check = TRUE;
$item_nids = array();
while ($node = db_fetch_array($result)) {
$item_nids[] = $node['nid'];
$node = node_load(array(
'nid' => $node['nid'],
));
$types[] = $node->type;
$title_size[] = strlen($node->title);
$body_size[] = strlen($node->body);
$author_check = $feed_node->uid == $node->uid && $author_check;
}
$types = array_unique($types);
$this
->assertEqual($types[0], 'story', 'The first news item is a story.');
$this
->assertEqual(count($types), 1, 'All news items have the same type.');
sort($title_size);
sort($body_size);
$this
->assertNotEqual($title_size[0], 0, 'All news item titles are longer than 0 character.');
$this
->assertNotEqual($body_size[0], 0, 'All news item bodies are longer than 0 character.');
$this
->assertTrue($author_check, 'All news items has the proper author.');
$this
->drupalPost("node/{$nid}/purge", array(), "Yes");
node_delete($nid);
$item_remain = db_result(db_query("SELECT COUNT(*) FROM {feedapi_node_item} fi JOIN {feedapi_node_item_feed} ff ON ff.feed_item_nid = fi.nid WHERE ff.feed_nid = %d", $nid));
$this
->assertEqual($item_remain, 0, 'All news item database entries are deleted because of feed deletion.');
$node_remain = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE nid IN (" . db_placeholders($item_nids, 'int') . ")", $item_nids));
$this
->assertEqual($node_remain, 0, 'All nodes belonging to a news item are deleted.');
node_get_types('types', NULL, TRUE);
$this
->drupalGet("admin/build/block");
_block_rehash();
$result = db_query("SELECT module, delta FROM {blocks} WHERE status = 1");
$to_disable_blocks = array();
while ($row = db_fetch_array($result)) {
$to_disable_blocks[] = $row;
}
db_query("UPDATE {blocks} SET status = 0 WHERE status = 1");
$region = array_pop(array_keys(system_region_list(variable_get('theme_default', FALSE))));
db_query("UPDATE {blocks} SET status = 1, region='%s' WHERE module = 'feedapi' AND delta = '%s'", $region, $this->info->type);
$this
->drupalGet('node');
$this
->assertText(t('Feed URL'), 'The block is showing up');
$edit = array(
'url' => $feed_url,
);
$this
->drupalPost('node', $edit, 'Add');
$this
->assertText(t('Link to site'), 'The node is created via the simplified form block.');
$nid = db_result(db_query("SELECT nid FROM {feedapi} WHERE url = '%s'", $feed_url));
$this
->assertEqual(is_numeric($nid), TRUE, 'The feed node is in the database');
if (is_numeric($nid)) {
$values = db_fetch_array(db_query("SELECT settings, feed_type, next_refresh_time, half_done FROM {feedapi} WHERE nid = %d", $nid));
$sane_default = TRUE;
$sane_default = $sane_default || is_array($values['settings']) && count($values['settings']) > 1;
$sane_default = $sane_default || $values['feed_type'] == 'XML feed';
$sane_default = $sane_default || $values['next_refresh_time'] == 0;
$sane_default = $sane_default || $values['half_done'] == 0;
$this
->assertIdentical($sane_default, TRUE, "The feed has sane default values in the database table");
node_delete($nid);
}
db_query("UPDATE {blocks} SET status = 0 WHERE module = 'feedapi' AND delta = '%s'", $this->info->type);
foreach ($to_disable_blocks as $to_enable_block) {
db_query("UPDATE {blocks} SET status = 1 WHERE module = '%s' AND delta ='%s'", $to_enable_block['module'], $to_enable_block['delta']);
}
$edit = array(
'feedapi[feedapi_url]' => $feed_url,
'feedapi[refresh_on_create]' => TRUE,
);
$this
->drupalPost('node/add/' . $this->info->type, $edit, 'Save');
$nid = db_result(db_query("SELECT nid FROM {feedapi} WHERE url = '%s'", $feed_url));
$this
->assertEqual(is_numeric($nid), TRUE, 'The feed node is in the database');
$this
->drupalPost("node/{$nid}/purge", array(), "Yes");
node_delete($nid);
$this
->drupalGet('admin/build/block');
}
menu_rebuild();
}
function testKeepNodeSettingsAtUpdate() {
$this
->create_type(array_pop($this
->get_parsers()));
$settings = feedapi_get_settings($this->info->type);
$this
->feedapi_user();
$feed_url = $this
->testFileURL('test_feed.rss');
$edit = array(
'feedapi[feedapi_url]' => $feed_url,
);
$this
->drupalPost('node/add/' . $this->info->type, $edit, 'Save');
$node = db_fetch_object(db_query("SELECT nid FROM {feedapi} WHERE url = '%s'", $feed_url));
$this
->drupalGet("node/{$node->nid}/refresh");
$notification = t("%new new item(s) were saved. %updated existing item(s) were updated.", array(
"%new" => 10,
"%updated" => 0,
));
$notification = str_replace('<em>', '', $notification);
$notification = str_replace('</em>', '', $notification);
$this
->assertText($notification, 'The proper number of items were created');
$title = 'xFgfsfdfsRDFGFes';
$feed_url_new = $this
->testFileURL('test_feed_mod_title.rss');
$sticky = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE sticky = 1"));
$this
->assertTrue($sticky == 0, 'The sticky bit is off by default.');
db_query("UPDATE {node} SET sticky = 1");
db_query("UPDATE {feedapi} SET hash = '%s', url='%s' WHERE nid = %d", $this
->randomName(5), $feed_url_new, $node->nid);
$this
->drupalGet("node/{$node->nid}/refresh");
$not_sticky = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE sticky = 0"));
$this
->assertTrue($not_sticky == 0, 'The sticky bit remained the same just as before the update');
$this
->drupalGet('admin/content/node');
$this
->assertText($title, 'The item node update was successful');
$this
->drupalGet('/');
$this
->assertText($title, 'The item node really appears on the first page.');
}
}