37 private $assertCountBefore;
39 protected function setUp()
42 $this->
dbManager = $this->testDb->getDbManager();
43 $this->logger =
new Logger(
"test");
45 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
48 protected function tearDown()
50 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
55 public function testGetUserGroupMap()
57 $this->testDb->createPlainTables(array(
'groups',
'group_user_member'));
58 $this->testDb->insertData(array(
'groups',
'group_user_member'));
60 $defaultGroups = $this->userDao->getUserGroupMap($userId=1);
61 assertThat($defaultGroups, equalTo(array(1=>
'Default User')));
64 public function testGetAdminGroupMap()
66 $this->testDb->createPlainTables(array(
'groups',
'group_user_member'));
67 $this->testDb->insertData(array(
'groups',
'group_user_member'));
68 defined(
'PLUGIN_DB_ADMIN') or define(
'PLUGIN_DB_ADMIN',10);
70 $defaultGroups = $this->userDao->getAdminGroupMap($userId=2,$userLevel=
PLUGIN_DB_ADMIN);
71 assertThat($defaultGroups, equalTo(array(1=>
'Default User',2=>
'fossy')));
75 public function testGetDeletableAdminGroupMap()
77 $this->testDb->createPlainTables(array(
'groups',
'group_user_member',
'users'));
80 $this->
dbManager->insertTableRow(
'users',array(
'user_pk'=>$userId,
'user_name'=>$username));
81 $this->
dbManager->insertTableRow(
'groups', array(
'group_pk'=>201,
'group_name'=>$username));
82 $this->
dbManager->insertTableRow(
'group_user_member', array(
'group_fk'=>201,
'user_fk'=>$userId));
83 $deletable = array(
'group_pk'=>202,
'group_name'=>
'anyName');
84 $this->
dbManager->insertTableRow(
'groups', $deletable);
85 $this->
dbManager->insertTableRow(
'group_user_member', array(
'group_fk'=>202,
'user_fk'=>$userId,
'group_perm'=>1));
87 $groupsAsAdmin = $this->userDao->getDeletableAdminGroupMap($userId,$userLevel=
PLUGIN_DB_ADMIN);
88 assertThat($groupsAsAdmin, equalTo(array($deletable[
'group_pk']=>$deletable[
'group_name'])));
90 $groups = $this->userDao->getDeletableAdminGroupMap($userId);
91 assertThat($groups, equalTo(array($deletable[
'group_pk']=>$deletable[
'group_name'])));
93 $groupsAsForeign = $this->userDao->getDeletableAdminGroupMap($userId+1);
94 assertThat($groupsAsForeign, equalTo(array()));
97 public function testAddGroup()
99 $this->
dbManager->queryOnce(
'CREATE TABLE groups (group_pk integer NOT NULL PRIMARY KEY, group_name varchar(64))');
100 $this->testDb->insertData(array(
'groups'));
101 $groupId = $this->userDao->addGroup($groupName=
'newGroup');
102 $row = $this->
dbManager->getSingleRow(
'SELECT group_name FROM groups WHERE group_pk=$1',array($groupId));
103 assertThat($row[
'group_name'], equalTo($groupName));
111 $this->testDb->createPlainTables(array(
'groups',
'users'));
112 $this->testDb->insertData(array(
'groups',
'user'));
113 $this->userDao->addGroup(
'fossy');
121 $this->testDb->createPlainTables(array(
'groups',
'users'));
122 $this->testDb->insertData(array(
'groups',
'user'));
123 $this->userDao->addGroup(
'');
126 public function testGetUserName()
130 $this->testDb->createPlainTables(array(
'users'));
131 $this->
dbManager->insertTableRow(
'users',array(
'user_pk'=>$userId,
'user_name'=>$username));
132 $uName = $this->userDao->getUserName($userId);
133 assertThat($uName,equalTo($username));
142 $this->testDb->createPlainTables(array(
'users'));
143 $this->userDao->getUserName(101);
146 public function testGetGroupIdByName()
148 $this->testDb->createPlainTables(array(
'groups'));
149 $this->testDb->insertData(array(
'groups'));
150 $groupId = $this->userDao->getGroupIdByName(
'fossy');
151 assertThat($groupId,equalTo(2));
154 public function testAddGroupMembership()
156 $this->testDb->createPlainTables(array(
'users',
'groups',
'group_user_member'));
157 $this->testDb->insertData(array(
'users',
'groups',
'group_user_member'));
158 $this->userDao->addGroupMembership($groupId=2,$userId=1);
159 $map = $this->userDao->getUserGroupMap($userId);
160 assertThat($map,hasKey($groupId));
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
fo_dbManager * dbManager
fo_dbManager object
testAddGroupFailEmptyName()
testAddGroupFailIfAlreadyExists()