Index: tests/mollom.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/mollom/tests/mollom.test,v retrieving revision 1.73 diff -u -p -r1.73 mollom.test --- tests/mollom.test 19 Oct 2010 21:47:03 -0000 1.73 +++ tests/mollom.test 26 Oct 2010 17:23:28 -0000 @@ -580,6 +580,20 @@ class MollomWebTestCase extends DrupalWe } /** + * Replaces the server list to point to the local fake server implementation. + */ + protected function enableTestServer() { + variable_set('mollom_servers', array($GLOBALS['base_url'] . '/xmlrpc.php?version=')); + } + + /** + * Reverts the server list to use real Mollom servers in following requests. + */ + protected function disableTestServer() { + variable_del('mollom_servers'); + } + + /** * Retrieve submitted XML-RPC values from testing server implementation. * * @param $method @@ -2888,6 +2902,99 @@ class MollomAnalysisTestCase extends Mol $this->assertSame('profanity', $data->profanity, $expected['profanity']); $this->assertSame('moderate', $data->moderate, 0); } + + // Verify that no feedback is sent for new, unpublished SPAM comments. + // @todo Entirely rethink which tests actually need to run against the real + // Mollom backend. MollomResponseTestCase might be the only one. + $this->enableTestServer(); + $edit = array( + 'title' => $this->randomString(), + 'body' => 'spam', + ); + $this->drupalPost('mollom-test/form', $edit, 'Submit'); + $mid = $this->assertTestSubmitData(); + $data = $this->assertMollomData('mollom_test', $mid); + $record = mollom_test_load($mid); + $this->assertEqual($record['status'], 0, t('Unpublished test post found.')); + $this->assertSame('spam', $data->spam, MOLLOM_ANALYSIS_SPAM); + $this->assertSame('profanity', $data->profanity, 0); + $this->assertSame('moderate', $data->moderate, 1); + $feedback = $this->getServerRecord('mollom.sendFeedback'); + $this->assertTrue(empty($feedback), t('No feedback sent for the published test post.')); + + // Verify that publishing the post sends feedback. + $this->drupalLogin($this->admin_user); + $edit = array( + 'status' => TRUE, + ); + $this->drupalPost('mollom-test/form/' . $mid, $edit, 'Submit'); + $mid = $this->assertTestSubmitData($mid); + $data = $this->assertMollomData('mollom_test', $mid); + $record = mollom_test_load($mid); + $this->assertEqual($record['status'], 1, t('Published test post found.')); + $this->assertSame('spam', $data->spam, MOLLOM_ANALYSIS_SPAM); + $this->assertSame('profanity', $data->profanity, 0); + $this->assertSame('moderate', $data->moderate, 0); + $feedback = $this->getServerRecord('mollom.sendFeedback'); + $this->assertSame('session_id', $feedback['session_id'], $data->session_id); + $this->assertSame('feedback', $feedback['feedback'], 'ham'); + + // Verify that no feedback is sent for new, published HAM comments. + $this->drupalLogout(); + $edit = array( + 'title' => $this->randomString(), + 'body' => 'ham', + ); + $this->drupalPost('mollom-test/form', $edit, 'Submit'); + $mid = $this->assertTestSubmitData(); + $data = $this->assertMollomData('mollom_test', $mid); + $record = mollom_test_load($mid); + $this->assertEqual($record['status'], 1, t('Published test post found.')); + $this->assertSame('spam', $data->spam, MOLLOM_ANALYSIS_HAM); + $this->assertSame('profanity', $data->profanity, 0); + $this->assertSame('moderate', $data->moderate, 0); + $feedback = $this->getServerRecord('mollom.sendFeedback'); + $this->assertTrue(empty($feedback), t('No feedback sent for the published test post.')); + + // Change the form protection discard bad posts. + $this->drupalLogin($this->admin_user); + $this->setProtection('mollom_test_form', MOLLOM_MODE_ANALYSIS, NULL, array( + 'mollom[discard]' => 1, + )); + $this->drupalLogout(); + + // Verify that no feedback is sent for new, published HAM comments. + $edit = array( + 'title' => $this->randomString(), + 'body' => 'ham', + ); + $this->drupalPost('mollom-test/form', $edit, 'Submit'); + $mid = $this->assertTestSubmitData(); + $data = $this->assertMollomData('mollom_test', $mid); + $record = mollom_test_load($mid); + $this->assertEqual($record['status'], 1, t('Published test post found.')); + $this->assertSame('spam', $data->spam, MOLLOM_ANALYSIS_HAM); + $this->assertSame('profanity', $data->profanity, 0); + $this->assertSame('moderate', $data->moderate, 0); + $feedback = $this->getServerRecord('mollom.sendFeedback'); + $this->assertTrue(empty($feedback), t('No feedback sent for the published test post.')); + + // Verify that no feedback is sent for new, published UNSURE comments. + $edit = array( + 'title' => $this->randomString(), + 'body' => 'unsure', + ); + $this->drupalPost('mollom-test/form', $edit, 'Submit'); + $this->postCorrectCaptcha(NULL, array(), 'Submit'); + $mid = $this->assertTestSubmitData(); + $data = $this->assertMollomData('mollom_test', $mid); + $record = mollom_test_load($mid); + $this->assertEqual($record['status'], 1, t('Published test post found.')); + $this->assertSame('spam', $data->spam, MOLLOM_ANALYSIS_UNSURE); + $this->assertSame('profanity', $data->profanity, 0); + $this->assertSame('moderate', $data->moderate, 0); + $feedback = $this->getServerRecord('mollom.sendFeedback'); + $this->assertTrue(empty($feedback), t('No feedback sent for the published test post.')); } /**