SecuritySettingsControllerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @author Lukas Reschke
  4. * @copyright 2014 Lukas Reschke lukas@owncloud.com
  5. *
  6. * This file is licensed under the Affero General Public License version 3 or
  7. * later.
  8. * See the COPYING-README file.
  9. */
  10. namespace Tests\Settings\Controller;
  11. use \OC\Settings\Application;
  12. use OC\Settings\Controller\SecuritySettingsController;
  13. use OCP\IConfig;
  14. use OCP\IRequest;
  15. /**
  16. * @package Tests\Settings\Controller
  17. */
  18. class SecuritySettingsControllerTest extends \Test\TestCase {
  19. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  20. private $config;
  21. /** @var SecuritySettingsController */
  22. private $securitySettingsController;
  23. protected function setUp() {
  24. parent::setUp();
  25. $this->config = $this->createMock(IConfig::class);
  26. $this->securitySettingsController = new SecuritySettingsController(
  27. 'settings',
  28. $this->createMock(IRequest::class),
  29. $this->config
  30. );
  31. }
  32. public function testTrustedDomainsWithExistingValues() {
  33. $this->config
  34. ->expects($this->once())
  35. ->method('setSystemValue')
  36. ->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com'));
  37. $this->config
  38. ->expects($this->once())
  39. ->method('getSystemValue')
  40. ->with('trusted_domains')
  41. ->will($this->returnValue(array('owncloud.org', 'owncloud.com')));
  42. $response = $this->securitySettingsController->trustedDomains('newdomain.com');
  43. $expectedResponse = array('status' => 'success');
  44. $this->assertSame($expectedResponse, $response);
  45. }
  46. public function testTrustedDomainsEmpty() {
  47. $this->config
  48. ->expects($this->once())
  49. ->method('setSystemValue')
  50. ->with('trusted_domains', array('newdomain.com'));
  51. $this->config
  52. ->expects($this->once())
  53. ->method('getSystemValue')
  54. ->with($this->equalTo('trusted_domains'), $this->equalTo([]))
  55. ->willReturn([]);
  56. $response = $this->securitySettingsController->trustedDomains('newdomain.com');
  57. $expectedResponse = array('status' => 'success');
  58. $this->assertSame($expectedResponse, $response);
  59. }
  60. }