2014-11-03 12:55:52 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Lukas Reschke
|
|
|
|
* @copyright 2014 Lukas Reschke lukas@owncloud.com
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
2016-05-19 12:17:01 +03:00
|
|
|
namespace Tests\Settings\Controller;
|
2014-11-03 12:55:52 +03:00
|
|
|
|
|
|
|
use \OC\Settings\Application;
|
2016-05-19 12:17:01 +03:00
|
|
|
use OC\Settings\Controller\SecuritySettingsController;
|
2016-10-06 15:05:52 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IRequest;
|
2014-11-03 12:55:52 +03:00
|
|
|
|
|
|
|
/**
|
2016-05-19 12:17:01 +03:00
|
|
|
* @package Tests\Settings\Controller
|
2014-11-03 12:55:52 +03:00
|
|
|
*/
|
2016-10-06 15:05:52 +03:00
|
|
|
class SecuritySettingsControllerTest extends \Test\TestCase {
|
2014-11-03 12:55:52 +03:00
|
|
|
|
2016-10-06 15:05:52 +03:00
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $config;
|
2014-11-03 12:55:52 +03:00
|
|
|
|
|
|
|
/** @var SecuritySettingsController */
|
|
|
|
private $securitySettingsController;
|
|
|
|
|
|
|
|
protected function setUp() {
|
2016-10-06 15:05:52 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
$this->securitySettingsController = new SecuritySettingsController(
|
|
|
|
'settings',
|
|
|
|
$this->createMock(IRequest::class),
|
|
|
|
$this->config
|
|
|
|
);
|
2014-11-03 12:55:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testTrustedDomainsWithExistingValues() {
|
2016-10-06 15:05:52 +03:00
|
|
|
$this->config
|
2014-11-03 12:55:52 +03:00
|
|
|
->expects($this->once())
|
|
|
|
->method('setSystemValue')
|
|
|
|
->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com'));
|
2016-10-06 15:05:52 +03:00
|
|
|
$this->config
|
2014-11-03 12:55:52 +03:00
|
|
|
->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->with('trusted_domains')
|
|
|
|
->will($this->returnValue(array('owncloud.org', 'owncloud.com')));
|
|
|
|
|
|
|
|
$response = $this->securitySettingsController->trustedDomains('newdomain.com');
|
|
|
|
$expectedResponse = array('status' => 'success');
|
|
|
|
|
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTrustedDomainsEmpty() {
|
2016-10-06 15:05:52 +03:00
|
|
|
$this->config
|
2014-11-03 12:55:52 +03:00
|
|
|
->expects($this->once())
|
|
|
|
->method('setSystemValue')
|
|
|
|
->with('trusted_domains', array('newdomain.com'));
|
2016-10-06 15:05:52 +03:00
|
|
|
$this->config
|
2014-11-03 12:55:52 +03:00
|
|
|
->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
2016-09-06 11:29:14 +03:00
|
|
|
->with($this->equalTo('trusted_domains'), $this->equalTo([]))
|
|
|
|
->willReturn([]);
|
2014-11-03 12:55:52 +03:00
|
|
|
|
|
|
|
$response = $this->securitySettingsController->trustedDomains('newdomain.com');
|
|
|
|
$expectedResponse = array('status' => 'success');
|
|
|
|
|
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
}
|