From 7db93ee4b64fa6252223444a56aff45d3e29886e Mon Sep 17 00:00:00 2001 From: yurabakhtin Date: Tue, 9 Feb 2021 14:03:35 +0300 Subject: [PATCH] Add tests --- tests/codeception/_pages/TwofaAuthPage.php | 28 ++++++++++++++++++++++ tests/codeception/functional/TwofaCest.php | 15 +++++++++++- tests/codeception/unit/TwofaTest.php | 9 ++++--- views/check/index.php | 2 +- 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 tests/codeception/_pages/TwofaAuthPage.php diff --git a/tests/codeception/_pages/TwofaAuthPage.php b/tests/codeception/_pages/TwofaAuthPage.php new file mode 100644 index 0000000..7547caf --- /dev/null +++ b/tests/codeception/_pages/TwofaAuthPage.php @@ -0,0 +1,28 @@ +actor, 'waitForText')) { + $this->actor->waitForText('Two-factor authentication'); + } + $this->actor->fillField('CheckCode[code]', $code); + $this->actor->click('#verify-button'); + } + +} diff --git a/tests/codeception/functional/TwofaCest.php b/tests/codeception/functional/TwofaCest.php index 04db548..e371fc0 100644 --- a/tests/codeception/functional/TwofaCest.php +++ b/tests/codeception/functional/TwofaCest.php @@ -7,12 +7,25 @@ namespace twofa\functional; +use tests\codeception\_pages\LoginPage; +use tests\codeception\_pages\TwofaAuthPage; use twofa\FunctionalTester; class TwofaCest { - public function testSendVerifyingCode(FunctionalTester $I) + public function testCheckWrongVerifyingCode(FunctionalTester $I) { + $I->wantTo('check wrong verifying code'); + $loginPage = LoginPage::openBy($I); + $I->amGoingTo('try to login with admin credentials'); + $loginPage->login('Admin', 'test'); + $I->expectTo('See Two Factor Auth'); + $I->see('Two-factor authentication'); + + $twofaAuthPage = TwofaAuthPage::openBy($I); + $twofaAuthPage->verify('test code'); + $I->expectTo('see wrong verifying code'); + $I->see('Verifying code is not valid!'); } } diff --git a/tests/codeception/unit/TwofaTest.php b/tests/codeception/unit/TwofaTest.php index cdbd5c0..d197c76 100644 --- a/tests/codeception/unit/TwofaTest.php +++ b/tests/codeception/unit/TwofaTest.php @@ -36,9 +36,12 @@ public function testVerifyCode() $this->assertTrue(TwofaHelper::enableVerifying()); $this->assertTrue(TwofaHelper::isVerifyingRequired()); $this->assertFalse(TwofaHelper::isValidCode('test')); + } - //$this->becomeUser('User1'); - //$this->assertFalse(TwofaHelper::isVerifyingRequired()); - //$this->assertFalse(TwofaHelper::isValidCode('test')); + public function testDisableVerifying() + { + $this->becomeUser('Admin'); + $this->assertTrue(TwofaHelper::disableVerifying()); + $this->assertFalse(TwofaHelper::isVerifyingRequired()); } } \ No newline at end of file diff --git a/views/check/index.php b/views/check/index.php index 8a2cbaf..c4aaab1 100644 --- a/views/check/index.php +++ b/views/check/index.php @@ -41,7 +41,7 @@ link(Url::toRoute('/user/auth/logout'))->right()->pjax(false) ?> - 'btn btn-primary', 'data-ui-loader' => ""]); ?> + 'verify-button', 'class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?>