You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.4 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-27
  8. *
  9. * Unit tests for CaptchaValidator class
  10. */
  11. require_once dirname(__FILE__) . '/../../session/Session.php';
  12. require_once dirname(__FILE__) . '/../../validator/iValidator.php';
  13. require_once dirname(__FILE__) . '/../../validator/Validator.php';
  14. require_once dirname(__FILE__) . '/../../captcha/CaptchaValidator.php';
  15. require_once dirname(__FILE__) . '/../../captcha/Captcha.php';
  16. class CaptchaValidatorTest extends PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * @TODO: CaptchaValidator->isValid() - $value param not used
  20. */
  21. public function testIsValid()
  22. {
  23. $captcha = new Captcha();
  24. $token = $captcha->getToken();
  25. $code = Session::get('_ccode');
  26. $validator = new CaptchaValidator();
  27. $this->assertTrue($validator->isValid(null, array('ctoken' => $token, 'ccode' => $code)));
  28. $this->assertFalse($validator->isValid(null, array('ctoken' => $token . 'asd', 'ccode' => $code)));
  29. $this->assertEquals('Entered code wrong', $validator->getMessage());
  30. }
  31. public function testIsValidInvalid()
  32. {
  33. $validator = new CaptchaValidator();
  34. $this->assertFalse($validator->isValid(null, array()));
  35. $this->assertEquals('Entered code wrong', $validator->getMessage());
  36. }
  37. }