forked from splorp/wordpress-comment-blacklist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
.DS_Store | ||
/vendor | ||
/composer.lock | ||
/.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
verbose="true" | ||
stopOnFailure="false" | ||
backupGlobals="false" | ||
> | ||
<testsuites> | ||
<testsuite | ||
name="testsuite" | ||
> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<ini name="display_errors" value="On" /> | ||
<ini name="display_startup_errors" value="On" /> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
class Test extends \PHPUnit\Framework\TestCase | ||
{ | ||
protected $blacklist = ''; | ||
|
||
protected function setUp(): void | ||
{ | ||
$filename = __DIR__.'/../blacklist.txt'; | ||
if(file_exists($filename)) { | ||
$this->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), ['.', '..']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
loli*ta gi*rl fu*ck c*p pt*hc | ||
I do spy software your website. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |