-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for basic identification of bad words
- Loading branch information
Showing
8 changed files
with
196 additions
and
4 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ node_modules | |
bower_components | ||
js/dist | ||
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
Empty file.
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,105 @@ | ||
<?php | ||
|
||
namespace FoF\Filter\Tests\integration\api; | ||
|
||
use Flarum\Discussion\Discussion; | ||
use Flarum\Testing\integration\RetrievesAuthorizedUsers; | ||
use Flarum\Testing\integration\TestCase; | ||
use Illuminate\Support\Arr; | ||
|
||
class CreatePostTest extends TestCase | ||
{ | ||
use RetrievesAuthorizedUsers; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->extension('flarum-flags', 'flarum-approval', 'fof-filter'); | ||
|
||
$this->prepareDatabase([ | ||
'users' => [ | ||
$this->normalUser(), | ||
], | ||
'settings' => [ | ||
['key' => 'fof-filter.words', 'value' => 'wibble'.PHP_EOL.'wobble'.PHP_EOL], | ||
['key' => 'fof-filter.censors', 'value' => '["\/(w|w\\.|w\\-|\u03c9|\u03c8|\u03a8)(i|i\\.|i\\-|!|\\||\\]\\[|]|1|\u222b|\u00cc|\u00cd|\u00ce|\u00cf|\u00ec|\u00ed|\u00ee|\u00ef)(b|b\\.|b\\-|8|\\|3|\u00df|\u0392|\u03b2)(b|b\\.|b\\-|8|\\|3|\u00df|\u0392|\u03b2)(l|1\\.|l\\-|!|\\||\\]\\[|]|\u00a3|\u222b|\u00cc|\u00cd|\u00ce|\u00cf)(e|e\\.|e\\-|3|\u20ac|\u00c8|\u00e8|\u00c9|\u00e9|\u00ca|\u00ea|\u2211)\/i","\/(w|w\\.|w\\-|\u03c9|\u03c8|\u03a8)(o|o\\.|o\\-|0|\u039f|\u03bf|\u03a6|\u00a4|\u00b0|\u00f8)(b|b\\.|b\\-|8|\\|3|\u00df|\u0392|\u03b2)(b|b\\.|b\\-|8|\\|3|\u00df|\u0392|\u03b2)(l|1\\.|l\\-|!|\\||\\]\\[|]|\u00a3|\u222b|\u00cc|\u00cd|\u00ce|\u00cf)(e|e\\.|e\\-|3|\u20ac|\u00c8|\u00e8|\u00c9|\u00e9|\u00ca|\u00ea|\u2211)\/i"]'] | ||
] | ||
]); | ||
|
||
parent::setUp(); | ||
|
||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function create_discussion_without_any_bad_words() | ||
{ | ||
$response = $this->send( | ||
$this->request('POST', '/api/discussions', [ | ||
'authenticatedAs' => 2, | ||
'json' => [ | ||
'data' => [ | ||
'attributes' => [ | ||
'title' => 'test - too-obscure', | ||
'content' => 'predetermined content for automated testing - too-obscure', | ||
], | ||
] | ||
], | ||
]) | ||
); | ||
|
||
$this->assertEquals(201, $response->getStatusCode()); | ||
|
||
/** @var Discussion $discussion */ | ||
$discussion = Discussion::firstOrFail(); | ||
$data = json_decode($response->getBody()->getContents(), true); | ||
|
||
$this->assertEquals('test - too-obscure', $discussion->title); | ||
$this->assertEquals('test - too-obscure', Arr::get($data, 'data.attributes.title')); | ||
|
||
$post = $discussion->firstPost; | ||
|
||
$this->assertNotNull($post); | ||
$this->assertEquals('predetermined content for automated testing - too-obscure', $post->content); | ||
|
||
$this->assertTrue($post->is_approved); | ||
$this->assertTrue($discussion->is_approved); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function create_discussion_with_bad_words() | ||
{ | ||
$response = $this->send( | ||
$this->request('POST', '/api/discussions', [ | ||
'authenticatedAs' => 2, | ||
'json' => [ | ||
'data' => [ | ||
'attributes' => [ | ||
'title' => 'test - wibble', | ||
'content' => 'predetermined content for automated testing - wibble', | ||
], | ||
] | ||
], | ||
]) | ||
); | ||
|
||
$this->assertEquals(201, $response->getStatusCode()); | ||
|
||
/** @var Discussion $discussion */ | ||
$discussion = Discussion::firstOrFail(); | ||
$data = json_decode($response->getBody()->getContents(), true); | ||
|
||
$this->assertEquals('test - wibble', $discussion->title); | ||
$this->assertEquals('test - wibble', Arr::get($data, 'data.attributes.title')); | ||
|
||
$post = $discussion->firstPost; | ||
|
||
$this->assertNotNull($post); | ||
$this->assertEquals('predetermined content for automated testing - wibble', $post->content); | ||
|
||
$this->assertFalse($post->is_approved); | ||
$this->assertFalse($discussion->is_approved); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
use Flarum\Testing\integration\Setup\SetupScript; | ||
|
||
require __DIR__.'/../../vendor/autoload.php'; | ||
|
||
$setup = new SetupScript(); | ||
|
||
$setup->run(); |
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,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="true" | ||
stopOnFailure="false" | ||
> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">../src/</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Flarum Integration Tests"> | ||
<directory suffix="Test.php">./integration</directory> | ||
<exclude>./integration/tmp</exclude> | ||
</testsuite> | ||
</testsuites> | ||
</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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">../src/</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Flarum Unit Tests"> | ||
<directory suffix="Test.php">./unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
<listeners> | ||
<listener class="\Mockery\Adapter\Phpunit\TestListener" /> | ||
</listeners> | ||
</phpunit> |
Empty file.