diff --git a/.gitignore b/.gitignore index e43b0f9..16231e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .DS_Store +/vendor +/composer.lock +/.phpunit.result.cache \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..2f05501 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "phpunit/phpunit": "^9.5" + } +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..97da343 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,20 @@ + + + + + tests + + + + + + + \ No newline at end of file diff --git a/tests/Test.php b/tests/Test.php new file mode 100644 index 0000000..16c5a06 --- /dev/null +++ b/tests/Test.php @@ -0,0 +1,55 @@ +blacklist = file_get_contents($filename); + } + } + + public function testFalsePositives() + { + $this->runTestInFolder('false_positives'); + } + + public function testFalseNegatives() { + $this->runTestInFolder('false_negatives'); + } + + private function runTestInFolder($folder) { + $files = $this->getFilesInFolder($folder); + foreach($files as $files__value) { + $file_content = file_get_contents(__DIR__ . '/' . $folder . '/' . $files__value); + foreach(explode("\n", $file_content) as $file_content__value) { + if( $file_content__value == '' ) { continue; } + $match = null; + foreach(explode("\n", $this->blacklist) as $blacklist__value) { + if( $blacklist__value == '' ) { continue; } + $pattern = sprintf('#%s#i', preg_quote($blacklist__value, '#')); + if( preg_match($pattern, $file_content__value) ) { + $match = ['blacklist' => $blacklist__value, 'string' => $file_content__value]; + break; + } + } + if( $folder === 'false_positives' && $match !== null ) { + $this->assertEquals('"'.$match['string'].'" => "'.$match['blacklist']. '"', 'FALSELY DETECTED AS SPAM'); + } + else if( $folder === 'false_negatives' && $match === null ) { + $this->assertEquals($file_content__value, 'FALSELY NOT DETECTED AS SPAM'); + } + else { + $this->assertTrue(true); + } + } + } + } + + private function getFilesInFolder($folder) { + if( !is_string($folder) || $folder == '' || !is_dir(__DIR__ . '/' . $folder) ) { return []; } + return array_diff(scandir(__DIR__ . '/' . $folder), ['.', '..']); + } +} \ No newline at end of file diff --git a/tests/false_negatives/2021-09-15.txt b/tests/false_negatives/2021-09-15.txt new file mode 100644 index 0000000..934ee09 --- /dev/null +++ b/tests/false_negatives/2021-09-15.txt @@ -0,0 +1,2 @@ +loli*ta gi*rl fu*ck c*p pt*hc +I do spy software your website. diff --git a/tests/false_positives/2021-09-15.txt b/tests/false_positives/2021-09-15.txt new file mode 100644 index 0000000..54be307 --- /dev/null +++ b/tests/false_positives/2021-09-15.txt @@ -0,0 +1,12 @@ +foobar@icloud.com +foobar@yahoo.com +foobar@1und1.de +foobar@ionos.de +foobar@gmail.com +foobar@freenet.de +foobar@aol.com +foobar@outlook.de +foobar@t-online.de +foobar@web.de +foobar@gmx.de +foobar@gmx.net