SecuritySettingsControllerTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. }