-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for Two_Factor_Provider::get_code(). (#522)
* Add unit tests for Two_Factor_Provider::get_code(). * Add a test that validates an array of characters results in the correct character output * Explicitly check the length of the generated codes, and add a test for a string input of valid characters. --------- Co-authored-by: Ian Dunn <[email protected]>
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Test Two Factor Provider | ||
* | ||
* @package Two_Factor | ||
*/ | ||
|
||
/** | ||
* Class Tests_Two_Factor_Provider | ||
* | ||
* @package Two_Factor | ||
* @group providers | ||
*/ | ||
class Tests_Two_Factor_Provider extends WP_UnitTestCase { | ||
/** | ||
* @covers Two_Factor_Provider::get_code | ||
*/ | ||
function test_get_code() { | ||
$code = Two_Factor_Provider::get_code( 3, '1' ); | ||
$this->assertEquals( '111', $code ); | ||
|
||
$code = Two_Factor_Provider::get_code( 8, '1' ); | ||
$this->assertEquals( '11111111', $code ); | ||
|
||
$code = Two_Factor_Provider::get_code( 8, 'A' ); | ||
$this->assertEquals( 'AAAAAAAA', $code ); | ||
|
||
$code = Two_Factor_Provider::get_code( 30, array( 'A', 'B', 'C' ) ); | ||
$this->assertSame( 1, preg_match( '/^[ABC]{30}$/', $code ) ); | ||
|
||
$code = Two_Factor_Provider::get_code( 30, 'DEF' ); | ||
$this->assertSame( 1, preg_match( '/^[DEF]{30}$/', $code ) ); | ||
|
||
$code = Two_Factor_Provider::get_code( 8 ); | ||
$this->assertEquals( 8, strlen( $code ) ); | ||
} | ||
} |