feeds_news.test 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * @file
  4. * Tests for feeds_news feature.
  5. */
  6. /**
  7. * Test Feed configuration.
  8. */
  9. class FeedsExamplesFeedTestCase extends FeedsWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Feature: Feed',
  13. 'description' => 'Test "Feed" default configuration.',
  14. 'group' => 'Feeds',
  15. 'dependencies' => array('features', 'views'),
  16. );
  17. }
  18. public function setUp() {
  19. parent::setUp(array('features', 'views', 'feeds_news'));
  20. }
  21. /**
  22. * Run tests.
  23. */
  24. public function test() {
  25. $nid = $this->createFeedNode('feed', NULL, '', 'feed');
  26. // Assert menu tabs for feed nodes does not show up on non-feed nodes.
  27. $this->drupalGet("node/{$nid}/feed-items");
  28. $this->assertResponse(200);
  29. $not_feed_node = $this->drupalCreateNode();
  30. $this->drupalGet("node/{$not_feed_node->nid}/feed-items");
  31. $this->assertResponse(404);
  32. // Assert results.
  33. $count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'feed_item'")->fetchField();
  34. $this->assertEqual($count, 10, 'Found the correct number of feed item nodes in database.');
  35. $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
  36. $this->assertEqual($count, 10, 'Found the correct number of records in feeds_item.');
  37. $count = db_query("SELECT COUNT(*) FROM {node} WHERE title = 'Open Atrium Translation Workflow: Two Way Translation Updates'")->fetchField();
  38. $this->assertEqual($count, 1, 'Found title.');
  39. $count = db_query("SELECT COUNT(*) FROM {node} WHERE title = 'Week in DC Tech: October 5th Edition'")->fetchField();
  40. $this->assertEqual($count, 1, 'Found title.');
  41. $count = db_query("SELECT COUNT(*) FROM {node} WHERE title = 'Integrating the Siteminder Access System in an Open Atrium-based Intranet'")->fetchField();
  42. $this->assertEqual($count, 1, 'Found title.');
  43. $count = db_query("SELECT COUNT(*) FROM {node} WHERE title = 'Scaling the Open Atrium UI'")->fetchField();
  44. $this->assertEqual($count, 1, 'Found title.');
  45. $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node' AND url = 'http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating'")->fetchField();
  46. $this->assertEqual($count, 1, 'Found feed_node_item record.');
  47. $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node' AND url = 'http://developmentseed.org/blog/2009/oct/05/week-dc-tech-october-5th-edition'")->fetchField();
  48. $this->assertEqual($count, 1, 'Found feed_node_item record.');
  49. $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node' AND guid = '974 at http://developmentseed.org'")->fetchField();
  50. $this->assertEqual($count, 1, 'Found feed_node_item record.');
  51. $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node' AND guid = '970 at http://developmentseed.org'")->fetchField();
  52. $this->assertEqual($count, 1, 'Found feed_node_item record.');
  53. // Remove all items
  54. $this->drupalPost("node/$nid/delete-items", array(), 'Delete');
  55. $this->assertText('Deleted 10 nodes');
  56. // Import again.
  57. $this->drupalPost("node/$nid/import", array(), 'Import');
  58. $this->assertText('Created 10 nodes');
  59. // Delete and assert all items gone.
  60. $this->drupalPost("node/$nid/delete-items", array(), 'Delete');
  61. $count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'feed_item'")->fetchField();
  62. $this->assertEqual($count, 0, 'Found the correct number of feed item nodes in database.');
  63. $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
  64. $this->assertEqual($count, 0, 'Found the correct number of records in feeds_item.');
  65. // Create a batch of nodes.
  66. $this->createFeedNodes('feed', 10, 'feed');
  67. $count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'feed_item'")->fetchField();
  68. $this->assertEqual($count, 100, 'Imported 100 nodes.');
  69. $count = db_query("SELECT COUNT(*) FROM {feeds_item} WHERE entity_type = 'node'")->fetchField();
  70. $this->assertEqual($count, 100, 'Found 100 records in feeds_item.');
  71. }
  72. }
  73. /**
  74. * Test OPML import configuration.
  75. */
  76. class FeedsExamplesOPMLTestCase extends FeedsWebTestCase {
  77. public static function getInfo() {
  78. return array(
  79. 'name' => 'Feature: OPML import',
  80. 'description' => 'Test "OPML import" default configuration.',
  81. 'group' => 'Feeds',
  82. );
  83. }
  84. /**
  85. * Enable feeds_news feature.
  86. */
  87. public function setUp() {
  88. parent::setUp(array('feeds_news'));
  89. }
  90. /**
  91. * Run tests.
  92. */
  93. public function test() {
  94. // Import OPML and assert.
  95. $file = $this->generateOPML();
  96. $this->importFile('opml', $file);
  97. $this->assertText('Created 3 nodes');
  98. $count = db_query("SELECT COUNT(*) FROM {feeds_source}")->fetchField();
  99. $this->assertEqual($count, 4, 'Found correct number of items.');
  100. // Import a feed and then delete all items from it.
  101. $this->drupalPost('node/1/import', array(), 'Import');
  102. $this->assertText('Created 10 nodes');
  103. $this->drupalPost('node/1/delete-items', array(), 'Delete');
  104. $this->assertText('Deleted 10 nodes');
  105. }
  106. }