Skip to content

Commit

Permalink
Merge pull request #12 from humhub/enh/4-add-tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
luke- authored Feb 9, 2021
2 parents acdcaa2 + 7db93ee commit e7fabfd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
28 changes: 28 additions & 0 deletions tests/codeception/_pages/TwofaAuthPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace tests\codeception\_pages;

use tests\codeception\_support\BasePage;

/**
* Represents 2FA verifying code page
* @property \AcceptanceTester|\FunctionalTester $actor
*/
class TwofaAuthPage extends BasePage
{

public $route = 'twofa/check';

/**
* @param string $code
*/
public function verify($code)
{
if(method_exists($this->actor, 'waitForText')) {
$this->actor->waitForText('Two-factor authentication');
}
$this->actor->fillField('CheckCode[code]', $code);
$this->actor->click('#verify-button');
}

}
15 changes: 14 additions & 1 deletion tests/codeception/functional/TwofaCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
}
9 changes: 6 additions & 3 deletions tests/codeception/unit/TwofaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion views/check/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<?= Button::danger(Yii::t('TwofaModule.base', 'Log out'))->link(Url::toRoute('/user/auth/logout'))->right()->pjax(false) ?>

<?= Html::submitButton(Yii::t('TwofaModule.base', 'Verify'), ['class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?>
<?= Html::submitButton(Yii::t('TwofaModule.base', 'Verify'), ['id' => 'verify-button', 'class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?>

<?php ActiveForm::end(); ?>

Expand Down

0 comments on commit e7fabfd

Please sign in to comment.