2
0

MailHideTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_ReCaptcha
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** @see Zend_Service_ReCaptcha_MailHide */
  23. require_once 'Zend/Service/ReCaptcha/MailHide.php';
  24. /** @see Zend_Config */
  25. require_once 'Zend/Config.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Service_ReCaptcha
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Service
  33. * @group Zend_Service_ReCaptcha
  34. */
  35. class Zend_Service_ReCaptcha_MailHideTest extends PHPUnit_Framework_TestCase
  36. {
  37. protected $_publicKey = TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY;
  38. protected $_privateKey = TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY;
  39. protected $_mailHide = null;
  40. public function setUp() {
  41. $this->_mailHide = new Zend_Service_ReCaptcha_MailHide();
  42. }
  43. public function testSetGetPrivateKey() {
  44. $this->_mailHide->setPrivateKey($this->_privateKey);
  45. $this->assertSame($this->_privateKey, $this->_mailHide->getPrivateKey());
  46. }
  47. public function testSetGetEmail() {
  48. $mail = 'mail@example.com';
  49. $this->_mailHide->setEmail($mail);
  50. $this->assertSame($mail, $this->_mailHide->getEmail());
  51. $this->assertSame('example.com', $this->_mailHide->getEmailDomainPart());
  52. }
  53. public function testEmailLocalPart() {
  54. $this->_mailHide->setEmail('abcd@example.com');
  55. $this->assertSame('a', $this->_mailHide->getEmailLocalPart());
  56. $this->_mailHide->setEmail('abcdef@example.com');
  57. $this->assertSame('abc', $this->_mailHide->getEmailLocalPart());
  58. $this->_mailHide->setEmail('abcdefg@example.com');
  59. $this->assertSame('abcd', $this->_mailHide->getEmailLocalPart());
  60. }
  61. public function testConstructor() {
  62. $mail = 'mail@example.com';
  63. $options = array(
  64. 'theme' => 'black',
  65. 'lang' => 'no',
  66. );
  67. $config = new Zend_Config($options);
  68. $mailHide = new Zend_Service_ReCaptcha_MailHide($this->_publicKey, $this->_privateKey, $mail, $config);
  69. $_options = $mailHide->getOptions();
  70. $this->assertSame($this->_publicKey, $mailHide->getPublicKey());
  71. $this->assertSame($this->_privateKey, $mailHide->getPrivateKey());
  72. $this->assertSame($mail, $mailHide->getEmail());
  73. $this->assertSame($options['theme'], $_options['theme']);
  74. $this->assertSame($options['lang'], $_options['lang']);
  75. }
  76. public function testGetHtml() {
  77. $mail = 'mail@example.com';
  78. $this->_mailHide->setEmail($mail);
  79. $this->_mailHide->setPublicKey($this->_publicKey);
  80. $this->_mailHide->setPrivateKey($this->_privateKey);
  81. $html = $this->_mailHide->getHtml();
  82. $this->assertRegExp('#^m<a href=".*?">\.\.\.</a>@example\.com$#', $html);
  83. }
  84. public function testGetHtmlWithNoEmail() {
  85. $this->setExpectedException('Zend_Service_ReCaptcha_MailHide_Exception');
  86. $html = $this->_mailHide->getHtml();
  87. }
  88. public function testGetHtmlWithMissingPublicKey() {
  89. $this->setExpectedException('Zend_Service_ReCaptcha_MailHide_Exception');
  90. $mail = 'mail@example.com';
  91. $this->_mailHide->setEmail($mail);
  92. $this->_mailHide->setPrivateKey($this->_privateKey);
  93. $html = $this->_mailHide->getHtml();
  94. }
  95. public function testGetHtmlWithMissingPrivateKey() {
  96. $this->setExpectedException('Zend_Service_ReCaptcha_MailHide_Exception');
  97. $mail = 'mail@example.com';
  98. $this->_mailHide->setEmail($mail);
  99. $this->_mailHide->setPublicKey($this->_publicKey);
  100. $html = $this->_mailHide->getHtml();
  101. }
  102. public function testGetHtmlWithParamter() {
  103. $mail = 'mail@example.com';
  104. $this->_mailHide->setPublicKey($this->_publicKey);
  105. $this->_mailHide->setPrivateKey($this->_privateKey);
  106. $html = $this->_mailHide->getHtml($mail);
  107. $this->assertRegExp('#m<a href=".*?">\.\.\.</a>@example\.com$#', $html);
  108. }
  109. }