feeds_mapper_config.test 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * @file
  4. * Contains FeedsMapperConfigTestCase.
  5. */
  6. /**
  7. * Test cases for Feeds mapping configuration form.
  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. $second_callback_value = $this->randomString();
  35. // Set some settings.
  36. $edit = array(
  37. 'config[0][settings][checkbox]' => 1,
  38. 'config[0][settings][textfield]' => 'Some text',
  39. 'config[0][settings][textarea]' => 'Textarea value: Didery dofffffffffffffffffffffffffffffffffffff',
  40. 'config[0][settings][radios]' => 'option1',
  41. 'config[0][settings][select]' => 'option4',
  42. 'config[0][settings][second_value]' => $second_callback_value,
  43. );
  44. $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_0');
  45. $this->assertText(t('* Changes made to target configuration are stored temporarily. Click Save to make your changes permanent.'));
  46. // Click Save.
  47. $this->drupalPost(NULL, array(), t('Save'));
  48. // Reload.
  49. $this->drupalGet('admin/structure/feeds/syndication/mapping');
  50. // See if our settings were saved.
  51. $this->assertText('Checkbox active.');
  52. $this->assertText('Textfield value: Some text');
  53. $this->assertText('Textarea value: Didery dofffffffffffffffffffffffffffffffffffff');
  54. $this->assertText('Radios value: Option 1');
  55. $this->assertText('Select value: Another One');
  56. $this->assertText(t('Second summary: @value', array('@value' => $second_callback_value)));
  57. // Check that settings are in db.
  58. $config = unserialize(db_query("SELECT config FROM {feeds_importer} WHERE id='syndication'")->fetchField());
  59. $settings = $config['processor']['config']['mappings'][0];
  60. $this->assertEqual($settings['checkbox'], 1);
  61. $this->assertEqual($settings['textfield'], 'Some text');
  62. $this->assertEqual($settings['textarea'], 'Textarea value: Didery dofffffffffffffffffffffffffffffffffffff');
  63. $this->assertEqual($settings['radios'], 'option1');
  64. $this->assertEqual($settings['select'], 'option4');
  65. $this->assertEqual($settings['second_value'], $second_callback_value);
  66. // Check that form validation works.
  67. // Click gear to get form.
  68. $this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_0');
  69. // Set some settings.
  70. $edit = array(
  71. // Required form item.
  72. 'config[0][settings][textfield]' => '',
  73. );
  74. $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_0');
  75. $this->assertText('A text field field is required.');
  76. $this->drupalPost(NULL, array(), t('Save'));
  77. // Reload.
  78. $this->drupalGet('admin/structure/feeds/syndication/mapping');
  79. // Value has not changed.
  80. $this->assertText('Textfield value: Some text');
  81. // Check that multiple mappings work.
  82. $this->addMappings('syndication', array(
  83. 1 => array(
  84. 'source' => 'url',
  85. 'target' => 'test_target',
  86. ),
  87. ));
  88. $this->assertText('Checkbox active.');
  89. $this->assertText('Checkbox inactive.');
  90. // Click gear to get form.
  91. $this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_1');
  92. // Set some settings.
  93. $edit = array(
  94. 'config[1][settings][textfield]' => 'Second mapping text',
  95. );
  96. $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_1');
  97. // Click Save.
  98. $this->drupalPost(NULL, array(), t('Save'));
  99. // Reload.
  100. $this->drupalGet('admin/structure/feeds/syndication/mapping');
  101. $this->assertText('Checkbox active.');
  102. $this->assertText('Checkbox inactive.');
  103. $this->assertText('Second mapping text');
  104. }
  105. }