OriginalOfflineTest.php 3.2 KB

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