diff --git a/tests/apitest.php b/tests/apitest.php index 7d29e883f..f93a07f20 100644 --- a/tests/apitest.php +++ b/tests/apitest.php @@ -148,7 +148,11 @@ public function testGet($user, $start, $count, $expected) { \OC_User::setUserId($user); $this->assertEquals($user, \OC_User::getUser()); - $activityManager = new ActivityManager(); + $activityManager = new ActivityManager( + $this->getMock('OCP\IRequest'), + $this->getMock('OCP\IUserSession'), + $this->getMock('OCP\IConfig') + ); $activityManager->registerExtension(function() { return new Extension(\OCP\Util::getL10N('activity', 'en'), $this->getMock('\OCP\IURLGenerator')); }); diff --git a/tests/consumertest.php b/tests/consumertest.php index f4b820a30..5c09690b4 100644 --- a/tests/consumertest.php +++ b/tests/consumertest.php @@ -137,7 +137,11 @@ public function testReceiveEmail($type, $author, $affectedUser, $subject, $expec * @param array|false $expected */ public function testRegister($type, $author, $affectedUser, $subject, $expected) { - $activityManager = new ActivityManager(); + $activityManager = new ActivityManager( + $this->getMock('OCP\IRequest'), + $this->getMock('OCP\IUserSession'), + $this->getMock('OCP\IConfig') + ); $consumer = new Consumer($this->userSettings, $author); $container = $this->getMock('\OCP\AppFramework\IAppContainer'); $container->expects($this->any()) diff --git a/tests/controller/feedtest.php b/tests/controller/feedtest.php index aca1a8827..7356fde62 100644 --- a/tests/controller/feedtest.php +++ b/tests/controller/feedtest.php @@ -37,6 +37,9 @@ class FeedTest extends TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $userSettings; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $manager; + /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $session; @@ -67,6 +70,9 @@ protected function setUp() { $this->session = $this->getMockBuilder('OCP\IUserSession') ->disableOriginalConstructor() ->getMock(); + $this->manager = $this->getMockBuilder('OCP\Activity\IManager') + ->disableOriginalConstructor() + ->getMock(); $this->controller = new Feed( 'activity', @@ -75,7 +81,7 @@ protected function setUp() { $this->helper, $this->userSettings, $this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(), - $this->session, + $this->manager, $this->config, 'test' ); @@ -128,6 +134,9 @@ public function testShow($acceptHeader, $expectedHeader) { * @param string $expectedHeader */ public function testShowNoToken($acceptHeader, $expectedHeader) { + $this->manager->expects($this->any()) + ->method('getCurrentUserId') + ->willThrowException(new \UnexpectedValueException()); if ($acceptHeader !== null) { $this->request->expects($this->any()) ->method('getHeader') @@ -149,75 +158,6 @@ public function testShowNoToken($acceptHeader, $expectedHeader) { $this->assertContains($description, $renderedResponse); } - public function getUserFromTokenThrowInvalidTokenData() { - return [ - [null, []], - ['', []], - ['12345678901234567890123456789', []], - ['1234567890123456789012345678901', []], - ['123456789012345678901234567890', []], - ['123456789012345678901234567890', ['user1', 'user2']], - ]; - } - - /** - * @expectedException \UnexpectedValueException - * @dataProvider getUserFromTokenThrowInvalidTokenData - * - * @param string $token - * @param array $users - */ - public function testGetUserFromTokenThrowInvalidToken($token, $users) { - if ($token !== null) { - $this->request->expects($this->any()) - ->method('getParam') - ->with('token', '') - ->willReturn($token); - } - $this->config->expects($this->any()) - ->method('getUsersForUserValue') - ->with('activity', 'rsstoken', $token) - ->willReturn($users); - - \Test_Helper::invokePrivate($this->controller, 'getUserFromToken'); - } - - - public function getUserData() { - return [ - [null, '123456789012345678901234567890', 'user1'], - ['user2', null, 'user2'], - ['user2', '123456789012345678901234567890', 'user2'], - ]; - } - - /** - * @dataProvider getUserData - * - * @param string $userLoggedIn - * @param string $token - * @param string $expected - */ - public function testGetUser($userLoggedIn, $token, $expected) { - if ($userLoggedIn !== null) { - $this->mockUserSession($userLoggedIn); - } - - if ($token !== null) { - $this->request->expects($this->any()) - ->method('getParam') - ->with('token', '') - ->willReturn($token); - } - - $this->config->expects($this->any()) - ->method('getUsersForUserValue') - ->with('activity', 'rsstoken', '123456789012345678901234567890') - ->willReturn(['user1']); - - $this->assertEquals($expected, \Test_Helper::invokePrivate($this->controller, 'getUser')); - } - protected function mockUserSession($user) { $mockUser = $this->getMockBuilder('\OCP\IUser') ->disableOriginalConstructor() @@ -232,5 +172,8 @@ protected function mockUserSession($user) { $this->session->expects($this->any()) ->method('getUser') ->willReturn($mockUser); + $this->manager->expects($this->any()) + ->method('getCurrentUserId') + ->willReturn($user); } } diff --git a/tests/datahelpertest.php b/tests/datahelpertest.php index ba21aa89d..5a616a11b 100644 --- a/tests/datahelpertest.php +++ b/tests/datahelpertest.php @@ -132,7 +132,11 @@ public function translationData() { */ public function testTranslation($text, $params, $stripPath, $highlightParams, $expected) { $activityLanguage = \OCP\Util::getL10N('activity', 'en'); - $activityManager = new ActivityManager(); + $activityManager = new ActivityManager( + $this->getMock('OCP\IRequest'), + $this->getMock('OCP\IUserSession'), + $this->getMock('OCP\IConfig') + ); $activityManager->registerExtension(function() use ($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\OCP\IURLGenerator')); }); @@ -188,7 +192,11 @@ public function translationNotActivityAppData() { */ public function testTranslationNotActivityApp($text, $params, $stripPath, $highlightParams, $expected) { $activityLanguage = \OCP\Util::getL10N('activity', 'en'); - $activityManager = new ActivityManager(); + $activityManager = new ActivityManager( + $this->getMock('OCP\IRequest'), + $this->getMock('OCP\IUserSession'), + $this->getMock('OCP\IConfig') + ); $dataHelper = new DataHelper( $activityManager, diff --git a/tests/datatest.php b/tests/datatest.php index a18a30c3f..30372a65c 100644 --- a/tests/datatest.php +++ b/tests/datatest.php @@ -37,7 +37,11 @@ protected function setUp() { parent::setUp(); $this->activityLanguage = $activityLanguage = \OCP\Util::getL10N('activity', 'en'); - $activityManager = new ActivityManager(); + $activityManager = new ActivityManager( + $this->getMock('OCP\IRequest'), + $this->getMock('OCP\IUserSession'), + $this->getMock('OCP\IConfig') + ); $activityManager->registerExtension(function() use ($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\OCP\IURLGenerator')); }); diff --git a/tests/grouphelpertest.php b/tests/grouphelpertest.php index aca5bc530..448d1dac9 100644 --- a/tests/grouphelpertest.php +++ b/tests/grouphelpertest.php @@ -477,7 +477,11 @@ public function groupHelperData() { */ public function testGroupHelper($allowGrouping, $activities, $expected) { $activityLanguage = \OCP\Util::getL10N('activity', 'en'); - $activityManager = new ActivityManager(); + $activityManager = new ActivityManager( + $this->getMock('OCP\IRequest'), + $this->getMock('OCP\IUserSession'), + $this->getMock('OCP\IConfig') + ); $activityManager->registerExtension(function() use ($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\OCP\IURLGenerator')); }); diff --git a/tests/navigationtest.php b/tests/navigationtest.php index 41ab44dd5..d0bcc03fb 100644 --- a/tests/navigationtest.php +++ b/tests/navigationtest.php @@ -40,11 +40,23 @@ public function getTemplateData() { */ public function testGetTemplate($constructorActive, $forceActive) { $activityLanguage = \OCP\Util::getL10N('activity', 'en'); - $activityManager = new ActivityManager(); + $activityManager = new ActivityManager( + $this->getMock('OCP\IRequest'), + $this->getMock('OCP\IUserSession'), + $this->getMock('OCP\IConfig') + ); $activityManager->registerExtension(function() use ($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\OCP\IURLGenerator')); }); - $navigation = new Navigation($activityLanguage, $activityManager, \OC::$server->getURLGenerator(), $constructorActive); + $navigation = new Navigation( + $activityLanguage, + $activityManager, + \OC::$server->getURLGenerator(), + $this->getMockBuilder('OCA\Activity\UserSettings')->disableOriginalConstructor()->getMock(), + 'test', + '', + $constructorActive + ); $output = $navigation->getTemplate($forceActive)->fetchPage(); // Get only the template part with the navigation links diff --git a/tests/parameterhelpertest.php b/tests/parameterhelpertest.php index cde1407d7..d2fae06bb 100644 --- a/tests/parameterhelpertest.php +++ b/tests/parameterhelpertest.php @@ -52,7 +52,11 @@ protected function setUp() { ->disableOriginalConstructor() ->getMock(); $activityLanguage = \OCP\Util::getL10N('activity', 'en'); - $activityManager = new ActivityManager(); + $activityManager = new ActivityManager( + $this->getMock('OCP\IRequest'), + $this->getMock('OCP\IUserSession'), + $this->getMock('OCP\IConfig') + ); $activityManager->registerExtension(function() use ($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\OCP\IURLGenerator')); }); diff --git a/tests/usersettingstest.php b/tests/usersettingstest.php index 635502099..420f043a5 100644 --- a/tests/usersettingstest.php +++ b/tests/usersettingstest.php @@ -38,7 +38,11 @@ protected function setUp() { parent::setUp(); $activityLanguage = \OCP\Util::getL10N('activity', 'en'); - $activityManager = new ActivityManager(); + $activityManager = new ActivityManager( + $this->getMock('OCP\IRequest'), + $this->getMock('OCP\IUserSession'), + $this->getMock('OCP\IConfig') + ); $activityManager->registerExtension(function() use ($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\OCP\IURLGenerator')); });