2
0

ImplodingTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_Dn
  24. */
  25. require_once 'Zend/Ldap/Dn.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. * @group Zend_Ldap_Dn
  34. */
  35. class Zend_Ldap_Dn_ImplodingTest extends PHPUnit_Framework_TestCase
  36. {
  37. public function testDnWithMultiValuedRdnRoundTrip()
  38. {
  39. $dn1='cn=Surname\, Firstname+uid=userid,cn=name2,dc=example,dc=org';
  40. $dnArray=Zend_Ldap_Dn::explodeDn($dn1);
  41. $dn2=Zend_Ldap_Dn::implodeDn($dnArray);
  42. $this->assertEquals($dn1, $dn2);
  43. }
  44. public function testImplodeDn()
  45. {
  46. $expected='cn=name1,cn=name2,dc=example,dc=org';
  47. $dnArray=array(
  48. array("cn" => "name1"),
  49. array("cn" => "name2"),
  50. array("dc" => "example"),
  51. array("dc" => "org")
  52. );
  53. $dn=Zend_Ldap_Dn::implodeDn($dnArray);
  54. $this->assertEquals($expected, $dn);
  55. $dn=Zend_Ldap_Dn::implodeDn($dnArray, Zend_Ldap_Dn::ATTR_CASEFOLD_UPPER, ';');
  56. $this->assertEquals('CN=name1;CN=name2;DC=example;DC=org', $dn);
  57. }
  58. public function testImplodeDnWithUtf8Characters()
  59. {
  60. $expected='uid=rogasawara,ou=営業部,o=Airius';
  61. $dnArray=array(
  62. array("uid" => "rogasawara"),
  63. array("ou" => "営業部"),
  64. array("o" => "Airius"),
  65. );
  66. $dn=Zend_Ldap_Dn::implodeDn($dnArray);
  67. $this->assertEquals($expected, $dn);
  68. }
  69. public function testImplodeRdn()
  70. {
  71. $a=array('cn' => 'value');
  72. $expected='cn=value';
  73. $this->assertEquals($expected, Zend_Ldap_Dn::implodeRdn($a));
  74. }
  75. public function testImplodeRdnMultiValuedRdn()
  76. {
  77. $a=array('cn' => 'value', 'uid' => 'testUser');
  78. $expected='cn=value+uid=testUser';
  79. $this->assertEquals($expected, Zend_Ldap_Dn::implodeRdn($a));
  80. }
  81. public function testImplodeRdnMultiValuedRdn2()
  82. {
  83. $a=array('cn' => 'value', 'uid' => 'testUser', 'ou' => 'myDep');
  84. $expected='cn=value+ou=myDep+uid=testUser';
  85. $this->assertEquals($expected, Zend_Ldap_Dn::implodeRdn($a));
  86. }
  87. public function testImplodeRdnCaseFold()
  88. {
  89. $a=array('cn' => 'value');
  90. $expected='CN=value';
  91. $this->assertEquals($expected,
  92. Zend_Ldap_Dn::implodeRdn($a, Zend_Ldap_Dn::ATTR_CASEFOLD_UPPER));
  93. $a=array('CN' => 'value');
  94. $expected='cn=value';
  95. $this->assertEquals($expected,
  96. Zend_Ldap_Dn::implodeRdn($a, Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER));
  97. }
  98. public function testImplodeRdnMultiValuedRdnCaseFold()
  99. {
  100. $a=array('cn' => 'value', 'uid' => 'testUser', 'ou' => 'myDep');
  101. $expected='CN=value+OU=myDep+UID=testUser';
  102. $this->assertEquals($expected,
  103. Zend_Ldap_Dn::implodeRdn($a, Zend_Ldap_Dn::ATTR_CASEFOLD_UPPER));
  104. $a=array('CN' => 'value', 'uID' => 'testUser', 'ou' => 'myDep');
  105. $expected='cn=value+ou=myDep+uid=testUser';
  106. $this->assertEquals($expected,
  107. Zend_Ldap_Dn::implodeRdn($a, Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER));
  108. }
  109. /**
  110. * @expectedException Zend_Ldap_Exception
  111. */
  112. public function testImplodeRdnInvalidOne()
  113. {
  114. $a=array('cn');
  115. Zend_Ldap_Dn::implodeRdn($a);
  116. }
  117. /**
  118. * @expectedException Zend_Ldap_Exception
  119. */
  120. public function testImplodeRdnInvalidThree()
  121. {
  122. $a=array('cn' => 'value', 'ou');
  123. Zend_Ldap_Dn::implodeRdn($a);
  124. }
  125. }