OriginalOfflineTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_Ldap
  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. /**
  23. * Zend_Ldap
  24. */
  25. require_once 'Zend/Ldap.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Ldap
  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_Ldap
  33. */
  34. class Zend_Ldap_OriginalOfflineTest extends PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * Zend_Ldap instance
  38. *
  39. * @var Zend_Ldap
  40. */
  41. protected $_ldap = null;
  42. /**
  43. * Setup operations run prior to each test method:
  44. *
  45. * * Creates an instance of Zend_Ldap
  46. *
  47. * @return void
  48. */
  49. public function setUp()
  50. {
  51. $this->_ldap = new Zend_Ldap();
  52. }
  53. /**
  54. * @return void
  55. */
  56. public function testFilterEscapeBasicOperation()
  57. {
  58. $input = 'a*b(b)d\e/f';
  59. $expected = 'a\2ab\28b\29d\5ce\2ff';
  60. $this->assertEquals($expected, Zend_Ldap::filterEscape($input));
  61. }
  62. /**
  63. * @return void
  64. */
  65. public function testInvalidOptionResultsInException()
  66. {
  67. $optionName = 'invalid';
  68. try {
  69. $this->_ldap->setOptions(array($optionName => 'irrelevant'));
  70. $this->fail('Expected Zend_Ldap_Exception not thrown');
  71. } catch (Zend_Ldap_Exception $e) {
  72. $this->assertEquals("Unknown Zend_Ldap option: $optionName", $e->getMessage());
  73. }
  74. }
  75. /**
  76. * @return void
  77. */
  78. public function testExplodeDnOperation()
  79. {
  80. $inputs = array(
  81. 'CN=Alice Baker,CN=Users,DC=example,DC=com' => true,
  82. 'CN=Baker\\, Alice,CN=Users,DC=example,DC=com' => true,
  83. 'OU=Sales,DC=local' => true,
  84. 'OU=Sales;DC=local' => true,
  85. 'OU=Sales ,DC=local' => true,
  86. 'OU=Sales, dC=local' => true,
  87. 'ou=Sales , DC=local' => true,
  88. 'OU=Sales ; dc=local' => true,
  89. 'DC=local' => true,
  90. ' DC=local' => true,
  91. 'DC= local ' => true,
  92. 'username' => false,
  93. 'username@example.com' => false,
  94. 'EXAMPLE\\username' => false,
  95. 'CN=,Alice Baker,CN=Users,DC=example,DC=com' => false,
  96. 'CN=Users,DC==example,DC=com' => false,
  97. 'O=ACME' => true,
  98. '' => false,
  99. ' ' => false,
  100. );
  101. foreach ($inputs as $dn => $expected) {
  102. $ret = Zend_Ldap::explodeDn($dn);
  103. $this->assertTrue($ret === $expected);
  104. }
  105. }
  106. }