Skip to content

Commit

Permalink
Merge pull request #278 from owncloud/coding-standard-2.0.0
Browse files Browse the repository at this point in the history
Coding standard 2.0.0
  • Loading branch information
phil-davis authored Dec 16, 2019
2 parents b3a8552 + 542a429 commit f2abaca
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .drone.starlark
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ def setupCeph(serviceParams):

createFirstBucket = serviceParams['createFirstBucket'] if 'createFirstBucket' in serviceParams else True
setupCommands = serviceParams['setupCommands'] if 'setupCommands' in serviceParams else [
'wait-for-it -t 120 ceph:80',
'wait-for-it -t 600 ceph:80',
'cd /var/www/owncloud/server/apps/files_primary_s3',
'cp tests/drone/ceph.config.php /var/www/owncloud/server/config',
'cd /var/www/owncloud/server',
Expand Down Expand Up @@ -1298,7 +1298,7 @@ def setupScality(serviceParams):
createFirstBucket = serviceParams['createFirstBucket'] if 'createFirstBucket' in serviceParams else True
createExtraBuckets = serviceParams['createExtraBuckets'] if 'createExtraBuckets' in serviceParams else False
setupCommands = serviceParams['setupCommands'] if 'setupCommands' in serviceParams else [
'wait-for-it -t 120 scality:8000',
'wait-for-it -t 600 scality:8000',
'cd /var/www/owncloud/server/apps/files_primary_s3',
'cp tests/drone/%s /var/www/owncloud/server/config' % configFile,
'cd /var/www/owncloud/server'
Expand Down
42 changes: 28 additions & 14 deletions tests/unit/Dav/GroupMembershipCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ public function testDeleteAsAdmin() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDeleteAsNonAdmin() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->setCurrentUserMemberInfo(['group_id' => 1, 'user_id' => self::CURRENT_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_MEMBER]);
$this->config->method('getSystemValue')
->willReturn(true);
Expand All @@ -209,9 +210,10 @@ public function testDeleteAsNonAdmin() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDeleteAsNonMember() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->setCurrentUserMemberInfo(null);
$this->config->method('getSystemValue')
->willReturn(true);
Expand Down Expand Up @@ -380,10 +382,11 @@ public function testAddMemberAsAdmin($isSuperAdmin, $currentMemberInfo) {
}

/**
* @expectedException \Sabre\DAV\Exception\PreconditionFailed
* @dataProvider adminProvider
*/
public function testAddMemberAsAdminFails($isSuperAdmin, $currentMemberInfo) {
$this->expectException(\Sabre\DAV\Exception\PreconditionFailed::class);

$this->setCurrentUserMemberInfo($currentMemberInfo);
$this->setCurrentUserSuperAdmin($isSuperAdmin);

Expand All @@ -401,10 +404,11 @@ public function testAddMemberAsAdminFails($isSuperAdmin, $currentMemberInfo) {
}

/**
* @expectedException \Sabre\DAV\Exception\PreconditionFailed
* @dataProvider adminProvider
*/
public function testAddNonExistingMemberAsAdmin($isSuperAdmin, $currentMemberInfo) {
$this->expectException(\Sabre\DAV\Exception\PreconditionFailed::class);

$this->setCurrentUserMemberInfo($currentMemberInfo);
$this->setCurrentUserSuperAdmin($isSuperAdmin);

Expand All @@ -420,10 +424,11 @@ public function testAddNonExistingMemberAsAdmin($isSuperAdmin, $currentMemberInf
}

/**
* @expectedException \Sabre\DAV\Exception\PreconditionFailed
* @dataProvider adminProvider
*/
public function testAddNonExistingMemberMismatchCaseAsAdmin($isSuperAdmin, $currentMemberInfo) {
$this->expectException(\Sabre\DAV\Exception\PreconditionFailed::class);

$this->setCurrentUserMemberInfo($currentMemberInfo);
$this->setCurrentUserSuperAdmin($isSuperAdmin);

Expand All @@ -439,9 +444,10 @@ public function testAddNonExistingMemberMismatchCaseAsAdmin($isSuperAdmin, $curr
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testAddMemberAsNonAdmin() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->setCurrentUserMemberInfo(['group_id' => 1, 'user_id' => self::CURRENT_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_MEMBER]);

$this->config->method('getSystemValue')
Expand All @@ -456,9 +462,10 @@ public function testAddMemberAsNonAdmin() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testAddMemberAsNonMember() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->setCurrentUserMemberInfo(null);

$this->config->method('getSystemValue')
Expand All @@ -473,9 +480,10 @@ public function testAddMemberAsNonMember() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testAddMemberWithShareToMemberRestrictionAndNoCommonGroup() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->setCurrentUserMemberInfo(['group_id' => 1, 'user_id' => self::CURRENT_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_ADMIN]);
$this->config->method('getSystemValue')
->willReturn(true);
Expand Down Expand Up @@ -537,9 +545,10 @@ public function testIsMember() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testIsMemberAsNonMember() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->setCurrentUserMemberInfo(null);
$this->config->method('getSystemValue')
->willReturn(true);
Expand Down Expand Up @@ -598,9 +607,10 @@ public function testGetMember($isSuperAdmin, $currentMemberInfo) {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testGetMemberAsNonMember() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->setCurrentUserMemberInfo(null);
$this->config->method('getSystemValue')
->willReturn(true);
Expand Down Expand Up @@ -671,9 +681,10 @@ public function testSearchMembers($isSuperAdmin, $currentMemberInfo) {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testGetMembersAsNonMember() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->setCurrentUserMemberInfo(null);
$this->config->method('getSystemValue')
->willReturn(true);
Expand All @@ -684,16 +695,18 @@ public function testGetMembersAsNonMember() {
}

/**
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
*/
public function testSetName() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);

$this->node->setName('x');
}

/**
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
*/
public function testCreateDirectory() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);

$this->node->createDirectory('somedir');
}

Expand All @@ -711,9 +724,10 @@ public function providesUpdateDisplayNameValidateException() {
/**
* @dataProvider providesUpdateDisplayNameValidateException
* @param string $groupName
* @expectedException \OCA\CustomGroups\Exception\ValidationException
*/
public function testUpdateDisplayNameValidatException($groupName) {
$this->expectException(\OCA\CustomGroups\Exception\ValidationException::class);

$this->node->updateDisplayName($groupName);
}
}
24 changes: 16 additions & 8 deletions tests/unit/Dav/GroupsCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ public function testCreateGroup() {
}

/**
* @expectedException \Sabre\DAV\Exception\Conflict
*/
public function testCreateGroupNoDuplicates() {
$this->expectException(\Sabre\DAV\Exception\Conflict::class);

$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user1');
$this->userSession->method('getUser')->willReturn($user);
Expand Down Expand Up @@ -287,9 +288,10 @@ public function providesTestCreateException() {

/**
* @dataProvider providesTestCreateException
* @expectedException \OCA\CustomGroups\Exception\ValidationException
*/
public function testCreateGroupExceptions($groupName, $displayName) {
$this->expectException(\OCA\CustomGroups\Exception\ValidationException::class);

$mkCol = new MkCol([], [
GroupMembershipCollection::PROPERTY_DISPLAY_NAME => $displayName
]);
Expand All @@ -314,9 +316,10 @@ public function testCreateGroupExceptionsStatusCode($groupName, $displayName) {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testCreateGroupNoPermission() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$helper = $this->createMock(MembershipHelper::class);
$helper->expects($this->once())
->method('canCreateGroups')
Expand All @@ -338,9 +341,10 @@ public function testCreateGroupNoPermission() {
}

/**
* @expectedException \Sabre\DAV\Exception\MethodNotAllowed
*/
public function testCreateGroupAlreadyExists() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);

$this->handler->expects($this->once())
->method('createGroup')
->with('group1', 'group1')
Expand All @@ -364,9 +368,10 @@ public function testGetGroup() {
}

/**
* @expectedException \Sabre\DAV\Exception\NotFound
*/
public function testGetGroupNonExisting() {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);

$this->handler->expects($this->any())
->method('getGroupByUri')
->with('groupx')
Expand All @@ -388,23 +393,26 @@ public function testGroupExists() {
}

/**
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
*/
public function testSetName() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);

$this->collection->setName('x');
}

/**
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
*/
public function testDelete() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);

$this->collection->delete();
}

/**
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
*/
public function testCreateFile() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);

$this->collection->createFile('somefile.txt');
}
}
18 changes: 12 additions & 6 deletions tests/unit/Dav/MembershipNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ public function testDeleteAsAdmin() {
}

