feeds_mapper_config.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @file
  4. * Test cases for Feeds mapping configuration form.
  5. */
  6. /**
  7. * Class for testing basic Feeds ajax mapping configurtaion form behavior.
  8. */
  9. class FeedsMapperConfigTestCase extends FeedsMapperTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Mapper: Config',
  13. 'description' => 'Test the mapper configuration UI.',
  14. 'group' => 'Feeds',
  15. );
  16. }
  17. public function setUp() {
  18. parent::setUp(array('feeds_tests'));
  19. }
  20. /**
  21. * Basic test of mapping configuration.
  22. */
  23. public function test() {
  24. // Create importer configuration.
  25. $this->createImporterConfiguration();
  26. $this->addMappings('syndication', array(
  27. array(
  28. 'source' => 'url',
  29. 'target' => 'test_target',
  30. ),
  31. ));
  32. // Click gear to get form.
  33. $this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_0');
  34. // Set some settings.
  35. $edit = array(
  36. 'config[0][settings][checkbox]' => 1,
  37. 'config[0][settings][textfield]' => 'Some text',
  38. 'config[0][settings][textarea]' => 'Textarea value: Didery dofffffffffffffffffffffffffffffffffffff',
  39. 'config[0][settings][radios]' => 'option1',
  40. 'config[0][settings][select]' => 'option4',
  41. );
  42. $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_0');
  43. // Click Save.
  44. $this->drupalPost(NULL, array(), t('Save'));
  45. // Reload.
  46. $this->drupalGet('admin/structure/feeds/syndication/mapping');
  47. // See if our settings were saved.
  48. $this->assertText('Checkbox active.');
  49. $this->assertText('Textfield value: Some text');
  50. $this->assertText('Textarea value: Didery dofffffffffffffffffffffffffffffffffffff');
  51. $this->assertText('Radios value: Option 1');
  52. $this->assertText('Select value: Another One');
  53. // Check that settings are in db.
  54. $config = unserialize(db_query("SELECT config FROM {feeds_importer} WHERE id='syndication'")->fetchField());
  55. $settings = $config['processor']['config']['mappings'][0];
  56. $this->assertEqual($settings['checkbox'], 1);
  57. $this->assertEqual($settings['textfield'], 'Some text');
  58. $this->assertEqual($settings['textarea'], 'Textarea value: Didery dofffffffffffffffffffffffffffffffffffff');
  59. $this->assertEqual($settings['radios'], 'option1');
  60. $this->assertEqual($settings['select'], 'option4');
  61. // Check that form validation works.
  62. // Click gear to get form.
  63. $this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_0');
  64. // Set some settings.
  65. $edit = array(
  66. // Required form item.
  67. 'config[0][settings][textfield]' => '',
  68. );
  69. $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_0');
  70. $this->assertText('A text field field is required.');
  71. $this->drupalPost(NULL, array(), t('Save'));
  72. // Reload.
  73. $this->drupalGet('admin/structure/feeds/syndication/mapping');
  74. // Value has not changed.
  75. $this->assertText('Textfield value: Some text');
  76. // Check that multiple mappings work.
  77. $this->addMappings('syndication', array(
  78. 1 => array(
  79. 'source' => 'url',
  80. 'target' => 'test_target',
  81. ),
  82. ));
  83. $this->assertText('Checkbox active.');
  84. $this->assertText('Checkbox inactive.');
  85. // Click gear to get form.
  86. $this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_1');
  87. // Set some settings.
  88. $edit = array(
  89. 'config[1][settings][textfield]' => 'Second mapping text',
  90. );
  91. $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_1');
  92. // Click Save.
  93. $this->drupalPost(NULL, array(), t('Save'));
  94. // Reload.
  95. $this->drupalGet('admin/structure/feeds/syndication/mapping');
  96. $this->assertText('Checkbox active.');
  97. $this->assertText('Checkbox inactive.');
  98. $this->assertText('Second mapping text');
  99. }
  100. }