Skip to content

Commit

Permalink
Fix constructors in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed Mar 25, 2015
1 parent 0403ea5 commit 2ba0bdb
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 80 deletions.
6 changes: 5 additions & 1 deletion tests/apitest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down
6 changes: 5 additions & 1 deletion tests/consumertest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
83 changes: 13 additions & 70 deletions tests/controller/feedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
Expand All @@ -75,7 +81,7 @@ protected function setUp() {
$this->helper,
$this->userSettings,
$this->getMockBuilder('OCP\IURLGenerator')->disableOriginalConstructor()->getMock(),
$this->session,
$this->manager,
$this->config,
'test'
);
Expand Down Expand Up @@ -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')
Expand All @@ -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()
Expand All @@ -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);
}
}
12 changes: 10 additions & 2 deletions tests/datahelpertest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion tests/datatest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down
6 changes: 5 additions & 1 deletion tests/grouphelpertest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down
16 changes: 14 additions & 2 deletions tests/navigationtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tests/parameterhelpertest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down
6 changes: 5 additions & 1 deletion tests/usersettingstest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down

0 comments on commit 2ba0bdb

Please sign in to comment.