Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Merge branch '8.x-1.x' into hotfix/remove-unused-variables-#545
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrenssen authored Jan 29, 2020
2 parents 1e77f29 + 488b701 commit eaf0088
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 46 deletions.
2 changes: 0 additions & 2 deletions phpcs-ruleset.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
<rule ref="./vendor/drupal/coder/coder_sniffer/DrupalPractice">
<!-- https://github.com/Gizra/og/issues/549 -->
<exclude name="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable" />
<!-- https://github.com/Gizra/og/issues/548 -->
<exclude name="DrupalPractice.Commenting.ExpectedException.TagFound" />
<!-- https://github.com/Gizra/og/issues/550 -->
<exclude name="DrupalPractice.Constants.GlobalDefine.GlobalConstant" />
<!-- https://github.com/Gizra/og/issues/544 -->
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Kernel/Access/AccessByOgMembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\Tests\og\Kernel\Access;

use Drupal\Core\Entity\EntityStorageException;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\og\Traits\OgMembershipCreationTrait;
Expand Down Expand Up @@ -182,8 +183,6 @@ public function testEntityOperationAccess($user, array $expected_results) {

/**
* Tests exception is thrown when trying to save non-member role.
*
* @expectedException \Drupal\Core\Entity\EntityStorageException
*/
public function testNonMemberRoleMembershipSave() {
/** @var \Drupal\og\Entity\OgRole $role */
Expand All @@ -194,6 +193,7 @@ public function testNonMemberRoleMembershipSave() {
->save();

$membership = OgMembership::create();
$this->expectException(EntityStorageException::class);
$membership
->setOwner($this->users['non-member'])
->setGroup($this->group)
Expand Down
32 changes: 19 additions & 13 deletions tests/src/Kernel/Entity/OgMembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\Tests\og\Kernel\Entity;

use Drupal\Core\Entity\EntityStorageException;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\KernelTests\KernelTestBase;
Expand Down Expand Up @@ -138,25 +139,25 @@ public function testGetSetOwner() {
* Tests getting the owner of a newly created membership.
*
* @covers ::getOwner
* @expectedException \LogicException
*/
public function testGetOwnerOnNewMembership() {
// A brand new entity does not have an owner set yet. It should throw a
// logic exception.
$membership = OgMembership::create();
$this->expectException(\LogicException::class);
$membership->getOwner();
}

/**
* Tests getting the owner ID of a newly created membership.
*
* @covers ::getOwnerId
* @expectedException \LogicException
*/
public function testGetOwnerIdOnNewMembership() {
// A brand new entity does not have an owner set yet. It should throw a
// logic exception.
$membership = OgMembership::create();
$this->expectException(\LogicException::class);
$membership->getOwnerId();
}

Expand Down Expand Up @@ -225,11 +226,11 @@ public function testMembershipStaticCache() {
* Tests exceptions are thrown when trying to save a membership with no user.
*
* @covers ::preSave
* @expectedException \Drupal\Core\Entity\EntityStorageException
*/
public function testSetNoUserException() {
/** @var \Drupal\og\OgMembershipInterface $membership */
$membership = OgMembership::create(['type' => OgMembershipInterface::TYPE_DEFAULT]);
$this->expectException(EntityStorageException::class);
$membership
->setGroup($this->group)
->save();
Expand All @@ -239,11 +240,11 @@ public function testSetNoUserException() {
* Tests exceptions are thrown when trying to save a membership with no group.
*
* @covers ::preSave
* @expectedException \Drupal\Core\Entity\EntityStorageException
*/
public function testSetNoGroupException() {
/** @var \Drupal\og\OgMembershipInterface $membership */
$membership = OgMembership::create();
$this->expectException(EntityStorageException::class);
$membership
->setOwner($this->user)
->save();
Expand Down Expand Up @@ -277,7 +278,6 @@ public function testNoOwnerException() {
* Tests saving a membership with a non group entity.
*
* @covers ::preSave
* @expectedException \Drupal\Core\Entity\EntityStorageException
*/
public function testSetNonValidGroupException() {
$non_group = EntityTest::create([
Expand All @@ -288,14 +288,15 @@ public function testSetNonValidGroupException() {
$non_group->save();
/** @var \Drupal\og\OgMembershipInterface $membership */
$membership = Og::createMembership($non_group, $this->user);

$this->expectException(EntityStorageException::class);
$membership->save();
}

/**
* Tests saving an existing membership.
*
* @covers ::preSave
* @expectedException \Drupal\Core\Entity\EntityStorageException
*/
public function testSaveExistingMembership() {
$group = EntityTest::create([
Expand All @@ -312,14 +313,15 @@ public function testSaveExistingMembership() {
$membership1->save();

$membership2 = Og::createMembership($group, $this->user);

$this->expectException(EntityStorageException::class);
$membership2->save();
}

/**
* Tests saving a membership with a role with a different group type.
*
* @covers ::preSave
* @expectedException \Drupal\Core\Entity\EntityStorageException
* @dataProvider saveRoleWithWrongGroupTypeProvider
*/
public function testSaveRoleWithWrongGroupType($group_entity_type_id, $group_bundle_id) {
Expand All @@ -338,6 +340,7 @@ public function testSaveRoleWithWrongGroupType($group_entity_type_id, $group_bun
->setName(mb_strtolower($this->randomMachineName()));
$wrong_role->save();

$this->expectException(EntityStorageException::class);
Og::createMembership($group, $this->user)->addRole($wrong_role)->save();
}

Expand Down Expand Up @@ -438,7 +441,6 @@ public function isRoleValidProvider() {
* An array of test role metadata.
*
* @covers ::save
* @expectedException \Drupal\Core\Entity\EntityStorageException
* @dataProvider saveMembershipWithInvalidRolesProvider
*/
public function testSaveMembershipWithInvalidRoles(array $roles_metadata): void {
Expand Down Expand Up @@ -486,6 +488,7 @@ public function testSaveMembershipWithInvalidRoles(array $roles_metadata): void

// Create a membership with the test group and roles. This should throw an
// exception since the roles are invalid.
$this->expectException(EntityStorageException::class);
OgMembership::create()
->setOwner($this->user)
->setGroup($this->group)
Expand Down Expand Up @@ -567,7 +570,6 @@ public function saveMembershipWithInvalidRolesProvider(): array {
* Tests the exception thrown if the validity of a role cannot be established.
*
* @covers ::isRoleValid
* @expectedException \LogicException
*/
public function testIsRoleValidException() {
$role = OgRole::create([
Expand All @@ -578,6 +580,7 @@ public function testIsRoleValidException() {

// If a membership doesn't have a group yet it is not possible to determine
// wheter a role is valid.
$this->expectException(\LogicException::class);
$membership->isRoleValid($role);
}

Expand Down Expand Up @@ -643,12 +646,12 @@ public function testGetGroup() {
* Tests getting the group from a new membership.
*
* @covers ::getGroup
* @expectedException \LogicException
*/
public function testGetGroupOnNewMembership() {
$membership = OgMembership::create();

// When no group has been set yet, the method should throw an assertion.
$this->expectException(\LogicException::class);
$membership->getGroup();
}

Expand All @@ -671,10 +674,11 @@ public function testGetGroupBundle() {
* Tests getting the group bundle of a newly created membership.
*
* @covers ::getGroupBundle
* @expectedException \LogicException
*/
public function testGetGroupBundleOnNewMembership() {
$membership = OgMembership::create();

$this->expectException(\LogicException::class);
$membership->getGroupBundle();
}

Expand All @@ -693,10 +697,11 @@ public function testGetGroupEntityType() {
* Tests getting the group entity type ID of a newly created membership.
*
* @covers ::getGroupEntityType
* @expectedException \LogicException
*/
public function testGetGroupEntityTypeOnNewMembership() {
$membership = OgMembership::create();

$this->expectException(\LogicException::class);
$membership->getGroupEntityType();
}

Expand All @@ -715,10 +720,11 @@ public function testGetGroupId() {
* Tests getting the group ID of a newly created membership.
*
* @covers ::getGroupId
* @expectedException \LogicException
*/
public function testGetGroupIdOnNewMembership() {
$membership = OgMembership::create();

$this->expectException(\LogicException::class);
$membership->getGroupId();
}

Expand Down
8 changes: 4 additions & 4 deletions tests/src/Unit/DefaultRoleEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ public function testAddInvalidRole(array $invalid_roles) {
* @covers ::addRoles
*
* @dataProvider invalidDefaultRoleProvider
* @expectedException \InvalidArgumentException
*/
public function testAddInvalidRoles(array $invalid_roles) {
$this->expectOgRoleCreation($invalid_roles);

$this->expectException(\InvalidArgumentException::class);
$this->defaultRoleEvent->addRoles($invalid_roles);
$this->fail('An array of invalid roles cannot be added.');
}
Expand All @@ -364,11 +364,11 @@ public function testAddInvalidRoles(array $invalid_roles) {
* @covers ::setRole
*
* @dataProvider invalidDefaultRoleProvider
* @expectedException \InvalidArgumentException
*/
public function testSetInvalidRole(array $invalid_roles) {
$this->expectOgRoleCreation($invalid_roles);

$this->expectException(\InvalidArgumentException::class);
foreach ($invalid_roles as $invalid_role) {
$this->defaultRoleEvent->setRole($invalid_role);
}
Expand All @@ -383,11 +383,11 @@ public function testSetInvalidRole(array $invalid_roles) {
* @covers ::setRoles
*
* @dataProvider invalidDefaultRoleProvider
* @expectedException \InvalidArgumentException
*/
public function testSetInvalidRoles(array $invalid_roles) {
$this->expectOgRoleCreation($invalid_roles);

$this->expectException(\InvalidArgumentException::class);
$this->defaultRoleEvent->setRoles($invalid_roles);
}

Expand All @@ -400,12 +400,12 @@ public function testSetInvalidRoles(array $invalid_roles) {
* @covers ::offsetSet
*
* @dataProvider invalidDefaultRoleProvider
* @expectedException \InvalidArgumentException
*/
public function testInvalidOffsetSet(array $invalid_roles) {
$this->expectOgRoleCreation($invalid_roles);

foreach ($invalid_roles as $name => $invalid_role) {
$this->expectException(\InvalidArgumentException::class);
$this->defaultRoleEvent[$name] = $invalid_role;
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/src/Unit/GroupCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ public function permissionsProvider() {

/**
* Tests fetching arguments from the route match without "getOption" defined.
*
* @expectedException BadMethodCallException
*/
public function testNoArgumentsFromRouteMatch() {
$this
Expand All @@ -300,6 +298,7 @@ public function testNoArgumentsFromRouteMatch() {

// Call the group check without the entity related arguments.
$group_check = new GroupCheck($this->entityTypeManager->reveal(), $this->ogAccess->reveal());
$this->expectException(\BadMethodCallException::class);
$group_check->access($this->user->reveal(), $this->route->reveal(), $this->routeMatch->reveal());
}

Expand Down
16 changes: 8 additions & 8 deletions tests/src/Unit/GroupContentOperationPermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,47 +332,47 @@ public function testSetRestrictAccess(array $values) {
* Tests getting an invalid property from a group content permission.
*
* @covers ::get
*
* @expectedException \InvalidArgumentException
*/
public function testGetInvalidProperty() {
$permission = new GroupContentOperationPermission();

$this->expectException(\InvalidArgumentException::class);
$permission->get('invalid property');
}

/**
* Tests setting an invalid property for a group content permission.
*
* @covers ::set
*
* @expectedException \InvalidArgumentException
*/
public function testSetInvalidProperty() {
$permission = new GroupContentOperationPermission();

$this->expectException(\InvalidArgumentException::class);
$permission->set('invalid property', 'a value');
}

/**
* Tests setting an invalid restrict access for a group content permission.
*
* @covers ::set
*
* @expectedException \InvalidArgumentException
*/
public function testSetInvalidRestrictAccessValue() {
$permission = new GroupContentOperationPermission();

$this->expectException(\InvalidArgumentException::class);
$permission->set('restrict access', 'invalid value');
}

/**
* Tests setting an invalid ownership property for a group content permission.
*
* @covers ::set
*
* @expectedException \InvalidArgumentException
*/
public function testSetInvalidOwnershipValue() {
$permission = new GroupContentOperationPermission();

$this->expectException(\InvalidArgumentException::class);
$permission->set('owner', 'invalid value');
}

Expand Down
12 changes: 6 additions & 6 deletions tests/src/Unit/GroupPermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,35 +239,35 @@ public function testSetRestrictAccess(array $values) {
* Tests getting an invalid property of a permission.
*
* @covers ::get
*
* @expectedException \InvalidArgumentException
*/
public function testGetInvalidProperty() {
$permission = new GroupPermission();

$this->expectException(\InvalidArgumentException::class);
$permission->get('invalid property');
}

/**
* Tests setting an invalid property for a permission.
*
* @covers ::set
*
* @expectedException \InvalidArgumentException
*/
public function testSetInvalidProperty() {
$permission = new GroupPermission();

$this->expectException(\InvalidArgumentException::class);
$permission->set('invalid property', 'a value');
}

/**
* Tests setting an invalid restrict access value for a permission.
*
* @covers ::set
*
* @expectedException \InvalidArgumentException
*/
public function testSetInvalidRestrictAccessValue() {
$permission = new GroupPermission();

$this->expectException(\InvalidArgumentException::class);
$permission->set('restrict access', 'invalid value');
}

Expand Down
Loading

0 comments on commit eaf0088

Please sign in to comment.