public function BotchaTestAdminLog::testAdminLog in BOTCHA Spam Prevention 6.3
Same name and namespace in other branches
- 7.3 tests/botcha.simpletest.test \BotchaTestAdminLog::testAdminLog()
Testing of placing messages into log.
File
- tests/
botcha.simpletest.test, line 776 - Simpletest-tests for BOTCHA module.
Class
Code
public function testAdminLog() {
// Unit testing: assume that correct work of other parts is tested elsewhere.
$recipebook_controller = $this->application
->getController(Botcha::CONTROLLER_TYPE_RECIPEBOOK);
$recipebook = $recipebook_controller
->getRecipebook();
// Fill in results array randomly to emulate spam check.
$is_spam = array();
$recipes_spam = array();
foreach ($recipebook
->getRecipes() as $recipe_id) {
$value = (bool) rand(0, 1);
$is_spam[$recipe_id] = $value;
if ($value) {
$recipes_spam[$recipe_id] = $recipe_id;
}
}
$count_recipes = count($is_spam);
$count_spam = count($recipes_spam);
$form_id = 'test_form_id';
$form = array();
$form['form_id']['#value'] = $form_id;
// Test success case.
// @todo Remove hardcode.
$recipebook
->handle('success', $form, array(), $is_spam);
$this
->drupalGet('admin/reports/dblog');
// @todo Assert that there is success message.
//$this->assertText(t('Checked %count botchas (%recipes_list)', array('%count' => $count_recipes, '%recipes_list' => implode(', ', $is_spam))), 'Success message is in log', 'BOTCHA');
// Test spam case.
// @todo Remove hardcode.
$recipebook
->handle('spam', $form, array(), $is_spam);
$this
->drupalGet('admin/reports/dblog');
// @todo It looks like being sometimes failed => find better way to click a link, that contains our form id.
// @todo Abstract it.
$this
->clickLink("{$form_id} post blocked by BOTCHA: submission ...");
// Assert that there is a spam message.
// We should pass plain text - so t() doesn't fit.
//$message = t('Failed %count_spam of %count_recipes recipes [%recipes_list] from "%rbid" recipe book.', array('%count_spam' => $count_spam, '%count_recipes' => $count_recipes, '%recipes_list' => implode(', ', $recipes_spam), '%rbid' => $recipebook->id));
$message = str_replace(array(
'%count_spam',
'%count_recipes',
'%recipes_list',
'%rbid',
), array(
$count_spam,
$count_recipes,
implode(', ', $recipes_spam),
$recipebook->id,
), 'Failed %count_spam of %count_recipes recipes [%recipes_list] from "%rbid" recipe book.');
$this
->assertText($message, 'Expected spam message \'' . $message . '\' is in log', 'BOTCHA');
}