OfflineTest.php 3.0 KB

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