We previously disabled grolesync because it would not play nice with views and cache contexts. After having given it some thought, we can now re-enable the functionality, albeit part of the main module. That way we don't need to introduce a hook that may potentially put our code's stability at risk.

The flow will now be:

Type of visitor Global treatment Group treatment
Anonymous Anonymous role Anonymous group role
Registered user (any) Authenticated user role Outsider group role
Registered user with roles Specific user roles NEW: Outsider group roles matching global roles by name
Group members (any) N/A Member group role
Group members with roles N/A Specific group roles

Comments

kristiaanvandeneynde created an issue. See original summary.

kristiaanvandeneynde’s picture

Issue summary: View changes
kristiaanvandeneynde’s picture

Status: Active » Needs review
StatusFileSize
new39.19 KB

Really excited about this one, needs tests still :)

legolasbo’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

The code looks solid @kristiaanvandeneynde, but as you've pointed out yourself. it does still needs tests. I'd especially like to see some kernel or web tests that demonstrate the intent of this change.

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new46.82 KB
new9 KB

This adds unit testing for the group role synchronizer service. Need to add kernel tests now for a test-only interdiff and a complete patch.

kristiaanvandeneynde’s picture

Just noticed I do not need to prophesize any group role storage in the set up. Will remove that in the final patch.

kristiaanvandeneynde’s picture

Issue tags: -Needs tests
StatusFileSize
new3.73 KB
new50.13 KB

Here we go. The test in the test-only patch looks slightly different to the one in the full patch because of the missing service.

The last submitted patch, 7: group-2883238-7-TEST_ONLY.patch, failed testing. View results

legolasbo’s picture

Status: Needs review » Needs work
+++ b/tests/src/Kernel/GroupRoleSynchronizationTest.php
@@ -0,0 +1,93 @@
+  /**
+   * Tests whether a new global role syncs to group roles.
+   */
+  public function testGlobalRoleCreation() {
+    $group_roles = $this->entityTypeManager->getStorage('group_role')->loadMultiple();
+    $key = $this->getGroupRoleId('default', $this->userRole->id());
+    $this->assertArrayHasKey($key, $group_roles, 'Synchronized role found for default group type');
+    $key = $this->getGroupRoleId('other', $this->userRole->id());
+    $this->assertArrayHasKey($key, $group_roles, 'Synchronized role found for other group type');
+    $this->assertEquals($this->userRole->label(), $group_roles[$key]->label(), 'Synchronized roles share the same label');
+  }

Method comment and name are contradicting each other.

testGlobalRoleCreation !== Tests whether a new global role syncs to group roles

Besides that, both mention the creation of a role, but I'm not seeing any roles getting created.

Side note:
Tests should consist of 3 specific blocks of code:
- Precondition (e.g. Optional creation of a group to test against)
- Execution (e.g. creation of the roles)
- Postcondtion (e.g. assertions that prove the roles have been created and synchronised)

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new5.8 KB
new50.52 KB
legolasbo’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/tests/src/Kernel/GroupRoleSynchronizationTest.php
@@ -43,25 +29,49 @@ class GroupRoleSynchronizationTest extends GroupKernelTestBase {
+    $role = $this->createUserRole('editor');
+    $role->set('label', 'Super-editor');
+    $role->save();

Nitpick: This could use a blank line between the creation of the role (pre condition) and the editing of the role (execution) to separate those two concepts a little clearer.

Looks good otherwise.

kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the reviews!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.