Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Croker committed Apr 2, 2021
1 parent 4493a18 commit 475c8b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 0 additions & 6 deletions tests/_craft/config/project/project.yaml

This file was deleted.

15 changes: 13 additions & 2 deletions tests/unit/services/SnaptchaServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Codeception\Test\Unit;
use Craft;
use craft\elements\User;
use putyourlightson\snaptcha\Snaptcha;
use UnitTester;

Expand All @@ -23,14 +24,24 @@ class SnaptchaServiceTest extends Unit
*/
protected $tester;

public function testIsUserAllowed()
{
Craft::$app->getUser()->identity = new User();

$this->assertFalse(Snaptcha::$plugin->snaptcha->isUserAllowed());

Snaptcha::$plugin->settings->validateUsers = false;
$this->assertTrue(Snaptcha::$plugin->snaptcha->isUserAllowed());
}

public function testIsIpAllowed()
{
$ipAddress = Craft::$app->getRequest()->getUserIP();

Snaptcha::$plugin->settings->allowList = [$ipAddress];
$this->assertTrue(Snaptcha::$plugin->snaptcha->isIpAllowed());

Snaptcha::$plugin->settings->allowList = [[ $ipAddress]];
Snaptcha::$plugin->settings->allowList = [[$ipAddress]];
$this->assertTrue(Snaptcha::$plugin->snaptcha->isIpAllowed());
}

Expand All @@ -41,7 +52,7 @@ public function testIsIpDenied()
Snaptcha::$plugin->settings->denyList = [$ipAddress];
$this->assertTrue(Snaptcha::$plugin->snaptcha->isIpDenied());

Snaptcha::$plugin->settings->denyList = [[ $ipAddress]];
Snaptcha::$plugin->settings->denyList = [[$ipAddress]];
$this->assertTrue(Snaptcha::$plugin->snaptcha->isIpDenied());
}
}
2 changes: 1 addition & 1 deletion tests/unit/variables/SnaptchaVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testGetField()
$field = $this->variable->getField();

$this->assertStringContainsString(
'name="'.$this->variable->getFieldName().'" value="" autocomplete="off"',
'name="'.$this->variable->getFieldName().'" value="" data-key=',
$field
);
}
Expand Down

0 comments on commit 475c8b8

Please sign in to comment.