HelperTest.php 2.9 KB

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