diff --git a/mollom.module b/mollom.module index 531cf53..8d0242b 100644 --- a/mollom.module +++ b/mollom.module @@ -1201,8 +1201,8 @@ function mollom_form_load_all($reset = FALSE) { else { $result = db_query("SELECT * FROM {mollom_form}"); foreach ($result as $mollom_form) { - $mollom_form->enabled_fields = unserialize($mollom_form->enabled_fields); - $mollom_forms[$mollom_form->form_id] = $mollom_form; + $mollom_form->enabled_fields = unserialize($mollom_form->enabled_fields); + $mollom_forms[$mollom_form->form_id] = $mollom_form; } } foreach ($mollom_forms as $id => $mollom_form) { @@ -1214,9 +1214,9 @@ function mollom_form_load_all($reset = FALSE) { // Ensure default values (partially for administrative configuration). $mollom_form += array( - 'form_id' => $id, - 'title' => $id, - 'elements' => array(), + 'form_id' => $id, + 'title' => $id, + 'elements' => array(), ); $mollom_forms[$id] = $mollom_form; @@ -1607,7 +1607,7 @@ function _mollom_get_openid($account) { * The type of entity to check. * @param $bundle * An array of bundle names to check. - * + * * @return array * An array of protected bundles for this entity type. */ diff --git a/tests/mollom.test b/tests/mollom.test index 83c0db1..56edacb 100644 --- a/tests/mollom.test +++ b/tests/mollom.test @@ -442,8 +442,15 @@ class MollomWebTestCase extends DrupalWebTestCase { protected function setProtectionUI($form_id, $mode = MOLLOM_MODE_ANALYSIS, $fields = NULL, $edit = array()) { // Always start from overview page, also to make debugging easier. $this->drupalGet('admin/config/content/mollom'); - // Determine whether the form is already protected. - $exists = db_query_range('SELECT 1 FROM {mollom_form} WHERE form_id = :form_id', 0, 1, array(':form_id' => $form_id))->fetchField(); + + // Load all forms, stored in db and/or code + $forms = mollom_form_load_all(TRUE); + + // Does the form exist already somewhere? + $exists = isset($forms[$form_id]); + // Does it exist in the database? + $in_database = db_query_range('SELECT 1 FROM {mollom_form} WHERE form_id = :form_id', 0, 1, array(':form_id' => $form_id))->fetchField(); + // Add a new form. if (!$exists) { $this->clickLink(t('Add form')); @@ -482,7 +489,11 @@ class MollomWebTestCase extends DrupalWebTestCase { } } $this->drupalPost(NULL, $edit, t('Save')); - if (!$exists) { + + if (!$exists && !$in_database) { + $this->assertText(t('The form protection has been added.')); + } + elseif ($exists && !$in_database) { $this->assertText(t('The form protection has been added.')); } else { @@ -1050,7 +1061,7 @@ class MollomTestingExportingFormConfiguration extends MollomWebTestCase { // Does the export contains valid PHP code? $this->assertRaw('$mollom_form = new stdClass();'); - // Check if there exported form configuration is loaded in the overview + // Check if the exported form configuration is loaded in the overview $this->drupalGet('admin/config/content/mollom'); $this->assertText('Mollom exported basic test form'); @@ -1075,14 +1086,21 @@ class MollomTestingExportingFormConfiguration extends MollomWebTestCase { $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. + $edit = array( + 'mollom[strictness]' => 'relaxed', + ); + $this->setProtectionUI('mollom_exported_basic_test_form', MOLLOM_MODE_ANALYSIS, NULL, $edit); + $this->assertText('Database overriding code'); + + // Check if we can update an already overridden form configuration $this->setProtectionUI('mollom_exported_basic_test_form', MOLLOM_MODE_CAPTCHA); // Check if we can revert the form configuration to default - // @todo - // After previous todo + $links = $this->xpath('//td[contains(., :text)]/following-sibling::td/a', array(':text' => 'Mollom exported basic test form')); + $revert_url = (string) $links[2]['href']; + $this->assertLinkByHref($revert_url); + $this->drupalPost($revert_url, array(), t('Confirm')); + $this->assertText('In code'); } }