SettingsTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace OCA\ShareByMail\Tests;
  22. use OCA\ShareByMail\Settings;
  23. use OCA\ShareByMail\Settings\SettingsManager;
  24. use Test\TestCase;
  25. class SettingsTest extends TestCase {
  26. /** @var Settings */
  27. private $instance;
  28. /** @var SettingsManager | \PHPUnit_Framework_MockObject_MockObject */
  29. private $settingsManager;
  30. public function setUp() {
  31. parent::setUp();
  32. $this->settingsManager = $this->getMockBuilder(SettingsManager::class)
  33. ->disableOriginalConstructor()->getMock();
  34. $this->instance = new Settings($this->settingsManager);
  35. }
  36. public function testAnnounceShareProvider() {
  37. $before = [
  38. 'oc_appconfig' =>
  39. json_encode([
  40. 'key1' => 'value1',
  41. 'key2' => 'value2'
  42. ]),
  43. 'oc_foo' => 'oc_bar'
  44. ];
  45. $after = [
  46. 'oc_appconfig' =>
  47. json_encode([
  48. 'key1' => 'value1',
  49. 'key2' => 'value2',
  50. 'shareByMailEnabled' => true
  51. ]),
  52. 'oc_foo' => 'oc_bar'
  53. ];
  54. $this->instance->announceShareProvider(['array' => &$before]);
  55. $this->assertSame($after, $before);
  56. }
  57. public function testAnnounceShareByMailSettings() {
  58. $this->settingsManager->expects($this->once())->method('enforcePasswordProtection')->willReturn(true);
  59. $before = [
  60. 'oc_appconfig' =>
  61. json_encode([
  62. 'key1' => 'value1',
  63. 'key2' => 'value2'
  64. ]),
  65. 'oc_foo' => 'oc_bar'
  66. ];
  67. $after = [
  68. 'oc_appconfig' =>
  69. json_encode([
  70. 'key1' => 'value1',
  71. 'key2' => 'value2',
  72. 'shareByMail' => ['enforcePasswordProtection' => true]
  73. ]),
  74. 'oc_foo' => 'oc_bar'
  75. ];
  76. $this->instance->announceShareByMailSettings(['array' => &$before]);
  77. $this->assertSame($after, $before);
  78. }
  79. }