diff --git a/server/run-tests.sh b/server/run-tests.sh index 487b82e1..251e7164 100755 --- a/server/run-tests.sh +++ b/server/run-tests.sh @@ -1,2 +1,3 @@ phpunit --colors tests/models -phpunit --colors tests/controllers \ No newline at end of file +phpunit --colors tests/controllers +phpunit --colors tests/libs \ No newline at end of file diff --git a/server/tests/__mocks__/BeanMock.php b/server/tests/__mocks__/BeanMock.php index 56d7568a..e47421e1 100644 --- a/server/tests/__mocks__/BeanMock.php +++ b/server/tests/__mocks__/BeanMock.php @@ -1,6 +1,7 @@ returns(new \Mock([ + 'isSuccess' => \Mock::stub()->returns($value) + ])); + } + + public function __construct($privateKey) { + parent::__construct(); + + $this->privateKey = $privateKey; + $this->verify = ReCaptcha::$verify; + } + } +} \ No newline at end of file diff --git a/server/tests/__mocks__/RespectMock.php b/server/tests/__mocks__/RespectMock.php new file mode 100644 index 00000000..79d4d0eb --- /dev/null +++ b/server/tests/__mocks__/RespectMock.php @@ -0,0 +1,5 @@ +name = 'MOCK_SETTING_NAME'; $mockUserInstance->value = 'MOCK_SETTING_VALUE'; + $mockUserInstance->getValue = \Mock::stub()->returns('MOCK_SETTING_VALUE'); return $mockUserInstance; } diff --git a/server/tests/lib/.gitkeep b/server/tests/lib/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/server/tests/libs/validations/captchaTest.php b/server/tests/libs/validations/captchaTest.php new file mode 100644 index 00000000..618d0bc3 --- /dev/null +++ b/server/tests/libs/validations/captchaTest.php @@ -0,0 +1,35 @@ +validate('MOCK_RESPONSE'); + $this->assertTrue($response); + + \ReCaptcha\ReCaptcha::initVerify(false); + $response = $captchaValidation->validate('MOCK_RESPONSE'); + $this->assertFalse($response); + } + + public function testShouldPassCorrectValuesToCaptcha() { + $captchaValidation = new \CustomValidations\Captcha(); + $captchaValidation->validate('MOCK_RESPONSE'); + + $this->assertTrue(Setting::get('getSetting')->hasBeenCalledWithArgs('recaptcha-private')); + $this->assertTrue(\ReCaptcha\ReCaptcha::$verify->hasBeenCalledWithArgs('MOCK_RESPONSE', 'MOCK_REMOTE')); + } +} \ No newline at end of file