26 require_once __DIR__.
'/../../Plugin/FO_Plugin.php';
35 private $uploadPermissionDao;
37 protected function setUp()
40 $this->
dbManager = &$this->testDb->getDbManager();
42 $this->testDb->createPlainTables(array(
'upload',
'uploadtree'));
44 $this->
dbManager->prepare($stmt =
'insert.upload',
45 "INSERT INTO upload (upload_pk, uploadtree_tablename) VALUES ($1, $2)");
46 $uploadArray = array(array(1,
'uploadtree'), array(2,
'uploadtree_a'));
47 foreach ($uploadArray as $uploadEntry) {
50 $logger = M::mock(
'Monolog\Logger');
51 $logger->shouldReceive(
'debug');
54 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
57 protected function tearDown()
59 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
64 public function testmakeAccessibleToGroup()
66 $this->testDb->createPlainTables(array(
'perm_upload',
'group_user_member'));
69 $groupIdAlternative = 602;
70 $this->
dbManager->insertTableRow(
'group_user_member', array(
'group_fk'=>$groupId,
'user_fk'=>$userId,
'group_perm'=>
Auth::PERM_READ));
71 $this->
dbManager->insertTableRow(
'group_user_member', array(
'group_fk'=>$groupIdAlternative,
'user_fk'=>$userId,
'group_perm'=>
Auth::PERM_READ));
73 $unaccessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId=1, $groupId);
74 assertThat($unaccessibleIsAccessible,equalTo(
false));
76 $this->uploadPermissionDao->makeAccessibleToGroup($uploadId, $groupId,
Auth::PERM_WRITE);
77 $accessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
78 assertThat($accessibleIsAccessible,equalTo(
true));
79 $stillUnaccessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId, $groupIdAlternative);
80 assertThat($stillUnaccessibleIsAccessible,equalTo(
false));
82 $this->uploadPermissionDao->makeAccessibleToAllGroupsOf($uploadId, $userId);
83 $nowAccessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId, $groupIdAlternative);
84 assertThat($nowAccessibleIsAccessible,equalTo(
true));
87 public function testDeletePermissionId()
89 $this->testDb->createPlainTables(array(
'perm_upload'));
90 $this->testDb->insertData(array(
'perm_upload'));
91 $accessibleBefore = $this->uploadPermissionDao->isAccessible($uploadId=1, $groupId=2);
92 assertThat($accessibleBefore,equalTo(
true));
93 $this->uploadPermissionDao->updatePermissionId(1,0);
94 $accessibleAfter = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
95 assertThat($accessibleAfter,equalTo(
false));
98 public function testUpdatePermissionId()
100 $this->testDb->createPlainTables(array(
'perm_upload'));
101 $this->testDb->insertData(array(
'perm_upload'));
103 $adminBefore = $this->uploadPermissionDao->isEditable($uploadId=1, $groupId=2);
104 assertThat($adminBefore,equalTo(
true));
106 $adminNomore = $this->uploadPermissionDao->isEditable($uploadId, $groupId);
107 assertThat($adminNomore,equalTo(
false));
109 $adminAgain = $this->uploadPermissionDao->isEditable($uploadId, $groupId);
110 assertThat($adminAgain,equalTo(
true));
113 public function testInsertPermission()
115 $this->testDb->createPlainTables(array(
'perm_upload'));
116 $accessibleBefore = $this->uploadPermissionDao->isAccessible($uploadId=1, $groupId=2);
117 assertThat($accessibleBefore,equalTo(
false));
118 $this->uploadPermissionDao->insertPermission($uploadId, $groupId,
Auth::PERM_READ);
119 $accessibleAfter = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
120 assertThat($accessibleAfter,equalTo(
true));
121 $this->uploadPermissionDao->insertPermission($uploadId, $groupId,
Auth::PERM_NONE);
122 $accessibleNomore = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
123 assertThat($accessibleNomore,equalTo(
false));
126 public function testGetPublicPermission()
128 $this->testDb->insertData(array(
'upload'));
129 $perm = $this->uploadPermissionDao->getPublicPermission(3);
130 assertThat($perm,equalTo(0));
133 public function testGetPermissionGroups()
135 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
136 $this->testDb->insertData(array(
'perm_upload',
'groups'));
137 $permissionGroups = $this->uploadPermissionDao->getPermissionGroups(1);
138 assertThat($permissionGroups,is(array(2=>array(
'perm_upload_pk'=>1,
'perm'=>10,
'group_pk'=>2,
'group_name'=>
'fossy'))));
141 public function testAccessibilityViaNone()
143 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
144 $this->testDb->insertData(array(
'groups'));
146 $accessibilityWithBadGroup = $this->uploadPermissionDao->isAccessible($uploadId=2, $groupId=2);
147 assertThat($accessibilityWithBadGroup, equalTo(
false));
150 public function testAccessibilityViaGroup()
152 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
153 $this->testDb->insertData(array(
'groups',
'perm_upload'));
155 $accessibilityByGroup = $this->uploadPermissionDao->isAccessible($uploadId=2, $groupId=2);
156 assertThat($accessibilityByGroup, equalTo(
true));
160 public function testAccessibilityViaPublicForUnqualifiedUser()
162 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
163 $this->testDb->insertData(array(
'groups'));
165 $accessibilityByNone = $this->uploadPermissionDao->isAccessible($uploadId=2, $groupId=2);
166 assertThat($accessibilityByNone, equalTo(
false));
168 $this->uploadPermissionDao->setPublicPermission($uploadId,
Auth::PERM_READ);
169 $accessibilityByPublic = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
170 assertThat($accessibilityByPublic, equalTo(
false));
173 public function testAccessibilityViaPublicForQualifiedUser()
175 $this->testDb->createPlainTables(array(
'perm_upload',
'groups'));
176 $this->testDb->insertData(array(
'groups'));
178 $accessibilityByNone = $this->uploadPermissionDao->isAccessible($uploadId=2, $groupId=2);
179 assertThat($accessibilityByNone, equalTo(
false));
181 $this->uploadPermissionDao->setPublicPermission($uploadId,
Auth::PERM_READ);
182 $accessibilityByPublic = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
183 assertThat($accessibilityByPublic, equalTo(
true));
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
fo_dbManager * dbManager
fo_dbManager object