/tests/ZendTest/Ldap/OfflineTest.php

https://github.com/zucchi/zf2 · PHP · 131 lines · 93 code · 9 blank · 29 comment · 1 complexity · 463358d9f8ec4da44ea759688b6541f3 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. * @package Zend_Ldap
  9. */
  10. namespace ZendTest\Ldap;
  11. use Zend\Config;
  12. use Zend\Ldap;
  13. use Zend\Ldap\Exception;
  14. /**
  15. * @category Zend
  16. * @package Zend_Ldap
  17. * @subpackage UnitTests
  18. * @group Zend_Ldap
  19. */
  20. class OfflineTest extends \PHPUnit_Framework_TestCase
  21. {
  22. /**
  23. * Zend\Ldap\Ldap instance
  24. *
  25. * @var Ldap\Ldap
  26. */
  27. protected $ldap = null;
  28. /**
  29. * Setup operations run prior to each test method:
  30. *
  31. * * Creates an instance of Zend\Ldap\Ldap
  32. *
  33. * @return void
  34. */
  35. public function setUp()
  36. {
  37. if (!extension_loaded('ldap')) {
  38. $this->markTestSkipped('LDAP is not enabled');
  39. }
  40. $this->ldap = new Ldap\Ldap();
  41. }
  42. /**
  43. * @return void
  44. */
  45. public function testInvalidOptionResultsInException()
  46. {
  47. $optionName = 'invalid';
  48. try {
  49. $this->ldap->setOptions(array($optionName => 'irrelevant'));
  50. $this->fail('Expected Zend\Ldap\Exception\LdapException not thrown');
  51. } catch (Exception\LdapException $e) {
  52. $this->assertEquals("Unknown Zend\Ldap\Ldap option: $optionName", $e->getMessage());
  53. }
  54. }
  55. public function testException()
  56. {
  57. $e = new Exception\LdapException(null, '', 0);
  58. $this->assertEquals('no exception message', $e->getMessage());
  59. $this->assertEquals(0, $e->getCode());
  60. $e = new Exception\LdapException(null, '', 15);
  61. $this->assertEquals('0xf: no exception message', $e->getMessage());
  62. $this->assertEquals(15, $e->getCode());
  63. }
  64. public function testOptionsGetter()
  65. {
  66. $options = array(
  67. 'host' => TESTS_ZEND_LDAP_HOST,
  68. 'username' => TESTS_ZEND_LDAP_USERNAME,
  69. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  70. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  71. );
  72. $ldap = new Ldap\Ldap($options);
  73. $this->assertEquals(array(
  74. 'host' => TESTS_ZEND_LDAP_HOST,
  75. 'port' => 0,
  76. 'useSsl' => false,
  77. 'username' => TESTS_ZEND_LDAP_USERNAME,
  78. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  79. 'bindRequiresDn' => false,
  80. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  81. 'accountCanonicalForm' => null,
  82. 'accountDomainName' => null,
  83. 'accountDomainNameShort' => null,
  84. 'accountFilterFormat' => null,
  85. 'allowEmptyPassword' => false,
  86. 'useStartTls' => false,
  87. 'optReferrals' => false,
  88. 'tryUsernameSplit' => true,
  89. 'networkTimeout' => null,
  90. ), $ldap->getOptions()
  91. );
  92. }
  93. public function testConfigObject()
  94. {
  95. $config = new Config\Config(array(
  96. 'host' => TESTS_ZEND_LDAP_HOST,
  97. 'username' => TESTS_ZEND_LDAP_USERNAME,
  98. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  99. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  100. ));
  101. $ldap = new Ldap\Ldap($config);
  102. $this->assertEquals(array(
  103. 'host' => TESTS_ZEND_LDAP_HOST,
  104. 'port' => 0,
  105. 'useSsl' => false,
  106. 'username' => TESTS_ZEND_LDAP_USERNAME,
  107. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  108. 'bindRequiresDn' => false,
  109. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  110. 'accountCanonicalForm' => null,
  111. 'accountDomainName' => null,
  112. 'accountDomainNameShort' => null,
  113. 'accountFilterFormat' => null,
  114. 'allowEmptyPassword' => false,
  115. 'useStartTls' => false,
  116. 'optReferrals' => false,
  117. 'tryUsernameSplit' => true,
  118. 'networkTimeout' => null,
  119. ), $ldap->getOptions()
  120. );
  121. }
  122. }