summaryrefslogtreecommitdiffstats
path: root/tests/settings
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-06-11 17:57:00 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-06-16 11:10:00 +0200
commit171f86ca2e71918809930e823062d93c03833921 (patch)
treef605b2fa0d94a78c44d9781c595331f1e8a34b52 /tests/settings
parentfee62ac61c1cecb37e283fc6f9faf0251389226f (diff)
downloadnextcloud-server-171f86ca2e71918809930e823062d93c03833921.tar.gz
nextcloud-server-171f86ca2e71918809930e823062d93c03833921.zip
Only sort by group name when LDAP is involved
Diffstat (limited to 'tests/settings')
-rw-r--r--tests/settings/controller/groupscontrollertest.php96
1 files changed, 95 insertions, 1 deletions
diff --git a/tests/settings/controller/groupscontrollertest.php b/tests/settings/controller/groupscontrollertest.php
index 3c15754846c..82b4c7d3c05 100644
--- a/tests/settings/controller/groupscontrollertest.php
+++ b/tests/settings/controller/groupscontrollertest.php
@@ -10,6 +10,7 @@
namespace OC\Settings\Controller;
use OC\Group\Group;
+use OC\Group\MetaData;
use \OC\Settings\Application;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@@ -50,7 +51,7 @@ class GroupsControllerTest extends \Test\TestCase {
* TODO: Since GroupManager uses the static OC_Subadmin class it can't be mocked
* to test for subadmins. Thus the test always assumes you have admin permissions...
*/
- public function testIndex() {
+ public function testIndexSortByName() {
$firstGroup = $this->getMockBuilder('\OC\Group\Group')
->disableOriginalConstructor()->getMock();
$firstGroup
@@ -135,6 +136,99 @@ class GroupsControllerTest extends \Test\TestCase {
)
)
);
+ $response = $this->groupsController->index('', false, MetaData::SORT_GROUPNAME);
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ /**
+ * TODO: Since GroupManager uses the static OC_Subadmin class it can't be mocked
+ * to test for subadmins. Thus the test always assumes you have admin permissions...
+ */
+ public function testIndexSortbyCount() {
+ $firstGroup = $this->getMockBuilder('\OC\Group\Group')
+ ->disableOriginalConstructor()->getMock();
+ $firstGroup
+ ->method('getGID')
+ ->will($this->returnValue('firstGroup'));
+ $firstGroup
+ ->method('count')
+ ->will($this->returnValue(12));
+ $secondGroup = $this->getMockBuilder('\OC\Group\Group')
+ ->disableOriginalConstructor()->getMock();
+ $secondGroup
+ ->method('getGID')
+ ->will($this->returnValue('secondGroup'));
+ $secondGroup
+ ->method('count')
+ ->will($this->returnValue(25));
+ $thirdGroup = $this->getMockBuilder('\OC\Group\Group')
+ ->disableOriginalConstructor()->getMock();
+ $thirdGroup
+ ->method('getGID')
+ ->will($this->returnValue('thirdGroup'));
+ $thirdGroup
+ ->method('count')
+ ->will($this->returnValue(14));
+ $fourthGroup = $this->getMockBuilder('\OC\Group\Group')
+ ->disableOriginalConstructor()->getMock();
+ $fourthGroup
+ ->method('getGID')
+ ->will($this->returnValue('admin'));
+ $fourthGroup
+ ->method('count')
+ ->will($this->returnValue(18));
+ /** @var \OC\Group\Group[] $groups */
+ $groups = array();
+ $groups[] = $firstGroup;
+ $groups[] = $secondGroup;
+ $groups[] = $thirdGroup;
+ $groups[] = $fourthGroup;
+
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $this->container['UserSession']
+ ->expects($this->once())
+ ->method('getUser')
+ ->will($this->returnValue($user));
+ $user
+ ->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('MyAdminUser'));
+ $this->container['GroupManager']
+ ->method('search')
+ ->will($this->returnValue($groups));
+
+ $expectedResponse = new DataResponse(
+ array(
+ 'data' => array(
+ 'adminGroups' => array(
+ 0 => array(
+ 'id' => 'admin',
+ 'name' => 'admin',
+ 'usercount' => 18,
+ )
+ ),
+ 'groups' =>
+ array(
+ 0 => array(
+ 'id' => 'secondGroup',
+ 'name' => 'secondGroup',
+ 'usercount' => 25,
+ ),
+ 1 => array(
+ 'id' => 'thirdGroup',
+ 'name' => 'thirdGroup',
+ 'usercount' => 14,
+ ),
+ 2 => array(
+ 'id' => 'firstGroup',
+ 'name' => 'firstGroup',
+ 'usercount' => 12,
+ ),
+ )
+ )
+ )
+ );
$response = $this->groupsController->index();
$this->assertEquals($expectedResponse, $response);
}