/**
* @expectedException \Sabre\DAV\Exception\PreconditionFailed
*/
public function testDeleteAsAdminFailed() {
$this->expectException(\Sabre\DAV\Exception\PreconditionFailed::class);

$memberInfo = ['group_id' => 1, 'user_id' => self::CURRENT_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_ADMIN];
$this->config->method('getSystemValue')
->willReturn(true);
Expand All @@ -229,9 +230,10 @@ public function testDeleteAsAdminFailed() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDeleteAsNonAdmin() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->setCurrentUserMemberInfo(['group_id' => 1, 'user_id' => self::CURRENT_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_MEMBER]);
$this->config->method('getSystemValue')
->willReturn(true);
Expand Down Expand Up @@ -334,9 +336,10 @@ public function testDeleteSelfAsNonAdmin() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDeleteAsNonMember() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->config->method('getSystemValue')
->willReturn(true);
$this->groupManager->method('isAdmin')
Expand Down Expand Up @@ -377,9 +380,10 @@ public function testDeleteAsSuperAdmin() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDeleteSelfAsLastAdmin() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->config->method('getSystemValue')
->willReturn(true);
$this->groupManager->method('isAdmin')
Expand All @@ -403,9 +407,10 @@ public function testDeleteSelfAsLastAdmin() {
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDeleteLastAdminAsSuperAdmin() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

$this->config->method('getSystemValue')
->willReturn(true);
$this->groupManager->method('isAdmin')
Expand Down Expand Up @@ -611,9 +616,10 @@ public function testUnsetdminWhenLastAdminAsSuperAdmin() {
}

/**
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
*/
public function testSetName() {
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);

$this->node->setName('x');
}
}
3 changes: 2 additions & 1 deletion tests/unit/Dav/RootCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public function testGetUsers() {
}

/**
* @expectedException Sabre\DAV\Exception\NotFound
*/
public function testGetNonExisting() {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);

$this->collection->getChild('somethingelse');
}
}
Loading

0 comments on commit f2abaca

Please sign in to comment.