<commit_before><?php

class CoreFormsControllerTest extends \PHPUnit\Framework\TestCase {

    private $defaultSettings = [];

    protected function setUp(): void {
        $this->defaultSettings = [
            "country_blacklist" => Settings::get("country_blacklist")
        ];
        require_once getLanguageFilePath("en");
        Translation::loadAllModuleLanguageFiles("en");


        Settings::set("country_blacklist", "vn,jp,at,tr");
    }

    protected function tearDown(): void {
        $_POST = [];
        $_SERVER = [];

        foreach ($this->defaultSettings as $key => $value) {
            Settings::set($key, $value);
        }
    }

    public function testIncSpamCount() {
        $controller = new CoreFormsController();
        $initialCount = intval(Settings::get("contact_form_refused_spam_mails"));

        for ($i = 1; $i <= 3; $i++) {
            $oldCount = intval(Settings::get("contact_form_refused_spam_mails"));
            $newCount = $controller->_incSpamCount();
            $this->assertIsInt($newCount);
            $this->assertGreaterThan($oldCount, $newCount);
        }

        $this->assertEquals(
                $initialCount + 3,
                intval(Settings::get("contact_form_refused_spam_mails"))
        );
    }

    public function testSpamCheckReturnsNull() {
        $_POST = [
            "foo" => "bar",
            "hello" => "world"
        ];
        $controller = new CoreFormsController();
        $this->assertNull($controller->_spamCheck());
    }

    public function testSpamCheckWithHoneypotFilled() {
        $_POST = [
            "foo" => "bar",
            "hello" => "world",
            "my_homepage_url" => "http://hacker.ru"
        ];
        $controller = new CoreFormsController();
        $this->assertEquals("Honeypot is not empty!", $controller->_spamCheck());
    }

    public function testWithBadWord() {
        $_POST = [
            "foo" => "bar",
            "hello" => "world",
            "spam" => "Viagra"
        ];
        $controller = new CoreFormsController();
        $this->assertEquals("The request contains a bad word: viagra", $controller->_spamCheck());
    }

    public function testWithForbiddenCountry() {
        $_POST = [
            "foo" => "bar",
            "hello" => "world"
        ];
        $_SERVER["REMOTE_ADDR"] = "172.16.17.32";
        $controller = new CoreFormsController();
        $this->assertStringContainsString(
                "Access to this function for your country is blocked",
                $controller->_spamCheck()
        );
    }

}<commit_msg>Update CoreFormsControllerTest.php<commit_after><?php

class CoreFormsControllerTest extends \PHPUnit\Framework\TestCase {

    private $defaultSettings = [];

    protected function setUp(): void {
        $this->defaultSettings = [
            "country_blacklist" => Settings::get("country_blacklist"),
            "reject_requests_from_bots" => Settings::get("reject_requests_from_bots")
        ];
        require_once getLanguageFilePath("en");
        Translation::loadAllModuleLanguageFiles("en");
    }

    protected function tearDown(): void {
        $_POST = [];
        $_SERVER = [];

        foreach ($this->defaultSettings as $key => $value) {
            Settings::set($key, $value);
        }
    }

    public function testIncSpamCount() {
        $controller = new CoreFormsController();
        $initialCount = intval(Settings::get("contact_form_refused_spam_mails"));

        for ($i = 1; $i <= 3; $i++) {
            $oldCount = intval(Settings::get("contact_form_refused_spam_mails"));
            $newCount = $controller->_incSpamCount();
            $this->assertIsInt($newCount);
            $this->assertGreaterThan($oldCount, $newCount);
        }

        $this->assertEquals(
                $initialCount + 3,
                intval(Settings::get("contact_form_refused_spam_mails"))
        );
    }

    public function testSpamCheckReturnsNull() {
        $_POST = [
            "foo" => "bar",
            "hello" => "world"
        ];
        $controller = new CoreFormsController();
        $this->assertNull($controller->_spamCheck());
    }

    public function testSpamCheckWithHoneypotFilled() {
        $_POST = [
            "foo" => "bar",
            "hello" => "world",
            "my_homepage_url" => "http://hacker.ru"
        ];
        $controller = new CoreFormsController();
        $this->assertEquals("Honeypot is not empty!", $controller->_spamCheck());
    }

    public function testWithBadWord() {
        $_POST = [
            "foo" => "bar",
            "hello" => "world",
            "spam" => "Viagra"
        ];
        $controller = new CoreFormsController();
        $this->assertEquals("The request contains a bad word: viagra", $controller->_spamCheck());
    }

    public function testWithForbiddenCountry() {
        Settings::set("country_blacklist", "vn,jp,at,tr");

        $_POST = [
            "foo" => "bar",
            "hello" => "world"
        ];
        $_SERVER["REMOTE_ADDR"] = "172.16.17.32";
        $controller = new CoreFormsController();
        $this->assertStringContainsString(
                "Access to this function for your country is blocked",
                $controller->_spamCheck()
        );
    }

    public function testWithBot() {
        Settings::set("reject_requests_from_bots", "1");

        $_POST = [
            "foo" => "bar",
            "hello" => "world"
        ];
        $_SERVER['HTTP_USER_AGENT'] = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";

        $controller = new CoreFormsController();
        $this->assertStringContainsString(
                "Bots are not allowed to send messages on this website.",
                $controller->_spamCheck()
        );
    }

}
{'fraction_non_alphanumeric': 0.1439354949390976, 'fraction_numerical': 0.004975124378109453, 'mean_word_length': 2.1945205479452055, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '980786', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1590, 'n_words': 297}