securitysettingscontrollertest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 OC\Settings\Controller;
  11. use \OC\Settings\Application;
  12. /**
  13. * @package OC\Settings\Controller
  14. */
  15. class SecuritySettingsControllerTest extends \PHPUnit_Framework_TestCase {
  16. /** @var \OCP\AppFramework\IAppContainer */
  17. private $container;
  18. /** @var SecuritySettingsController */
  19. private $securitySettingsController;
  20. protected function setUp() {
  21. $app = new Application();
  22. $this->container = $app->getContainer();
  23. $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
  24. ->disableOriginalConstructor()->getMock();
  25. $this->container['AppName'] = 'settings';
  26. $this->securitySettingsController = $this->container['SecuritySettingsController'];
  27. }
  28. public function testTrustedDomainsWithExistingValues() {
  29. $this->container['Config']
  30. ->expects($this->once())
  31. ->method('setSystemValue')
  32. ->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com'));
  33. $this->container['Config']
  34. ->expects($this->once())
  35. ->method('getSystemValue')
  36. ->with('trusted_domains')
  37. ->will($this->returnValue(array('owncloud.org', 'owncloud.com')));
  38. $response = $this->securitySettingsController->trustedDomains('newdomain.com');
  39. $expectedResponse = array('status' => 'success');
  40. $this->assertSame($expectedResponse, $response);
  41. }
  42. public function testTrustedDomainsEmpty() {
  43. $this->container['Config']
  44. ->expects($this->once())
  45. ->method('setSystemValue')
  46. ->with('trusted_domains', array('newdomain.com'));
  47. $this->container['Config']
  48. ->expects($this->once())
  49. ->method('getSystemValue')
  50. ->with('trusted_domains')
  51. ->will($this->returnValue(''));
  52. $response = $this->securitySettingsController->trustedDomains('newdomain.com');
  53. $expectedResponse = array('status' => 'success');
  54. $this->assertSame($expectedResponse, $response);
  55. }
  56. }