Add tests for service creations

This commit is contained in:
Joas Schilling 2014-12-12 17:17:26 +01:00
Родитель b6a82ab317
Коммит 2f380bf0d1
2 изменённых файлов: 92 добавлений и 6 удалений

Просмотреть файл

@ -75,16 +75,25 @@ class Application extends App {
});
$container->registerService('Navigation', function(IContainer $c) {
/** @var \OC\Server $server */
$server = $c->query('ServerContainer');
$user = $server->getUserSession()->getUser();
$rssToken = ($user) ? $server->getConfig()->getUserValue($user->getUID(), 'activity', 'rsstoken') : '';
return new Navigation(
$c->query('ActivityL10N'),
$c->query('ServerContainer')->query('ActivityManager'),
$c->query('URLGenerator')
$server->query('ActivityManager'),
$c->query('URLGenerator'),
$rssToken
);
});
$container->registerService('UserSettings', function(IContainer $c) {
/** @var \OC\Server $server */
$server = $c->query('ServerContainer');
return new UserSettings(
$c->query('ServerContainer')->query('ActivityManager')
$server->query('ActivityManager')
);
});
@ -92,7 +101,9 @@ class Application extends App {
* Core Services
*/
$container->registerService('URLGenerator', function(IContainer $c) {
return $c->query('ServerContainer')->getURLGenerator();
/** @var \OC\Server $server */
$server = $c->query('ServerContainer');
return $server->getURLGenerator();
});
/**
@ -101,6 +112,10 @@ class Application extends App {
$container->registerService('SettingsController', function(IContainer $c) {
/** @var \OC\Server $server */
$server = $c->query('ServerContainer');
$user = $server->getUserSession()->getUser();
$userName = ($user) ? $user->getUID() : '';
return new Settings(
$c->query('AppName'),
$c->query('Request'),
@ -109,13 +124,17 @@ class Application extends App {
$c->query('URLGenerator'),
$c->query('ActivityData'),
$c->query('ActivityL10N'),
$server->getUserSession()->getUser()->getUID()
$userName
);
});
$container->registerService('ActivitiesController', function(IContainer $c) {
/** @var \OC\Server $server */
$server = $c->query('ServerContainer');
$user = $server->getUserSession()->getUser();
$userName = ($user) ? $user->getUID() : '';
return new Activities(
$c->query('AppName'),
$c->query('Request'),
@ -124,7 +143,7 @@ class Application extends App {
$c->query('GroupHelper'),
$c->query('Navigation'),
$c->query('UserSettings'),
$server->getUserSession()->getUser()->getUID()
$userName
);
});
}

67
tests/applicationtest.php Normal file
Просмотреть файл

@ -0,0 +1,67 @@
<?php
/**
* ownCloud - Activity App
*
* @author Joas Schilling
* @copyright 2014 Joas Schilling nickvergessen@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCA\Activity\Tests;
use OCA\Activity\AppInfo\Application;
class ApplicationTest extends TestCase {
/** @var \OCA\Activity\AppInfo\Application */
protected $app;
/** @var \OCP\AppFramework\IAppContainer */
protected $container;
protected function setUp() {
parent::setUp();
$this->app = new Application();
$this->container = $this->app->getContainer();
}
public function testContainerAppName() {
$this->app = new Application();
$this->assertEquals('activity', $this->container->getAppName());
}
public function queryData() {
return array(
array('ActivityData', 'OCA\Activity\Data'),
array('ActivityL10N', 'OCP\IL10N'),
array('DataHelper', 'OCA\Activity\DataHelper'),
array('GroupHelper', 'OCA\Activity\GroupHelper'),
array('Navigation', 'OCA\Activity\Navigation'),
array('UserSettings', 'OCA\Activity\UserSettings'),
array('URLGenerator', 'OCP\IURLGenerator'),
array('SettingsController', 'OCP\AppFramework\Controller'),
array('ActivitiesController', 'OCP\AppFramework\Controller'),
);
}
/**
* @dataProvider queryData
* @param string $service
* @param string $expected
*/
public function testContainerQuery($service, $expected) {
$this->assertTrue($this->container->query($service) instanceof $expected);
}
}