Skip to content

Commit

Permalink
further testing
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Jun 12, 2024
1 parent cd5b91d commit 1d47a33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Listener/CheckPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function getCensors(): array
// Ensure $censors is a non-empty array
if (!is_array($censors) || empty($censors)) {
// Censors have not been initialized correctly, generate them
$censors = CensorGenerator::generateCensors($this->settings->get('fof-filter.words'));
$censors = CensorGenerator::generateCensors($this->settings->get('fof-filter.words', ''));
$this->cache->forever('fof-filter.censors', json_encode($censors));
}

Expand Down
21 changes: 15 additions & 6 deletions tests/integration/api/CreatePostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,28 @@ public function create_discussion_without_any_bad_words()
$this->assertTrue($discussion->is_approved);
}

public function badWords()
{
return [
['wibble'],
['wobble'],
];
}

/**
* @test
* @dataProvider badWords
*/
public function create_discussion_with_bad_words_requires_approval()
public function create_discussion_with_bad_words_requires_approval(string $badWord)
{
$response = $this->send(
$this->request('POST', '/api/discussions', [
'authenticatedAs' => 2,
'json' => [
'data' => [
'attributes' => [
'title' => 'test - wibble',
'content' => 'predetermined content for automated testing - wibble',
'title' => "test - $badWord",
'content' => "predetermined content for automated testing - $badWord",
],
],
],
Expand All @@ -97,13 +106,13 @@ public function create_discussion_with_bad_words_requires_approval()
$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'));
$this->assertEquals("test - $badWord", $discussion->title);
$this->assertEquals("test - $badWord", Arr::get($data, 'data.attributes.title'));

$post = $discussion->firstPost;

$this->assertNotNull($post);
$this->assertEquals('predetermined content for automated testing - wibble', $post->content);
$this->assertEquals("predetermined content for automated testing - $badWord", $post->content);

$this->assertFalse($post->is_approved);
$this->assertFalse($discussion->is_approved);
Expand Down

0 comments on commit 1d47a33

Please sign in to comment.