ImplodingTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. */
  21. /**
  22. * Test helper
  23. */
  24. require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  25. /**
  26. * Zend_Ldap_Dn
  27. */
  28. require_once 'Zend/Ldap/Dn.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Ldap
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Ldap_Dn_ImplodingTest extends PHPUnit_Framework_TestCase
  37. {
  38. public function testDnWithMultiValuedRdnRoundTrip()
  39. {
  40. $dn1='cn=Surname\, Firstname+uid=userid,cn=name2,dc=example,dc=org';
  41. $dnArray=Zend_Ldap_Dn::explodeDn($dn1);
  42. $dn2=Zend_Ldap_Dn::implodeDn($dnArray);
  43. $this->assertEquals($dn1, $dn2);
  44. }
  45. public function testImplodeDn()
  46. {
  47. $expected='cn=name1,cn=name2,dc=example,dc=org';
  48. $dnArray=array(
  49. array("cn" => "name1"),
  50. array("cn" => "name2"),
  51. array("dc" => "example"),
  52. array("dc" => "org")
  53. );
  54. $dn=Zend_Ldap_Dn::implodeDn($dnArray);
  55. $this->assertEquals($expected, $dn);
  56. $dn=Zend_Ldap_Dn::implodeDn($dnArray, Zend_Ldap_Dn::ATTR_CASEFOLD_UPPER, ';');
  57. $this->assertEquals('CN=name1;CN=name2;DC=example;DC=org', $dn);
  58. }
  59. public function testImplodeDnWithUtf8Characters()
  60. {
  61. $expected='uid=rogasawara,ou=営業部,o=Airius';
  62. $dnArray=array(
  63. array("uid" => "rogasawara"),
  64. array("ou" => "営業部"),
  65. array("o" => "Airius"),
  66. );
  67. $dn=Zend_Ldap_Dn::implodeDn($dnArray);
  68. $this->assertEquals($expected, $dn);
  69. }
  70. public function testImplodeRdn()
  71. {
  72. $a=array('cn' => 'value');
  73. $expected='cn=value';
  74. $this->assertEquals($expected, Zend_Ldap_Dn::implodeRdn($a));
  75. }
  76. public function testImplodeRdnMultiValuedRdn()
  77. {
  78. $a=array('cn' => 'value', 'uid' => 'testUser');
  79. $expected='cn=value+uid=testUser';
  80. $this->assertEquals($expected, Zend_Ldap_Dn::implodeRdn($a));
  81. }
  82. public function testImplodeRdnMultiValuedRdn2()
  83. {
  84. $a=array('cn' => 'value', 'uid' => 'testUser', 'ou' => 'myDep');
  85. $expected='cn=value+ou=myDep+uid=testUser';
  86. $this->assertEquals($expected, Zend_Ldap_Dn::implodeRdn($a));
  87. }
  88. public function testImplodeRdnCaseFold()
  89. {
  90. $a=array('cn' => 'value');
  91. $expected='CN=value';
  92. $this->assertEquals($expected,
  93. Zend_Ldap_Dn::implodeRdn($a, Zend_Ldap_Dn::ATTR_CASEFOLD_UPPER));
  94. $a=array('CN' => 'value');
  95. $expected='cn=value';
  96. $this->assertEquals($expected,
  97. Zend_Ldap_Dn::implodeRdn($a, Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER));
  98. }
  99. public function testImplodeRdnMultiValuedRdnCaseFold()
  100. {
  101. $a=array('cn' => 'value', 'uid' => 'testUser', 'ou' => 'myDep');
  102. $expected='CN=value+OU=myDep+UID=testUser';
  103. $this->assertEquals($expected,
  104. Zend_Ldap_Dn::implodeRdn($a, Zend_Ldap_Dn::ATTR_CASEFOLD_UPPER));
  105. $a=array('CN' => 'value', 'uID' => 'testUser', 'ou' => 'myDep');
  106. $expected='cn=value+ou=myDep+uid=testUser';
  107. $this->assertEquals($expected,
  108. Zend_Ldap_Dn::implodeRdn($a, Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER));
  109. }
  110. /**
  111. * @expectedException Zend_Ldap_Exception
  112. */
  113. public function testImplodeRdnInvalidOne()
  114. {
  115. $a=array('cn');
  116. Zend_Ldap_Dn::implodeRdn($a);
  117. }
  118. /**
  119. * @expectedException Zend_Ldap_Exception
  120. */
  121. public function testImplodeRdnInvalidThree()
  122. {
  123. $a=array('cn' => 'value', 'ou');
  124. Zend_Ldap_Dn::implodeRdn($a);
  125. }
  126. }