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 83a8eeb..e030991 100644 --- a/views/check/index.php +++ b/views/check/index.php @@ -39,7 +39,7 @@
- 'btn btn-primary', 'data-ui-loader' => ""]); ?> + 'verify-button', 'class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?> 'pull-right', 'data-pjax' => false]) ?>