PasswordValidationCallableTest.php 756 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. class PasswordValidationCallableTEst extends \PHPUnit\Framework\TestCase {
  3. public function setUp(): void {
  4. $c = Config::getInstance();
  5. $all = $c->getAll();
  6. $all['password_validation'] = [
  7. function ($pw) {
  8. if ($pw === 'fail') {
  9. return 'test_fail';
  10. }
  11. }
  12. ];
  13. unset($all['min_password_length']);
  14. $c->setAll($all);
  15. parent::setUp();
  16. }
  17. public function testBasic() {
  18. // anything except 'fail' should work.
  19. $this->assertEmpty(validate_password('str'));
  20. $this->assertEquals([], validate_password('1234asdf'));
  21. $this->assertEquals(['test_fail'], validate_password('fail'));
  22. }
  23. }