aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-03-25 17:46:19 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2015-03-30 15:23:10 +0200
commitdd535968e822c21084ecb4f118b3dc4f572bf330 (patch)
treecbcd123126bc2cef51b7f835e42cd0b7afae23c2
parent17f882c3cf2d99a786daff56df5da8280746affb (diff)
downloadnextcloud-server-dd535968e822c21084ecb4f118b3dc4f572bf330.tar.gz
nextcloud-server-dd535968e822c21084ecb4f118b3dc4f572bf330.zip
Add tests from getCurrentUserId() method and fix the constructor
-rw-r--r--tests/lib/activitymanager.php110
1 files changed, 109 insertions, 1 deletions
diff --git a/tests/lib/activitymanager.php b/tests/lib/activitymanager.php
index d227c05d827..51ab4a7a947 100644
--- a/tests/lib/activitymanager.php
+++ b/tests/lib/activitymanager.php
@@ -13,10 +13,34 @@ class Test_ActivityManager extends \Test\TestCase {
/** @var \OC\ActivityManager */
private $activityManager;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $request;
+
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $session;
+
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+
protected function setUp() {
parent::setUp();
- $this->activityManager = new \OC\ActivityManager();
+ $this->request = $this->getMockBuilder('OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->session = $this->getMockBuilder('OCP\IUserSession')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->config = $this->getMockBuilder('OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->activityManager = new \OC\ActivityManager(
+ $this->request,
+ $this->session,
+ $this->config
+ );
+
$this->activityManager->registerExtension(function() {
return new NoOpExtension();
});
@@ -111,6 +135,90 @@ class Test_ActivityManager extends \Test\TestCase {
$result = $this->activityManager->getQueryForFilter('InvalidFilter');
$this->assertEquals(array(null, null), $result);
}
+
+ 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->activityManager, 'getUserFromToken');
+ }
+
+ public function getUserFromTokenData() {
+ return [
+ [null, '123456789012345678901234567890', 'user1'],
+ ['user2', null, 'user2'],
+ ['user2', '123456789012345678901234567890', 'user2'],
+ ];
+ }
+
+ /**
+ * @dataProvider getUserFromTokenData
+ *
+ * @param string $userLoggedIn
+ * @param string $token
+ * @param string $expected
+ */
+ public function testGetUserFromToken($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, $this->activityManager->getCurrentUserId());
+ }
+
+ protected function mockUserSession($user) {
+ $mockUser = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mockUser->expects($this->any())
+ ->method('getUID')
+ ->willReturn($user);
+
+ $this->session->expects($this->any())
+ ->method('isLoggedIn')
+ ->willReturn(true);
+ $this->session->expects($this->any())
+ ->method('getUser')
+ ->willReturn($mockUser);
+ }
}
class SimpleExtension implements \OCP\Activity\IExtension {