public function __construct(IAppContainer $container, App $app)
 {
     $this->api = $container->query('API');
     $this->request = $container->query('Request');
     $this->server = $container->getServer();
     $this->app = $app;
 }
Example #2
0
 /**
  * Test set up
  */
 public function setUp()
 {
     parent::setUp();
     $app = new Application();
     $this->container = $app->getContainer();
     $this->rootFolder = $this->container->getServer()->getRootFolder();
     $this->userManager = $this->getMockBuilder('\\OCP\\IUserManager')->disableOriginalConstructor()->getMock();
     $this->serverContainer = $this->getMockBuilder('OCP\\IServerContainer')->disableOriginalConstructor()->getMock();
     $this->logger = $this->getMockBuilder('\\OCP\\ILogger')->disableOriginalConstructor()->getMock();
 }
Example #3
0
 private function registerApplication()
 {
     $this->container->registerService('UseCaseGetActivityHistory', function ($c) {
         return new GetActivityHistory($c->query('ActivityRepository'), $c->query('FilterFactory'));
     });
     $this->container->registerService('UseCaseGetStorageHistory', function ($c) {
         return new GetStorageHistory($c->query('StorageRepository'), $c->query('FilterFactory'));
     });
     $this->container->registerService('AddStorageHandler', function ($c) {
         return new AddStorageHandler($c->query('StorageRepository'));
     });
 }
Example #4
0
	public function registerServices() {
		$app = $this->app;
		$appName = $this->appName;

		$this->container->registerService('HttpMiddleware', function($container) {
			return new HttpMiddleware();
		});

		$this->container->registerService('PageController', function(IAppContainer $container) use($app, $appName) {
			$request = $container->query('Request');
			return new PageController($appName, $request);
		});
		$this->container->registerService('AddressBookController', function(IAppContainer $container) use($app, $appName) {
			$request = $container->query('Request');
			$api = $container->query('API');
			return new AddressBookController($appName, $request, $app, $api);
		});
		$this->container->registerService('BackendController', function(IAppContainer $container) use($app, $appName) {
			$request = $container->query('Request');
			return new BackendController($container, $request, $app);
		});
		$this->container->registerService('GroupController', function(IAppContainer $container) use($app, $appName) {
			$request = $container->query('Request');
			$tags = $container->getServer()->getTagManager()->load('contact', array(), true);
			return new GroupController($appName, $request, $app, $tags);
		});
		$this->container->registerService('ContactController', function(IAppContainer $container) use($app, $appName) {
			$request = $container->query('Request');
			return new ContactController($appName, $request, $app);
		});
		$this->container->registerService('ContactPhotoController', function(IAppContainer $container) use($app, $appName) {
			$request = $container->query('Request');
			$cache = $container->getServer()->getCache();
			return new ContactPhotoController($appName, $request, $app, $cache);
		});
		$this->container->registerService('SettingsController', function(IAppContainer $container) use($app, $appName) {
			$request = $container->query('Request');
			return new SettingsController($appName, $request, $app);
		});
		$this->container->registerService('ImportController', function(IAppContainer $container) use($app, $appName) {
			$request = $container->query('Request');
			$cache = $container->getServer()->getCache();
			$tags = $container->getServer()->getTagManager()->load('contact');
			return new ImportController($appName, $request, $app, $cache, $tags);
		});
		$this->container->registerService('ExportController', function(IAppContainer $container) use($app, $appName) {
			$request = $container->query('Request');
			return new ExportController($appName, $request, $app);
		});
	}
