feeds_ui.test 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * @file
  4. * Tests for Feeds Admin UI module.
  5. */
  6. /**
  7. * Test basic Feeds UI functionality.
  8. */
  9. class FeedsUIUserInterfaceTestCase extends FeedsWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Feeds UI user interface',
  13. 'description' => 'Tests Feeds Admin UI module\'s GUI.',
  14. 'group' => 'Feeds',
  15. );
  16. }
  17. public function setUp() {
  18. parent::setUp(array('php'), array('use PHP for settings'));
  19. }
  20. /**
  21. * UI functionality tests on
  22. * feeds_ui_overview(),
  23. * feeds_ui_create_form(),
  24. * Change plugins on feeds_ui_edit_page().
  25. */
  26. public function testEditFeedConfiguration() {
  27. // Create an importer.
  28. $this->createImporterConfiguration('Test feed', 'test_feed');
  29. // Assert UI elements.
  30. $this->drupalGet('admin/structure/feeds/test_feed');
  31. $this->assertText('Basic settings');
  32. $this->assertText('Fetcher');
  33. $this->assertText('HTTP Fetcher');
  34. $this->assertText('Parser');
  35. $this->assertText('Common syndication parser');
  36. $this->assertText('Processor');
  37. $this->assertText('Node processor');
  38. $this->assertText('Getting started');
  39. $this->assertRaw('admin/structure/feeds/test_feed/settings');
  40. $this->assertRaw('admin/structure/feeds/test_feed/settings/FeedsNodeProcessor');
  41. $this->assertRaw('admin/structure/feeds/test_feed/fetcher');
  42. $this->assertRaw('admin/structure/feeds/test_feed/parser');
  43. $this->assertRaw('admin/structure/feeds/test_feed/processor');
  44. $this->drupalGet('import');
  45. $this->assertText('Basic page');
  46. // Select some other plugins.
  47. $this->drupalGet('admin/structure/feeds/test_feed');
  48. $this->clickLink('Change', 0);
  49. $this->assertText('Select a fetcher');
  50. $edit = array(
  51. 'plugin_key' => 'FeedsFileFetcher',
  52. );
  53. $this->drupalPost('admin/structure/feeds/test_feed/fetcher', $edit, 'Save');
  54. $this->clickLink('Change', 1);
  55. $this->assertText('Select a parser');
  56. $edit = array(
  57. 'plugin_key' => 'FeedsCSVParser',
  58. );
  59. $this->drupalPost('admin/structure/feeds/test_feed/parser', $edit, 'Save');
  60. $this->clickLink('Change', 2);
  61. $this->assertText('Select a processor');
  62. $edit = array(
  63. 'plugin_key' => 'FeedsUserProcessor',
  64. );
  65. $this->drupalPost('admin/structure/feeds/test_feed/processor', $edit, 'Save');
  66. // Assert changed configuration.
  67. $this->assertPlugins('test_feed', 'FeedsFileFetcher', 'FeedsCSVParser', 'FeedsUserProcessor');
  68. // Delete importer.
  69. $this->drupalPost('admin/structure/feeds/test_feed/delete', array(), 'Delete');
  70. $this->drupalGet('import');
  71. $this->assertNoText('Test feed');
  72. // Create the same importer again.
  73. $this->createImporterConfiguration('Test feed', 'test_feed');
  74. // Test basic settings settings.
  75. $edit = array(
  76. 'name' => 'Syndication feed',
  77. 'content_type' => 'page',
  78. 'import_period' => 3600,
  79. );
  80. $this->setSettings('test_feed', NULL, $edit);
  81. // Assert results of change.
  82. $this->assertText('Syndication feed');
  83. $this->assertText('Your changes have been saved.');
  84. $this->assertText('Attached to: Basic page');
  85. $this->assertText('Periodic import: every 1 hour');
  86. $this->drupalGet('admin/structure/feeds');
  87. $this->assertLink('Basic page');
  88. // Configure processor.
  89. $this->setSettings('test_feed', 'FeedsNodeProcessor', array('bundle' => 'article'));
  90. $this->assertFieldByName('bundle', 'article');
  91. // Create a feed node.
  92. $edit = array(
  93. 'title' => 'Development Seed',
  94. 'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
  95. );
  96. $this->drupalPost('node/add/page', $edit, 'Save');
  97. $this->assertText('Basic page Development Seed has been created.');
  98. // @todo Refreshing/deleting feed items. Needs to live in feeds.test
  99. }
  100. public function testImporterImport() {
  101. $name = $this->randomString();
  102. $id = drupal_strtolower($this->randomName());
  103. $this->createImporterConfiguration($name, $id);
  104. $this->setPlugin($id, 'FeedsCSVParser');
  105. $this->setPlugin($id, 'FeedsFileFetcher');
  106. $this->setPlugin($id, 'FeedsUserProcessor');
  107. $this->setSettings($id, 'FeedsFileFetcher', array('allowed_extensions' => 'xml'));
  108. $this->setSettings($id, 'FeedsCSVParser', array('delimiter' => '|'));
  109. $this->setSettings($id, 'FeedsUserProcessor', array('skip_hash_check' => TRUE));
  110. $this->drupalGet('admin/structure/feeds/' . $id . '/export');
  111. $export = $this->xpath('//textarea[1]/text()');
  112. $export = (string) $export[0];
  113. // Delete this importer.
  114. $this->drupalPost('admin/structure/feeds/' . $id . '/delete', array(), t('Delete'));
  115. // Try to import.
  116. $this->drupalPost('admin/structure/feeds/import', array('importer' => $export), t('Import'));
  117. $this->assertText("Successfully imported the $id feeds importer.");
  118. // Check that the settings are correct.
  119. $importer = feeds_importer($id);
  120. $this->assertEqual('FeedsFileFetcher', get_class($importer->fetcher));
  121. $this->assertEqual('FeedsCSVParser', get_class($importer->parser));
  122. $this->assertEqual('FeedsUserProcessor', get_class($importer->processor));
  123. $config = $importer->fetcher->getConfig();
  124. $this->assertEqual('xml', $config['allowed_extensions']);
  125. $config = $importer->parser->getConfig();
  126. $this->assertEqual('|', $config['delimiter']);
  127. $config = $importer->processor->getConfig();
  128. $this->assertTrue($config['skip_hash_check']);
  129. }
  130. }