-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from michalsn/validation_rules
Support for assigning validation data to strong_password method
- Loading branch information
Showing
2 changed files
with
185 additions
and
10 deletions.
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,130 @@ | ||
<?php | ||
|
||
use CodeIgniter\Test\CIUnitTestCase; | ||
use CodeIgniter\Validation\Validation; | ||
use Config\Services; | ||
use Myth\Auth\Authentication\Passwords\ValidationRules; | ||
|
||
|
||
class ValidationRulesTest extends CIUnitTestCase | ||
{ | ||
protected $validation; | ||
protected $config = [ | ||
'ruleSets' => [ | ||
ValidationRules::class, | ||
], | ||
]; | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Services::reset(true); | ||
|
||
$this->validation = new Validation((object) $this->config, \Config\Services::renderer()); | ||
$this->validation->reset(); | ||
|
||
$_REQUEST = []; | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
public function testStrongPasswordLongRule() | ||
{ | ||
$rules = [ | ||
'password' => 'strong_password[]', | ||
]; | ||
|
||
$data = [ | ||
'email' => 'john@smith.com', | ||
'password' => '!!!gerard!!!abootylicious', | ||
]; | ||
|
||
$this->validation->setRules($rules); | ||
|
||
$this->assertTrue($this->validation->run($data)); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
public function testStrongPasswordLongRuleWithPostRequest() | ||
{ | ||
$_REQUEST = $data = [ | ||
'email' => 'john@smith.com', | ||
'password' => '!!!gerard!!!abootylicious', | ||
]; | ||
|
||
$request = service('request'); | ||
$request->setMethod('post')->setGlobal('post', $data); | ||
|
||
$this->validation->setRules([ | ||
'password' => 'strong_password[]', | ||
]); | ||
|
||
$result = $this->validation->withRequest($request)->run(); | ||
$this->assertTrue($result); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
public function testStrongPasswordLongRuleWithRawInputRequest() | ||
{ | ||
$data = [ | ||
'email' => 'john@smith.com', | ||
'password' => '!!!gerard!!!abootylicious', | ||
]; | ||
|
||
$request = service('request'); | ||
$request->setMethod('patch')->setBody(http_build_query($data)); | ||
|
||
$this->validation->setRules([ | ||
'password' => 'strong_password[]', | ||
]); | ||
|
||
$result = $this->validation->withRequest($request)->run(); | ||
$this->assertTrue($result); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
public function testStrongPasswordShortRuleWithPostRequest() | ||
{ | ||
$_REQUEST = $data = [ | ||
'email' => 'john@smith.com', | ||
'password' => '!!!gerard!!!abootylicious', | ||
]; | ||
|
||
$request = service('request'); | ||
$request->setMethod('post')->setGlobal('post', $data); | ||
|
||
$this->validation->setRules([ | ||
'password' => 'strong_password', | ||
]); | ||
|
||
$result = $this->validation->withRequest($request)->run(); | ||
$this->assertTrue($result); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
public function testStrongPasswordShortRuleWithRawInputRequest() | ||
{ | ||
$data = [ | ||
'email' => 'john@smith.com', | ||
'password' => '!!!gerard!!!abootylicious', | ||
]; | ||
|
||
$request = service('request'); | ||
$request->setMethod('patch')->setBody(http_build_query($data)); | ||
|
||
$this->validation->setRules([ | ||
'password' => 'strong_password', | ||
]); | ||
|
||
$result = $this->validation->withRequest($request)->run(); | ||
$this->assertTrue($result); | ||
} | ||
|
||
} |