Example #5
0
 /**
  * Deletes all news entries of a given user
  * @param string $user
  */
 protected function clearUserNewsDatabase($user)
 {
     $sql = ['DELETE FROM `*PREFIX*news_items` WHERE `feed_id` IN
           (SELECT `id` FROM `*PREFIX*news_feeds` WHERE `user_id` = ?)', 'DELETE FROM `*PREFIX*news_feeds` WHERE `user_id` = ?', 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?'];
     $db = $this->container->query(IDb::class);
     foreach ($sql as $query) {
         $db->prepareQuery($query)->execute([$user]);
     }
 }
 /**
  * Shortcut for rendering a template
  * @param string $templateName the name of the template
  * @param array $params the template parameters in key => value structure
  * @param string $renderAs user renders a full page, blank only your template
  *                          admin an entry in the admin settings
  * @param array $headers set additional headers in name/value pairs
  * @return \OCP\AppFramework\Http\TemplateResponse containing the page
  */
 public function render($templateName, array $params = array(), $renderAs = 'user', array $headers = array())
 {
     $response = new TemplateResponse($this->app->getAppName(), $templateName);
     $response->setParams($params);
     $response->renderAs($renderAs);
     foreach ($headers as $name => $value) {
         $response->addHeader($name, $value);
     }
     return $response;
 }
 /**
  * Instantiates the environment
  *
  * @return Environment
  */
 private function instantiateEnvironment()
 {
     $this->container->registerService('UserId', function ($c) {
         return $this->userId;
     });
     $this->container->registerService('userFolder', function ($c) {
         return $this->userFolder;
     });
     return $this->container->query('OCA\\GalleryPlus\\Environment\\Environment');
 }
 protected function setUp()
 {
     $app = new Application();
     $this->container = $app->getContainer();
     $this->requestMock = $requestMock = $this->getMock('\\OCP\\IRequest');
     $this->container->registerService('Request', function ($c) use($requestMock) {
         return $requestMock;
     });
     $this->loggerMock = $loggerMock = $this->getMock('\\OCP\\ILogger');
     $this->container->registerService('Logger', function ($c) use($loggerMock) {
         return $loggerMock;
     });
     $this->translationMock = $translationMock = $this->getMock('\\OCP\\IL10N');
     $this->container->registerService('TranslationService', function ($c) use($translationMock) {
         return $translationMock;
     });
     $this->responseFactoryMock = $responseFactoryMock = $this->getMock('\\OCA\\EasyBackup\\ResponseFactory');
     $this->container->registerService('ResponseFactory', function ($c) use($responseFactoryMock) {
         return $responseFactoryMock;
     });
 }
Example #9
0
 private function registerUsageChartsApi()
 {
     $this->container->registerService('ContentStatisticsClientApiConnection', function ($c) {
         return new ApiConnection(new \GuzzleHttp\Client(), $c->query('ServerContainer')->getConfig()->getAppValue($c->query('AppName'), 'url'), $c->query('ServerContainer')->getConfig()->getAppValue($c->query('AppName'), 'username'), $c->query('ServerContainer')->getConfig()->getAppValue($c->query('AppName'), 'password'));
     });
     $this->container->registerService('ContentStatisticsClient', function ($c) {
         return new ContentStatisticsClient(new ActivityStream($c->query('ContentStatisticsClientApiConnection')), new StorageStream($c->query('ContentStatisticsClientApiConnection')));
     });
     $useApi = $this->container->query('ServerContainer')->getConfig()->getAppValue($this->container->query('AppName'), 'useapi');
     $this->container->registerService('FileHooks', function ($c) use(&$useApi) {
         return new FileHooks($c->query('ContentStatisticsClient'), $useApi);
     });
     $this->container->registerService('ContentStatisticsUpdater', function ($c) {
         return new ContentStatisticsUpdater($c->query('ContentStatisticsClient'), $c->query('DataProviderFactory'), $c->query('OwncloudUsers'));
     });
 }
 /**
  * If an SecurityException is being caught, ajax requests return a JSON error
  * response and non ajax requests redirect to the index
  * @param Controller $controller the controller that is being called
  * @param string $methodName the name of the method that will be called on
  *                           the controller
  * @param \Exception $exception the thrown exception
  * @throws \Exception the passed in exception if it cant handle it
  * @return Response a Response object or null in case that the exception could not be handled
  */
 public function afterException($controller, $methodName, \Exception $exception)
 {
     if ($exception instanceof SecurityException) {
         if (stripos($this->request->getHeader('Accept'), 'html') === false) {
             $response = new JSONResponse(array('message' => $exception->getMessage()), $exception->getCode());
             $this->app->log($exception->getMessage(), 'debug');
         } else {
             // TODO: replace with link to route
             $url = $this->app->getServer()->getURLGenerator()->getAbsoluteURL('index.php');
             $response = new RedirectResponse($url);
             $this->app->log($exception->getMessage(), 'debug');
         }
         return $response;
     }
     throw $exception;
 }
Example #11
0
 /**
  * Called before executing all tests in a suite
  *
  * If the module is injected, you need to use _initialize()
  *
  * @param array $settings
  */
 public function _beforeSuite($settings = [])
 {
     $this->coreTestCase = new CoreTestCase();
     $app = new App('gallery-test-setup');
     $this->container = $app->getContainer();
     $this->server = $this->container->getServer();
     $this->rootFolder = $this->server->getRootFolder();
     $this->userManager = $this->server->getUserManager();
     /**
      * Logging hooks are missing at the moment, so we need to disable encryption
      *
      * @link https://github.com/owncloud/core/issues/18085#issuecomment-128093797
      */
     $this->server->getConfig()->setAppValue('core', 'encryption_enabled', 'no');
     // This is because the filesystem is not properly cleaned up sometimes
     $this->server->getAppManager()->disableApp('files_trashbin');
     $this->setPreviewProviders();
     $this->createTestSetup($this->userId, $this->userPassword);
     $this->createTestSetup($this->sharerUserId, $this->sharerPassword);
     $this->createShares();
 }
 /**
  * @dataProvider queryData
  * @param string $service
  * @param string $expected
  */
 public function testContainerQuery($service, $expected)
 {
     $this->assertTrue($this->container->query($service) instanceof $expected);
 }
