Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
c4055af2
Commit
c4055af2
authored
9 years ago
by
Vincent Petry
Browse files
Options
Downloads
Plain Diff
Merge pull request #17927 from owncloud/fix_17925
set logger in constructor
parents
c34e63bb
7f6c5e45
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
settings/controller/encryptioncontroller.php
+26
-13
26 additions, 13 deletions
settings/controller/encryptioncontroller.php
tests/settings/controller/EncryptionControllerTest.php
+151
-0
151 additions, 0 deletions
tests/settings/controller/EncryptionControllerTest.php
with
177 additions
and
13 deletions
settings/controller/encryptioncontroller.php
+
26
−
13
View file @
c4055af2
...
@@ -78,6 +78,21 @@ class EncryptionController extends Controller {
...
@@ -78,6 +78,21 @@ class EncryptionController extends Controller {
$this
->
connection
=
$connection
;
$this
->
connection
=
$connection
;
$this
->
view
=
$view
;
$this
->
view
=
$view
;
$this
->
userManager
=
$userManager
;
$this
->
userManager
=
$userManager
;
$this
->
logger
=
$logger
;
}
/**
* @param IConfig $config
* @param View $view
* @param Connection $connection
* @param ILogger $logger
* @return Migration
*/
protected
function
getMigration
(
IConfig
$config
,
View
$view
,
Connection
$connection
,
ILogger
$logger
)
{
return
new
Migration
(
$config
,
$view
,
$connection
,
$logger
);
}
}
/**
/**
...
@@ -91,12 +106,11 @@ class EncryptionController extends Controller {
...
@@ -91,12 +106,11 @@ class EncryptionController extends Controller {
try
{
try
{
$migration
=
new
Migration
(
$this
->
config
,
$this
->
view
,
$this
->
connection
,
$this
->
logger
);
$migration
=
$this
->
get
Migration
(
$this
->
config
,
$this
->
view
,
$this
->
connection
,
$this
->
logger
);
$migration
->
reorganizeSystemFolderStructure
();
$migration
->
reorganizeSystemFolderStructure
();
$migration
->
updateDB
();
$migration
->
updateDB
();
foreach
(
$this
->
userManager
->
getBackends
()
as
$backend
)
{
foreach
(
$this
->
userManager
->
getBackends
()
as
$backend
)
{
$limit
=
500
;
$limit
=
500
;
$offset
=
0
;
$offset
=
0
;
do
{
do
{
...
@@ -111,21 +125,20 @@ class EncryptionController extends Controller {
...
@@ -111,21 +125,20 @@ class EncryptionController extends Controller {
$migration
->
finalCleanUp
();
$migration
->
finalCleanUp
();
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
return
array
(
return
[
'data'
=>
array
(
'data'
=>
[
'message'
=>
(
string
)
$this
->
l10n
->
t
(
'A problem occurred, please check your log files (Error: %s)'
,
[
$e
->
getMessage
()]),
'message'
=>
(
string
)
$this
->
l10n
->
t
(
'A problem occurred, please check your log files (Error: %s)'
,
[
$e
->
getMessage
()]),
)
,
]
,
'status'
=>
'error'
,
'status'
=>
'error'
,
)
;
]
;
}
}
return
array
(
'data'
=>
return
[
array
(
'message'
=>
'data'
=>
[
(
string
)
$this
->
l10n
->
t
(
'Migration Completed'
)
'message'
=>
(
string
)
$this
->
l10n
->
t
(
'Migration Completed'
),
),
],
'status'
=>
'success'
'status'
=>
'success'
,
);
];
}
}
}
}
This diff is collapsed.
Click to expand it.
tests/settings/controller/EncryptionControllerTest.php
0 → 100644
+
151
−
0
View file @
c4055af2
<?php
/**
* @author Lukas Reschke <lukas@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace
OC\Settings\Controller
;
use
OC\DB\Connection
;
use
OC\Files\View
;
use
OCP\IConfig
;
use
OCP\IL10N
;
use
OCP\ILogger
;
use
OCP\IRequest
;
use
OCP\IUserManager
;
use
Test\TestCase
;
/**
* Class EncryptionControllerTest
*
* @package OC\Settings\Controller
*/
class
EncryptionControllerTest
extends
TestCase
{
/** @var IRequest */
private
$request
;
/** @var IL10N */
private
$l10n
;
/** @var IConfig */
private
$config
;
/** @var Connection */
private
$connection
;
/** @var IUserManager */
private
$userManager
;
/** @var View */
private
$view
;
/** @var ILogger */
private
$logger
;
/** @var EncryptionController */
private
$encryptionController
;
public
function
setUp
()
{
$this
->
request
=
$this
->
getMockBuilder
(
'\\OCP\\IRequest'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
l10n
=
$this
->
getMockBuilder
(
'\\OCP\\IL10N'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
l10n
->
expects
(
$this
->
any
())
->
method
(
't'
)
->
will
(
$this
->
returnCallback
(
function
(
$message
,
array
$replace
)
{
return
vsprintf
(
$message
,
$replace
);
}));
$this
->
config
=
$this
->
getMockBuilder
(
'\\OCP\\IConfig'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
connection
=
$this
->
getMockBuilder
(
'\\OC\\DB\\Connection'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
userManager
=
$this
->
getMockBuilder
(
'\\OCP\\IUserManager'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
view
=
$this
->
getMockBuilder
(
'\\OC\\Files\\View'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
logger
=
$this
->
getMockBuilder
(
'\\OCP\\ILogger'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
encryptionController
=
$this
->
getMockBuilder
(
'\\OC\\Settings\\Controller\\EncryptionController'
)
->
setConstructorArgs
([
'settings'
,
$this
->
request
,
$this
->
l10n
,
$this
->
config
,
$this
->
connection
,
$this
->
userManager
,
$this
->
view
,
$this
->
logger
,
])
->
setMethods
([
'getMigration'
])
->
getMock
();
}
public
function
testStartMigrationSuccessful
()
{
$migration
=
$this
->
getMockBuilder
(
'\\OCA\\Encryption\\Migration'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
encryptionController
->
expects
(
$this
->
once
())
->
method
(
'getMigration'
)
->
with
(
$this
->
config
,
$this
->
view
,
$this
->
connection
,
$this
->
logger
)
->
will
(
$this
->
returnValue
(
$migration
));
$migration
->
expects
(
$this
->
once
())
->
method
(
'reorganizeSystemFolderStructure'
);
$migration
->
expects
(
$this
->
once
())
->
method
(
'updateDB'
);
$backend
=
$this
->
getMockBuilder
(
'\OCP\UserInterface'
)
->
getMock
();
$this
->
userManager
->
expects
(
$this
->
once
())
->
method
(
'getBackends'
)
->
will
(
$this
->
returnValue
([
$backend
]));
$backend
->
expects
(
$this
->
once
())
->
method
(
'getUsers'
)
->
will
(
$this
->
returnValue
([
'User 1'
,
'User 2'
]));
$migration
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'reorganizeFolderStructureForUser'
)
->
withConsecutive
(
[
'User 1'
],
[
'User 2'
]
);
$migration
->
expects
(
$this
->
once
())
->
method
(
'finalCleanUp'
);
$expected
=
[
'data'
=>
[
'message'
=>
'Migration Completed'
,
],
'status'
=>
'success'
,
];
$this
->
assertSame
(
$expected
,
$this
->
encryptionController
->
startMigration
());
}
public
function
testStartMigrationException
()
{
$this
->
encryptionController
->
expects
(
$this
->
once
())
->
method
(
'getMigration'
)
->
with
(
$this
->
config
,
$this
->
view
,
$this
->
connection
,
$this
->
logger
)
->
will
(
$this
->
throwException
(
new
\Exception
(
'My error message'
)));
$expected
=
[
'data'
=>
[
'message'
=>
'A problem occurred, please check your log files (Error: My error message)'
,
],
'status'
=>
'error'
,
];
$this
->
assertSame
(
$expected
,
$this
->
encryptionController
->
startMigration
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment