Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Apr 21, 2018
1 parent b2836bd commit c7aabd2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
6 changes: 6 additions & 0 deletions settings/Controller/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;

/**
Expand All @@ -40,6 +41,8 @@
class GroupsController extends Controller {
/** @var IGroupManager */
private $groupManager;
/** @var IUserManager */
private $userManager;
/** @var IL10N */
private $l10n;
/** @var IUserSession */
Expand All @@ -58,11 +61,13 @@ class GroupsController extends Controller {
public function __construct($appName,
IRequest $request,
IGroupManager $groupManager,
IUserManager $userManager,
IUserSession $userSession,
$isAdmin,
IL10N $l10n) {
parent::__construct($appName, $request);
$this->groupManager = $groupManager;
$this->userManager = $userManager;
$this->userSession = $userSession;
$this->isAdmin = $isAdmin;
$this->l10n = $l10n;
Expand All @@ -83,6 +88,7 @@ public function index($pattern = '', $filterGroups = false, $sortGroups = MetaDa
$this->userSession->getUser()->getUID(),
$this->isAdmin,
$this->groupManager,
$this->userManager,
$this->userSession
);
$groupsInfo->setSorting($sortGroups);
Expand Down
36 changes: 32 additions & 4 deletions tests/Settings/Controller/GroupsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;

/**
Expand All @@ -29,6 +30,9 @@ class GroupsControllerTest extends \Test\TestCase {
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
private $groupManager;

/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;

/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
private $userSession;

Expand All @@ -39,6 +43,7 @@ protected function setUp() {
parent::setUp();

$this->groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->userSession = $this->createMock(IUserSession::class);
$l = $this->createMock(IL10N::class);
$l->method('t')
Expand All @@ -49,6 +54,7 @@ protected function setUp() {
'settings',
$this->createMock(IRequest::class),
$this->groupManager,
$this->userManager,
$this->userSession,
true,
$l
Expand Down Expand Up @@ -112,8 +118,15 @@ public function testIndexSortByName() {
$groups[] = $thirdGroup;
$groups[] = $fourthGroup;

// Get disabled count
$this->userManager->expects($this->exactly(4))
->method('countDisabledUsersOfGroups')
->will($this->returnValue(0));

$user = $this->getMockBuilder(User::class)
->disableOriginalConstructor()->getMock();

// Get connected user
$this->userSession
->expects($this->once())
->method('getUser')
Expand All @@ -132,25 +145,29 @@ public function testIndexSortByName() {
0 => array(
'id' => 'admin',
'name' => 'Admin',
'usercount' => 0,//User count disabled 18,
'usercount' => 0, // User count disabled, should be 18,
'disabled' => 0
)
),
'groups' =>
array(
0 => array(
'id' => 'firstGroup',
'name' => 'First group',
'usercount' => 0,//User count disabled 12,
'usercount' => 0, // User count disabled, should be 12,
'disabled' => 0
),
1 => array(
'id' => 'secondGroup',
'name' => 'Second group',
'usercount' => 0,//User count disabled 25,
'usercount' => 0, // User count disabled, should be 25,
'disabled' => 0
),
2 => array(
'id' => 'thirdGroup',
'name' => 'Third group',
'usercount' => 0,//User count disabled 14,
'usercount' => 0, // User count disabled, should be 14,
'disabled' => 0
),
)
)
Expand Down Expand Up @@ -216,8 +233,15 @@ public function testIndexSortbyCount() {
$groups[] = $thirdGroup;
$groups[] = $fourthGroup;

// Get disabled count
$this->userManager->expects($this->exactly(4))
->method('countDisabledUsersOfGroups')
->will($this->returnValue(0));

$user = $this->getMockBuilder(User::class)
->disableOriginalConstructor()->getMock();

// Get connected user
$this->userSession
->expects($this->once())
->method('getUser')
Expand All @@ -238,6 +262,7 @@ public function testIndexSortbyCount() {
'id' => 'admin',
'name' => 'Admin',
'usercount' => 18,
'disabled' => 0
)
),
'groups' =>
Expand All @@ -246,16 +271,19 @@ public function testIndexSortbyCount() {
'id' => 'secondGroup',
'name' => 'Second group',
'usercount' => 25,
'disabled' => 0
),
1 => array(
'id' => 'thirdGroup',
'name' => 'Third group',
'usercount' => 14,
'disabled' => 0
),
2 => array(
'id' => 'firstGroup',
'name' => 'First group',
'usercount' => 12,
'disabled' => 0
),
)
)
Expand Down

0 comments on commit c7aabd2

Please sign in to comment.