word filter tests

This commit is contained in:
Shish 2015-09-20 20:18:55 +01:00
parent 90cd823ece
commit ff8da5be8e

View File

@ -1,56 +1,67 @@
<?php <?php
class WordFilterTest { class WordFilterTest extends ShimmiePHPUnitTestCase {
function testWordFilter() { function setUp() {
$this->log_in_as_admin(); global $config;
$this->get_page("setup"); parent::setUp();
$this->set_field("_config_word_filter", "whore,nice lady\na duck,a kitten\n white ,\tspace\ninvalid"); $config->set_string("word_filter", "whore,nice lady\na duck,a kitten\n white ,\tspace\ninvalid");
$this->click("Save Settings"); }
$this->log_out();
function _doThings($in, $out) {
global $user;
$this->log_in_as_user(); $this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
send_event(new CommentPostingEvent($image_id, $user, $in));
$this->get_page("post/view/$image_id"); $this->get_page("post/view/$image_id");
$this->assert_text($out);
}
# regular function testRegular() {
$this->set_field('comment', "posted by a whore"); $this->_doThings(
$this->click("Post Comment"); "posted by a whore",
$this->assert_text("posted by a nice lady"); "posted by a nice lady"
);
}
# replace all instances function testReplaceAll() {
$this->set_field('comment', "a whore is a whore is a whore"); $this->_doThings(
$this->click("Post Comment"); "a whore is a whore is a whore",
$this->assert_text("a nice lady is a nice lady is a nice lady"); "a nice lady is a nice lady is a nice lady"
);
}
# still have effect when case is changed function testMixedCase() {
$this->set_field('comment', "monkey WhorE"); $this->_doThings(
$this->click("Post Comment"); "monkey WhorE",
$this->assert_text("monkey nice lady"); "monkey nice lady"
);
}
# only do whole words function testOnlyWholeWords() {
$this->set_field('comment', "my name is whoretta"); $this->_doThings(
$this->click("Post Comment"); "my name is whoretta",
$this->assert_text("my name is whoretta"); "my name is whoretta"
);
}
# search multiple words function testMultipleWords() {
$this->set_field('comment', "I would like a duck"); $this->_doThings(
$this->click("Post Comment"); "I would like a duck",
$this->assert_text("I would like a kitten"); "I would like a kitten"
);
}
# test for a line which was entered with extra whitespace function testWhitespace() {
$this->set_field('comment', "A colour is white"); $this->_doThings(
$this->click("Post Comment"); "A colour is white",
$this->assert_text("A colour is space"); "A colour is space"
);
}
# don't do anything with invalid lines function testIgnoreInvalid() {
$this->set_field('comment', "The word was invalid"); $this->_doThings(
$this->click("Post Comment"); "The word was invalid",
$this->assert_text("The word was invalid"); "The word was invalid"
);
$this->log_out();
$this->log_in_as_admin();
$this->delete_image($image_id);
$this->log_out();
} }
} }