@@ -96,6 +96,7 @@ class UsersController extends Controller { | |||
* @param string $fromMailAddress | |||
* @param IURLGenerator $urlGenerator | |||
* @param IAppManager $appManager | |||
* @param IAvatarManager $avatarManager | |||
*/ | |||
public function __construct($appName, | |||
IRequest $request, |
@@ -55,6 +55,7 @@ class EncryptionControllerTest extends TestCase { | |||
private $encryptionController; | |||
public function setUp() { | |||
parent::setUp(); | |||
$this->request = $this->getMockBuilder('\\OCP\\IRequest') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->l10n = $this->getMockBuilder('\\OCP\\IL10N') |
@@ -10,42 +10,47 @@ | |||
namespace Tests\Settings\Controller; | |||
use OC\Group\Group; | |||
use OC\Group\MetaData; | |||
use \OC\Settings\Application; | |||
use OC\Settings\Controller\GroupsController; | |||
use OCP\AppFramework\Http; | |||
use OCP\AppFramework\Http\DataResponse; | |||
use OCP\IGroupManager; | |||
use OCP\IL10N; | |||
use OCP\IRequest; | |||
use OCP\IUserSession; | |||
/** | |||
* @package Tests\Settings\Controller | |||
*/ | |||
class GroupsControllerTest extends \Test\TestCase { | |||
/** @var \OCP\AppFramework\IAppContainer */ | |||
private $container; | |||
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $groupManager; | |||
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $userSession; | |||
/** @var GroupsController */ | |||
private $groupsController; | |||
protected function setUp() { | |||
$app = new Application(); | |||
$this->container = $app->getContainer(); | |||
$this->container['AppName'] = 'settings'; | |||
$this->container['GroupManager'] = $this->getMockBuilder('\OCP\IGroupManager') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['IsAdmin'] = true; | |||
$this->container['L10N'] | |||
->expects($this->any()) | |||
->method('t') | |||
->will($this->returnCallback(function($text, $parameters = array()) { | |||
return vsprintf($text, $parameters); | |||
})); | |||
$this->groupsController = $this->container['GroupsController']; | |||
parent::setUp(); | |||
$this->groupManager = $this->createMock(IGroupManager::class); | |||
$this->userSession = $this->createMock(IUserSession::class); | |||
$l = $this->createMock(IL10N::class); | |||
$l->method('t') | |||
->will($this->returnCallback(function($text, $parameters = []) { | |||
return vsprintf($text, $parameters); | |||
})); | |||
$this->groupsController = new GroupsController( | |||
'settings', | |||
$this->createMock(IRequest::class), | |||
$this->groupManager, | |||
$this->userSession, | |||
true, | |||
$l | |||
); | |||
} | |||
@@ -95,7 +100,7 @@ class GroupsControllerTest extends \Test\TestCase { | |||
$user = $this->getMockBuilder('\OC\User\User') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['UserSession'] | |||
$this->userSession | |||
->expects($this->once()) | |||
->method('getUser') | |||
->will($this->returnValue($user)); | |||
@@ -103,8 +108,7 @@ class GroupsControllerTest extends \Test\TestCase { | |||
->expects($this->once()) | |||
->method('getUID') | |||
->will($this->returnValue('MyAdminUser')); | |||
$this->container['GroupManager'] | |||
->method('search') | |||
$this->groupManager->method('search') | |||
->will($this->returnValue($groups)); | |||
$expectedResponse = new DataResponse( | |||
@@ -188,7 +192,7 @@ class GroupsControllerTest extends \Test\TestCase { | |||
$user = $this->getMockBuilder('\OC\User\User') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['UserSession'] | |||
$this->userSession | |||
->expects($this->once()) | |||
->method('getUser') | |||
->will($this->returnValue($user)); | |||
@@ -196,7 +200,7 @@ class GroupsControllerTest extends \Test\TestCase { | |||
->expects($this->once()) | |||
->method('getUID') | |||
->will($this->returnValue('MyAdminUser')); | |||
$this->container['GroupManager'] | |||
$this->groupManager | |||
->method('search') | |||
->will($this->returnValue($groups)); | |||
@@ -236,7 +240,7 @@ class GroupsControllerTest extends \Test\TestCase { | |||
} | |||
public function testCreateWithExistingGroup() { | |||
$this->container['GroupManager'] | |||
$this->groupManager | |||
->expects($this->once()) | |||
->method('groupExists') | |||
->with('ExistingGroup') | |||
@@ -253,12 +257,12 @@ class GroupsControllerTest extends \Test\TestCase { | |||
} | |||
public function testCreateSuccessful() { | |||
$this->container['GroupManager'] | |||
$this->groupManager | |||
->expects($this->once()) | |||
->method('groupExists') | |||
->with('NewGroup') | |||
->will($this->returnValue(false)); | |||
$this->container['GroupManager'] | |||
$this->groupManager | |||
->expects($this->once()) | |||
->method('createGroup') | |||
->with('NewGroup') | |||
@@ -275,12 +279,12 @@ class GroupsControllerTest extends \Test\TestCase { | |||
} | |||
public function testCreateUnsuccessful() { | |||
$this->container['GroupManager'] | |||
$this->groupManager | |||
->expects($this->once()) | |||
->method('groupExists') | |||
->with('NewGroup') | |||
->will($this->returnValue(false)); | |||
$this->container['GroupManager'] | |||
$this->groupManager | |||
->expects($this->once()) | |||
->method('createGroup') | |||
->with('NewGroup') | |||
@@ -300,7 +304,7 @@ class GroupsControllerTest extends \Test\TestCase { | |||
public function testDestroySuccessful() { | |||
$group = $this->getMockBuilder('\OC\Group\Group') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['GroupManager'] | |||
$this->groupManager | |||
->expects($this->once()) | |||
->method('get') | |||
->with('ExistingGroup') | |||
@@ -322,7 +326,7 @@ class GroupsControllerTest extends \Test\TestCase { | |||
} | |||
public function testDestroyUnsuccessful() { | |||
$this->container['GroupManager'] | |||
$this->groupManager | |||
->expects($this->once()) | |||
->method('get') | |||
->with('ExistingGroup') |
@@ -13,25 +13,36 @@ namespace Tests\Settings\Controller; | |||
use \OC\Settings\Application; | |||
use OC\Settings\Controller\LogSettingsController; | |||
use OCP\AppFramework\Http\StreamResponse; | |||
use OCP\IConfig; | |||
use OCP\IL10N; | |||
use OCP\IRequest; | |||
/** | |||
* @package Tests\Settings\Controller | |||
*/ | |||
class LogSettingsControllerTest extends \Test\TestCase { | |||
/** @var \OCP\AppFramework\IAppContainer */ | |||
private $container; | |||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $config; | |||
/** @var LogSettingsController */ | |||
private $logSettingsController; | |||
protected function setUp() { | |||
$app = new Application(); | |||
$this->container = $app->getContainer(); | |||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['AppName'] = 'settings'; | |||
$this->logSettingsController = $this->container['LogSettingsController']; | |||
parent::setUp(); | |||
$this->config = $this->createMock(IConfig::class); | |||
$l = $this->createMock(IL10N::class); | |||
$l->method('t') | |||
->will($this->returnCallback(function($text, $parameters = []) { | |||
return vsprintf($text, $parameters); | |||
})); | |||
$this->logSettingsController = new LogSettingsController( | |||
'settings', | |||
$this->createMock(IRequest::class), | |||
$this->config, | |||
$l | |||
); | |||
} | |||
/** | |||
@@ -39,8 +50,7 @@ class LogSettingsControllerTest extends \Test\TestCase { | |||
*/ | |||
public function testSetLogLevel($level, $inRange) { | |||
if ($inRange) { | |||
$this->container['Config'] | |||
->expects($this->once()) | |||
$this->config->expects($this->once()) | |||
->method('setSystemValue') | |||
->with('loglevel', $level); | |||
} |
@@ -10,39 +10,54 @@ | |||
namespace Tests\Settings\Controller; | |||
use OC\Settings\Application; | |||
use OC\Mail\Message; | |||
use OC\Settings\Controller\MailSettingsController; | |||
use OCP\IConfig; | |||
use OCP\IL10N; | |||
use OCP\IRequest; | |||
use OCP\IUserSession; | |||
use OCP\Mail\IMailer; | |||
/** | |||
* @package Tests\Settings\Controller | |||
*/ | |||
class MailSettingsControllerTest extends \Test\TestCase { | |||
private $container; | |||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $config; | |||
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $userSession; | |||
/** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $mailer; | |||
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $l; | |||
/** @var MailSettingsController */ | |||
private $mailController; | |||
protected function setUp() { | |||
parent::setUp(); | |||
$app = new Application(); | |||
$this->container = $app->getContainer(); | |||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['AppName'] = 'settings'; | |||
$this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['MailMessage'] = $this->getMockBuilder('\OCP\Mail\IMessage') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['Mailer'] = $this->getMockBuilder('\OC\Mail\Mailer') | |||
->setMethods(['send']) | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['DefaultMailAddress'] = 'no-reply@owncloud.com'; | |||
$this->l = $this->createMock(IL10N::class); | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->userSession = $this->createMock(IUserSession::class); | |||
$this->mailer = $this->createMock(IMailer::class); | |||
// $this->mailer = $this->getMockBuilder(IMailer::class) | |||
// ->setMethods(['send']) | |||
// ->getMock(); | |||
$this->mailController = new MailSettingsController( | |||
'settings', | |||
$this->createMock(IRequest::class), | |||
$this->l, | |||
$this->config, | |||
$this->userSession, | |||
$this->mailer, | |||
'no-reply@owncloud.com' | |||
); | |||
} | |||
public function testSetMailSettings() { | |||
$this->container['L10N'] | |||
$this->l | |||
->expects($this->exactly(2)) | |||
->method('t') | |||
->will($this->returnValue('Saved')); | |||
@@ -51,7 +66,7 @@ class MailSettingsControllerTest extends \Test\TestCase { | |||
* FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1 | |||
*/ | |||
/* | |||
$this->container['Config'] | |||
$this->config | |||
->expects($this->exactly(15)) | |||
->method('setSystemValue') | |||
->withConsecutive( | |||
@@ -74,8 +89,7 @@ class MailSettingsControllerTest extends \Test\TestCase { | |||
*/ | |||
/** @var \PHPUnit_Framework_MockObject_MockObject $config */ | |||
$config = $this->container['Config']; | |||
$config->expects($this->exactly(2)) | |||
$this->config->expects($this->exactly(2)) | |||
->method('setSystemValues'); | |||
/** | |||
* FIXME: Use the following block once Jenkins uses PHPUnit >= 4.1 | |||
@@ -106,7 +120,7 @@ class MailSettingsControllerTest extends \Test\TestCase { | |||
*/ | |||
// With authentication | |||
$response = $this->container['MailSettingsController']->setMailSettings( | |||
$response = $this->mailController->setMailSettings( | |||
'owncloud.com', | |||
'demo@owncloud.com', | |||
'smtp', | |||
@@ -120,7 +134,7 @@ class MailSettingsControllerTest extends \Test\TestCase { | |||
$this->assertSame($expectedResponse, $response); | |||
// Without authentication (testing the deletion of the stored password) | |||
$response = $this->container['MailSettingsController']->setMailSettings( | |||
$response = $this->mailController->setMailSettings( | |||
'owncloud.com', | |||
'demo@owncloud.com', | |||
'smtp', | |||
@@ -136,12 +150,12 @@ class MailSettingsControllerTest extends \Test\TestCase { | |||
} | |||
public function testStoreCredentials() { | |||
$this->container['L10N'] | |||
$this->l | |||
->expects($this->once()) | |||
->method('t') | |||
->will($this->returnValue('Saved')); | |||
$this->container['Config'] | |||
$this->config | |||
->expects($this->once()) | |||
->method('setSystemValues') | |||
->with([ | |||
@@ -149,7 +163,7 @@ class MailSettingsControllerTest extends \Test\TestCase { | |||
'mail_smtppassword' => 'PasswordToStore', | |||
]); | |||
$response = $this->container['MailSettingsController']->storeCredentials('UsernameToStore', 'PasswordToStore'); | |||
$response = $this->mailController->storeCredentials('UsernameToStore', 'PasswordToStore'); | |||
$expectedResponse = array('data' => array('message' =>'Saved'), 'status' => 'success'); | |||
$this->assertSame($expectedResponse, $response); | |||
@@ -166,7 +180,7 @@ class MailSettingsControllerTest extends \Test\TestCase { | |||
->method('getDisplayName') | |||
->will($this->returnValue('Werner Brösel')); | |||
$this->container['L10N'] | |||
$this->l | |||
->expects($this->any()) | |||
->method('t') | |||
->will( | |||
@@ -182,22 +196,25 @@ class MailSettingsControllerTest extends \Test\TestCase { | |||
'If you received this email, the settings seem to be correct.') | |||
) | |||
)); | |||
$this->container['UserSession'] | |||
$this->userSession | |||
->expects($this->any()) | |||
->method('getUser') | |||
->will($this->returnValue($user)); | |||
// Ensure that it fails when no mail address has been specified | |||
$response = $this->container['MailSettingsController']->sendTestMail(); | |||
$response = $this->mailController->sendTestMail(); | |||
$expectedResponse = array('data' => array('message' =>'You need to set your user email before being able to send test emails.'), 'status' => 'error'); | |||
$this->assertSame($expectedResponse, $response); | |||
// If no exception is thrown it should work | |||
$this->container['Config'] | |||
$this->config | |||
->expects($this->any()) | |||
->method('getUserValue') | |||
->will($this->returnValue('mail@example.invalid')); | |||
$response = $this->container['MailSettingsController']->sendTestMail(); | |||
$this->mailer->expects($this->once()) | |||
->method('createMessage') | |||
->willReturn($this->createMock(Message::class)); | |||
$response = $this->mailController->sendTestMail(); | |||
$expectedResponse = array('data' => array('message' =>'Email sent'), 'status' => 'success'); | |||
$this->assertSame($expectedResponse, $response); | |||
} |
@@ -11,33 +11,37 @@ namespace Tests\Settings\Controller; | |||
use \OC\Settings\Application; | |||
use OC\Settings\Controller\SecuritySettingsController; | |||
use OCP\IConfig; | |||
use OCP\IRequest; | |||
/** | |||
* @package Tests\Settings\Controller | |||
*/ | |||
class SecuritySettingsControllerTest extends \PHPUnit_Framework_TestCase { | |||
class SecuritySettingsControllerTest extends \Test\TestCase { | |||
/** @var \OCP\AppFramework\IAppContainer */ | |||
private $container; | |||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $config; | |||
/** @var SecuritySettingsController */ | |||
private $securitySettingsController; | |||
protected function setUp() { | |||
$app = new Application(); | |||
$this->container = $app->getContainer(); | |||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->container['AppName'] = 'settings'; | |||
$this->securitySettingsController = $this->container['SecuritySettingsController']; | |||
parent::setUp(); | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->securitySettingsController = new SecuritySettingsController( | |||
'settings', | |||
$this->createMock(IRequest::class), | |||
$this->config | |||
); | |||
} | |||
public function testTrustedDomainsWithExistingValues() { | |||
$this->container['Config'] | |||
$this->config | |||
->expects($this->once()) | |||
->method('setSystemValue') | |||
->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com')); | |||
$this->container['Config'] | |||
$this->config | |||
->expects($this->once()) | |||
->method('getSystemValue') | |||
->with('trusted_domains') | |||
@@ -50,11 +54,11 @@ class SecuritySettingsControllerTest extends \PHPUnit_Framework_TestCase { | |||
} | |||
public function testTrustedDomainsEmpty() { | |||
$this->container['Config'] | |||
$this->config | |||
->expects($this->once()) | |||
->method('setSystemValue') | |||
->with('trusted_domains', array('newdomain.com')); | |||
$this->container['Config'] | |||
$this->config | |||
->expects($this->once()) | |||
->method('getSystemValue') | |||
->with($this->equalTo('trusted_domains'), $this->equalTo([])) |
@@ -33,6 +33,7 @@ class SubadminMiddlewareTest extends \Test\TestCase { | |||
private $controller; | |||
protected function setUp() { | |||
parent::setUp(); | |||
$this->reflector = $this->getMockBuilder('\OC\AppFramework\Utility\ControllerMethodReflector') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->controller = $this->getMockBuilder('\OCP\AppFramework\Controller') |