Example #13
0
 /**
  * Registers the consumer to the Activity Manager
  *
  * @param IManager $am
  * @param IAppContainer $container
  */
 public static function register(IManager $am, IAppContainer $container)
 {
     $am->registerConsumer(function () use($am, $container) {
         return $container->query('Consumer');
     });
 }
 /**
  * @param IAppContainer $c
  */
 public function registerBackends(IAppContainer $c)
 {
     $l10n = $c->getServer()->getL10N($c->getAppName());
     // Local backend: Default database backend
     $this->backends->queue(function () use($c, $l10n) {
         return $this->backendFactory->createBackend('org.ownCloud.local', $this->backends, function () use($l10n) {
             return new Calendar\Backend\Local\Backend($l10n);
         }, function (Calendar\IBackend $backend) use($c) {
             $db = $c->getServer()->getDatabaseConnection();
             $factory = $c->query('CalendarFactory');
             return new Calendar\Backend\Local\Calendar($db, $backend, $factory);
         }, function (Calendar\ICalendar $calendar) use($c) {
             $db = $c->getServer()->getDatabaseConnection();
             $factory = $c->query('ObjectFactory');
             return new Calendar\Backend\Local\Object($db, $calendar, $factory);
         });
     });
     // Contacts backend: show contact's birthdays and anniversaries
     $contactsManager = $c->getServer()->getContactsManager();
     $this->backends->queue(function () use($c, $l10n, $contactsManager) {
         return $this->backendFactory->createBackend('org.ownCloud.contact', $this->backends, function () use($c, $contactsManager) {
             $appManager = $c->getServer()->getAppManager();
             return new Calendar\Backend\Contact\Backend($contactsManager, $appManager);
         }, function (Calendar\IBackend $backend) use($c, $contactsManager) {
             $l10n = $c->getServer()->getL10N('calendar');
             $calendarFactory = $c->query('CalendarFactory');
             return new Calendar\Backend\Contact\Calendar($contactsManager, $backend, $l10n, $calendarFactory);
         }, function (Calendar\ICalendar $calendar) use($c, $contactsManager) {
             $l10n = $c->getServer()->getL10N('calendar');
             $objectFactory = $c->query('ObjectFactory');
             return new Calendar\Backend\Contact\Object($contactsManager, $calendar, $l10n, $objectFactory);
         });
     });
     // Sharing backend: Enabling users to share calendars
     if (Share::isEnabled() && false) {
         $this->backends->queue(function () use($c, $l10n) {
             return $this->backendFactory->createBackend('org.ownCloud.sharing', $this->backends, function () {
                 return new Calendar\Backend\Sharing\Backend();
             }, function (Calendar\IBackend $backend) {
                 return new Calendar\Backend\Sharing\Calendar($backend);
             }, function (Calendar\ICalendar $calendar) {
                 return new Calendar\Backend\Sharing\Object($calendar);
             });
         });
     }
     // Webcal Backend: Show ICS files on the net
     if (function_exists('curl_init')) {
         $this->backends->queue(function () use($c, $l10n) {
             return $this->backendFactory->createBackend('org.ownCloud.webcal', $this->backends, function () use($c, $l10n) {
                 $subscriptions = $c->query('SubscriptionBusinessLayer');
                 $cacheFactory = $c->getServer()->getMemCacheFactory();
                 return new Calendar\Backend\WebCal\Backend($subscriptions, $l10n, $cacheFactory);
             }, function (Calendar\IBackend $backend) use($c, $l10n) {
                 $subscriptions = $c->query('SubscriptionBusinessLayer');
                 $cacheFactory = $c->getServer()->getMemCacheFactory();
                 $calendarFactory = $c->query('CalendarFactory');
                 return new Calendar\Backend\WebCal\Calendar($subscriptions, $l10n, $cacheFactory, $backend, $calendarFactory);
             }, function (Calendar\ICalendar $calendar) use($c, $l10n) {
                 $subscriptions = $c->query('SubscriptionBusinessLayer');
                 $cacheFactory = $c->getServer()->getMemCacheFactory();
                 $objectFactory = $c->query('ObjectFactory');
                 return new Calendar\Backend\WebCal\Object($subscriptions, $l10n, $cacheFactory, $calendar, $objectFactory);
             });
         });
     }
 }