HelperTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. *
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\User_LDAP\Tests;
  25. use OCA\User_LDAP\Helper;
  26. use OCP\IConfig;
  27. class HelperTest extends \Test\TestCase {
  28. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  29. private $config;
  30. /** @var Helper */
  31. private $helper;
  32. public function setUp() {
  33. parent::setUp();
  34. $this->config = $this->createMock(IConfig::class);
  35. $this->helper = new Helper($this->config);
  36. }
  37. public function testGetServerConfigurationPrefixes() {
  38. $this->config->method('getAppKeys')
  39. ->with($this->equalTo('user_ldap'))
  40. ->willReturn([
  41. 'foo',
  42. 'ldap_configuration_active',
  43. 's1ldap_configuration_active',
  44. ]);
  45. $result = $this->helper->getServerConfigurationPrefixes(false);
  46. $this->assertEquals(['', 's1'], $result);
  47. }
  48. public function testGetServerConfigurationPrefixesActive() {
  49. $this->config->method('getAppKeys')
  50. ->with($this->equalTo('user_ldap'))
  51. ->willReturn([
  52. 'foo',
  53. 'ldap_configuration_active',
  54. 's1ldap_configuration_active',
  55. ]);
  56. $this->config->method('getAppValue')
  57. ->will($this->returnCallback(function($app, $key, $default) {
  58. if ($app !== 'user_ldap') {
  59. $this->fail('wrong app');
  60. }
  61. if ($key === 's1ldap_configuration_active') {
  62. return '1';
  63. }
  64. return $default;
  65. }));
  66. $result = $this->helper->getServerConfigurationPrefixes(true);
  67. $this->assertEquals(['s1'], $result);
  68. }
  69. public function testGetServerConfigurationHost() {
  70. $this->config->method('getAppKeys')
  71. ->with($this->equalTo('user_ldap'))
  72. ->willReturn([
  73. 'foo',
  74. 'ldap_host',
  75. 's1ldap_host',
  76. 's02ldap_host',
  77. ]);
  78. $this->config->method('getAppValue')
  79. ->will($this->returnCallback(function($app, $key, $default) {
  80. if ($app !== 'user_ldap') {
  81. $this->fail('wrong app');
  82. }
  83. if ($key === 'ldap_host') {
  84. return 'example.com';
  85. }
  86. if ($key === 's1ldap_host') {
  87. return 'foo.bar.com';
  88. }
  89. return $default;
  90. }));
  91. $result = $this->helper->getServerConfigurationHosts();
  92. $this->assertEquals([
  93. '' => 'example.com',
  94. 's1' => 'foo.bar.com',
  95. 's02' => '',
  96. ], $result);
  97. }
  98. }