diff --git a/tests/mollom.test b/tests/mollom.test index 28d9c81..83c0db1 100644 --- a/tests/mollom.test +++ b/tests/mollom.test @@ -1010,6 +1010,83 @@ class MollomWebTestCase extends DrupalWebTestCase { } /** + * Tests exporting form configuration functionality. + */ +class MollomTestingExportingFormConfiguration extends MollomWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Exporting form configuration', + 'description' => 'Tests exporting of form configuration with CTools.', + 'group' => 'Mollom', + ); + } + + function setUp() { + parent::setUp(array('mollom', 'mollom_test', 'ctools')); + + $this->admin_user = $this->drupalCreateUser(array( + 'access administration pages', + 'administer mollom', + )); + } + + function testExportingFormConfiguration() { + $this->drupalLogin($this->admin_user); + + // Create a new form configuration + $this->setProtectionUI('mollom_basic_test_form', MOLLOM_MODE_ANALYSIS); + + // Check if we can export it + $this->assertLinkByHref('admin/config/content/mollom/export/mollom_basic_test_form'); + $this->assertText('In database'); + $links = $this->xpath('//td[contains(., :text)]/a', array(':text' => 'In database')); + + // Is there a valid export link? + $export_url = (string) $links[0]['href']; + $this->assertLinkByHref($export_url); + $export_url = $GLOBALS['base_root'] . $export_url; + $this->drupalGet($export_url); + + // Does the export contains valid PHP code? + $this->assertRaw('$mollom_form = new stdClass();'); + + // Check if there exported form configuration is loaded in the overview + $this->drupalGet('admin/config/content/mollom'); + $this->assertText('Mollom exported basic test form'); + + // Check if not overridden at this time + $this->assertText('In code'); + $this->assertText('Disable'); + + $links = $this->xpath('//td[contains(., :text)]/following-sibling::td/a', array(':text' => 'Mollom exported basic test form')); + + // Check if we can disable/enable the form configuration + $disable_url = (string) $links[1]['href']; + $this->assertLinkByHref($disable_url); + $this->drupalPost($disable_url, array(), t('Confirm')); + $this->assertText('Enable'); + $this->assertText('Disabled'); + + $links = $this->xpath('//td[contains(., :text)]/following-sibling::td/a', array(':text' => 'Mollom exported basic test form')); + + $enable_url = (string) $links[1]['href']; + $this->assertLinkByHref($enable_url); + $this->drupalPost($enable_url, array(), t('Confirm')); + $this->assertText('Disable'); + + // Check if we can override the form configuration + // @todo + // Breaks at this time, since mollom_form is not updated when an exported + // form configuration is added, but no configuration was set beforehand. + $this->setProtectionUI('mollom_exported_basic_test_form', MOLLOM_MODE_CAPTCHA); + + // Check if we can revert the form configuration to default + // @todo + // After previous todo + } +} + +/** * Tests testing mode functionality. */ class MollomTestingModeTestCase extends MollomWebTestCase { diff --git a/tests/mollom_test.module b/tests/mollom_test.module index 5f3c701..b788d95 100644 --- a/tests/mollom_test.module +++ b/tests/mollom_test.module @@ -6,6 +6,15 @@ */ /** + * Implements hook_ctools_plugin_api(). + */ +function mollom_test_ctools_plugin_api($module = NULL, $api = NULL) { + if ($module == "mollom" && $api == "mollom") { + return array("version" => "1"); + } +} + +/** * Implements hook_entity_info(). */ function mollom_test_entity_info() { @@ -61,6 +70,10 @@ function mollom_forms() { $forms['mollom_basic_test_form'] = array( 'callback' => 'mollom_test_form', ); + + $forms['mollom_exported_basic_test_form'] = array( + 'callback' => 'mollom_test_form', + ); return $forms; } @@ -80,6 +93,10 @@ function mollom_test_mollom_form_list() { $forms['mollom_basic_test_form'] = array( 'title' => 'Mollom basic test form', ); + // Same as above, but with exported form configuration. + $forms['mollom_exported_basic_test_form'] = array( + 'title' => 'Mollom exported basic test form', + ); // Same as above, but supports elements for text analysis. $forms['mollom_basic_elements_test_form'] = array( 'title' => 'Mollom basic elements test form', diff --git a/tests/mollom_test.mollom.inc b/tests/mollom_test.mollom.inc new file mode 100644 index 0000000..bb32238 --- /dev/null +++ b/tests/mollom_test.mollom.inc @@ -0,0 +1,37 @@ +disabled = FALSE; /* Edit this to true to make a default mollom_form disabled initially */ + $mollom_form->api_version = 1; + $mollom_form->form_id = 'mollom_exported_basic_test_form'; + $mollom_form->entity = ''; + $mollom_form->bundle = ''; + $mollom_form->mode = 2; + $mollom_form->checks = array( + 0 => 'spam', + ); + $mollom_form->unsure = 'captcha'; + $mollom_form->discard = TRUE; + $mollom_form->moderation = FALSE; + $mollom_form->enabled_fields = array( + 0 => 'title', + 1 => 'body', + 2 => 'exclude', + 3 => 'parent][child', + 4 => 'field', + ); + $mollom_form->strictness = 'normal'; + $mollom_form->module = 'mollom_test'; + + $export['mollom_exported_basic_test_form'] = $mollom_form; + + return $export; +}