From f589f1a1d62bac542f96082c3db2c9577c841e59 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 24 Oct 2016 11:46:25 +0200 Subject: [PATCH 1/2] Move files_sharing Controllers => Controller lib/Controller is the default location for controllers. So lets put them all in there. Signed-off-by: Roeland Jago Douma --- apps/files_sharing/lib/AppInfo/Application.php | 4 ++-- .../{Controllers => Controller}/ExternalSharesController.php | 4 ++-- .../lib/{Controllers => Controller}/ShareController.php | 2 +- apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php | 4 ++-- .../ExternalShareControllerTest.php | 2 +- .../tests/{Controllers => Controller}/ShareControllerTest.php | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) rename apps/files_sharing/lib/{Controllers => Controller}/ExternalSharesController.php (97%) rename apps/files_sharing/lib/{Controllers => Controller}/ShareController.php (99%) rename apps/files_sharing/tests/{Controllers => Controller}/ExternalShareControllerTest.php (98%) rename apps/files_sharing/tests/{Controllers => Controller}/ShareControllerTest.php (99%) diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 29cdf702a5..922db7dac7 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -32,8 +32,8 @@ use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware; use OCA\Files_Sharing\MountProvider; use OCP\AppFramework\App; use OC\AppFramework\Utility\SimpleContainer; -use OCA\Files_Sharing\Controllers\ExternalSharesController; -use OCA\Files_Sharing\Controllers\ShareController; +use OCA\Files_Sharing\Controller\ExternalSharesController; +use OCA\Files_Sharing\Controller\ShareController; use OCA\Files_Sharing\Middleware\SharingCheckMiddleware; use \OCP\IContainer; use OCP\IServerContainer; diff --git a/apps/files_sharing/lib/Controllers/ExternalSharesController.php b/apps/files_sharing/lib/Controller/ExternalSharesController.php similarity index 97% rename from apps/files_sharing/lib/Controllers/ExternalSharesController.php rename to apps/files_sharing/lib/Controller/ExternalSharesController.php index 24b3211e00..fe4c09dd19 100644 --- a/apps/files_sharing/lib/Controllers/ExternalSharesController.php +++ b/apps/files_sharing/lib/Controller/ExternalSharesController.php @@ -24,7 +24,7 @@ * */ -namespace OCA\Files_Sharing\Controllers; +namespace OCA\Files_Sharing\Controller; use OCP\AppFramework\Controller; use OCP\IRequest; @@ -35,7 +35,7 @@ use OCP\AppFramework\Http\DataResponse; /** * Class ExternalSharesController * - * @package OCA\Files_Sharing\Controllers + * @package OCA\Files_Sharing\Controller */ class ExternalSharesController extends Controller { diff --git a/apps/files_sharing/lib/Controllers/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php similarity index 99% rename from apps/files_sharing/lib/Controllers/ShareController.php rename to apps/files_sharing/lib/Controller/ShareController.php index 8e3405311e..62725115dd 100644 --- a/apps/files_sharing/lib/Controllers/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -30,7 +30,7 @@ * */ -namespace OCA\Files_Sharing\Controllers; +namespace OCA\Files_Sharing\Controller; use OC_Files; use OC_Util; diff --git a/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php b/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php index 7c5eb5afbd..7e9109bf2d 100644 --- a/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php +++ b/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php @@ -78,10 +78,10 @@ class SharingCheckMiddleware extends Middleware { throw new NotFoundException('Sharing is disabled.'); } - if ($controller instanceof \OCA\Files_Sharing\Controllers\ExternalSharesController && + if ($controller instanceof \OCA\Files_Sharing\Controller\ExternalSharesController && !$this->externalSharesChecks()) { throw new S2SException('Federated sharing not allowed'); - } else if ($controller instanceof \OCA\Files_Sharing\Controllers\ShareController && + } else if ($controller instanceof \OCA\Files_Sharing\Controller\ShareController && !$this->isLinkSharingEnabled()) { throw new NotFoundException('Link sharing is disabled'); } diff --git a/apps/files_sharing/tests/Controllers/ExternalShareControllerTest.php b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php similarity index 98% rename from apps/files_sharing/tests/Controllers/ExternalShareControllerTest.php rename to apps/files_sharing/tests/Controller/ExternalShareControllerTest.php index e5fd739c4f..71a4f4adeb 100644 --- a/apps/files_sharing/tests/Controllers/ExternalShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php @@ -24,7 +24,7 @@ namespace OCA\Files_Sharing\Tests\Controllers; -use OCA\Files_Sharing\Controllers\ExternalSharesController; +use OCA\Files_Sharing\Controller\ExternalSharesController; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; use OCP\Http\Client\IClientService; diff --git a/apps/files_sharing/tests/Controllers/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php similarity index 99% rename from apps/files_sharing/tests/Controllers/ShareControllerTest.php rename to apps/files_sharing/tests/Controller/ShareControllerTest.php index 94891d868c..dae7740b3a 100644 --- a/apps/files_sharing/tests/Controllers/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php @@ -33,7 +33,7 @@ namespace OCA\Files_Sharing\Tests\Controllers; use OC\Files\Filesystem; use OCA\FederatedFileSharing\FederatedShareProvider; -use OCA\Files_Sharing\Controllers\ShareController; +use OCA\Files_Sharing\Controller\ShareController; use OCP\AppFramework\Http\DataResponse; use OCP\Share\Exceptions\ShareNotFound; use OCP\AppFramework\Http\NotFoundResponse; @@ -96,7 +96,7 @@ class ShareControllerTest extends \Test\TestCase { ->method('isIncomingServer2serverShareEnabled')->willReturn(true); $this->eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); - $this->shareController = new \OCA\Files_Sharing\Controllers\ShareController( + $this->shareController = new \OCA\Files_Sharing\Controller\ShareController( $this->appName, $this->getMockBuilder('\OCP\IRequest')->getMock(), $this->config, From b4ebf03bef576c8c454cf0960dfc35632cc6913a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 24 Oct 2016 13:25:59 +0200 Subject: [PATCH 2/2] Fix tests Signed-off-by: Roeland Jago Douma --- .../Middleware/SharingCheckMiddlewareTest.php | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php b/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php index 2323317f66..c2965d04b6 100644 --- a/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php +++ b/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php @@ -24,37 +24,40 @@ */ namespace OCA\Files_Sharing\Middleware; +use OCA\Files_Sharing\Controller\ExternalSharesController; +use OCA\Files_Sharing\Controller\ShareController; +use OCP\App\IAppManager; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\NotFoundResponse; use OCP\Files\NotFoundException; use OCP\AppFramework\Utility\IControllerMethodReflector; use OCA\Files_Sharing\Exceptions\S2SException; use OCP\AppFramework\Http\JSONResponse; +use OCP\IConfig; /** * @package OCA\Files_Sharing\Middleware\SharingCheckMiddleware */ class SharingCheckMiddlewareTest extends \Test\TestCase { - /** @var \OCP\IConfig */ + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; - /** @var \OCP\App\IAppManager */ + /** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */ private $appManager; /** @var SharingCheckMiddleware */ private $sharingCheckMiddleware; - /** @var \OCP\AppFramework\Controller */ + /** @var Controller|\PHPUnit_Framework_MockObject_MockObject */ private $controllerMock; - /** @var IControllerMethodReflector */ + /** @var IControllerMethodReflector|\PHPUnit_Framework_MockObject_MockObject */ private $reflector; protected function setUp() { - $this->config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor()->getMock(); - $this->appManager = $this->getMockBuilder('\OCP\App\IAppManager') - ->disableOriginalConstructor()->getMock(); - $this->controllerMock = $this->getMockBuilder('\OCP\AppFramework\Controller') - ->disableOriginalConstructor()->getMock(); - $this->reflector = $this->getMockBuilder('\OCP\AppFramework\Utility\IControllerMethodReflector') - ->disableOriginalConstructor()->getMock(); + parent::setUp(); + + $this->config = $this->createMock(IConfig::class); + $this->appManager = $this->createMock(IAppManager::class); + $this->controllerMock = $this->createMock(Controller::class); + $this->reflector = $this->createMock(IControllerMethodReflector::class); $this->sharingCheckMiddleware = new SharingCheckMiddleware( 'files_sharing', @@ -198,14 +201,13 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { ->method('getAppValue') ->will($this->returnValueMap($config)); - $controller = $this->getMockBuilder('\OCA\Files_Sharing\Controllers\ExternalSharesController') - ->disableOriginalConstructor()->getMock(); + $controller = $this->createMock(ExternalSharesController::class); $exceptionThrown = false; try { $this->sharingCheckMiddleware->beforeController($controller, 'myMethod'); - } catch (\OCA\Files_Sharing\Exceptions\S2SException $exception) { + } catch (S2SException $exception) { $exceptionThrown = true; } @@ -231,8 +233,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { ->with('core', 'shareapi_allow_links', 'yes') ->will($this->returnValue('yes')); - $controller = $this->getMockBuilder('\OCA\Files_Sharing\Controllers\ShareController') - ->disableOriginalConstructor()->getMock(); + $controller = $this->createMock(ShareController::class); $this->sharingCheckMiddleware->beforeController($controller, 'myMethod'); } @@ -248,8 +249,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase { ->with('files_sharing') ->will($this->returnValue(true)); - $controller = $this->getMockBuilder('\OCA\Files_Sharing\Controllers\ShareController') - ->disableOriginalConstructor()->getMock(); + $controller = $this->createMock(ShareController::class); $this->sharingCheckMiddleware->beforeController($controller, 'myMethod'); }