From 912b5c7fcd8a34bf32e2fd0b23ebb16240430965 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 20:08:32 +0200 Subject: [PATCH 01/21] Run Rector + metadata update. --- .travis.yml | 8 +- composer.json | 6 +- og.info.yml | 3 +- src/Controller/OgAdminRoutesController.php | 2 +- src/Event/AccessEventBase.php | 2 +- src/Event/DefaultRoleEvent.php | 2 +- src/Event/GroupCreationEvent.php | 2 +- src/Event/OgAdminRoutesEvent.php | 2 +- src/Event/PermissionEvent.php | 2 +- src/GroupTypeManager.php | 2 +- src/OgAccess.php | 2 +- src/OgRoleManager.php | 2 +- src/PermissionManager.php | 2 +- src/Routing/RouteSubscriber.php | 2 +- tests/src/Kernel/Action/ActionTestBase.php | 1 + .../DefaultRoleEventIntegrationTest.php | 2 +- tests/src/Kernel/Entity/FieldCreateTest.php | 2 + .../Entity/GroupMembershipManagerTest.php | 2 + tests/src/Kernel/Entity/OgMembershipTest.php | 3 + .../OgStandardReferenceRelationshipTest.php | 100 +++++++++--------- tests/src/Kernel/PermissionEventTest.php | 2 +- .../Plugin/Block/MemberCountBlockTest.php | 1 + .../Context/OgContextCacheContextTestBase.php | 3 + .../OgMembershipStateCacheContextTest.php | 2 + .../Cache/Context/OgRoleCacheContextTest.php | 2 + tests/src/Unit/CreateMembershipTest.php | 2 + tests/src/Unit/DefaultRoleEventTest.php | 2 + tests/src/Unit/GroupCheckTest.php | 2 + tests/src/Unit/GroupTypeManagerTest.php | 2 + tests/src/Unit/OgAccessEntityTestBase.php | 2 + tests/src/Unit/OgAccessHookTest.php | 1 + tests/src/Unit/OgAccessTestBase.php | 2 + .../src/Unit/OgAdminRoutesControllerTest.php | 2 + tests/src/Unit/OgContextTest.php | 2 + tests/src/Unit/OgLocalTaskTest.php | 2 + .../Unit/OgResolvedGroupCollectionTest.php | 2 + tests/src/Unit/OgRoleManagerTest.php | 2 + .../OgGroupResolverTestBase.php | 3 + .../OgRouteGroupResolverTestBase.php | 2 + .../RequestQueryArgumentResolverTest.php | 2 + .../RouteGroupResolverTest.php | 2 + .../UserGroupAccessResolverTest.php | 2 + tests/src/Unit/SubscriptionControllerTest.php | 2 + 43 files changed, 124 insertions(+), 71 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9d91c798..e36fe4d3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ language: php php: - '7.4' - '8.0' + - '8.1' - nightly env: @@ -13,6 +14,7 @@ env: matrix: - TEST_SUITE=9.3.x - TEST_SUITE=9.4.x + - TEST_SUITE=10.0.x - TEST_SUITE=PHP_CodeSniffer # Only run the coding standards check once. @@ -20,8 +22,12 @@ matrix: exclude: - php: 7.4 env: TEST_SUITE=PHP_CodeSniffer + - php: 7.4 + env: TEST_SUITE=10.0.x - php: 8.0 env: TEST_SUITE=PHP_CodeSniffer + - php: 8.0 + env: TEST_SUITE=10.0.x mysql: database: og @@ -65,7 +71,7 @@ before_script: # Install Composer dependencies for core. Skip this for the coding standards test. - test ${TEST_SUITE} == "PHP_CodeSniffer" || composer install --working-dir=$DRUPAL_DIR - + # Start a web server on port 8888 in the background. - test ${TEST_SUITE} == "PHP_CodeSniffer" || nohup php -S localhost:8888 --docroot $DRUPAL_DIR > /dev/null 2>&1 & diff --git a/composer.json b/composer.json index 7340b7da5..4d7795b4d 100644 --- a/composer.json +++ b/composer.json @@ -24,13 +24,9 @@ "homepage": "https://www.drupal.org/u/pfrenssen" } ], - "require": { - "php": "^7.4 || ^8", - "drupal/core": "^9.3" - }, "require-dev": { "drupal/coder": "^8.3.16", - "phpunit/phpunit": "^7 || ^8" + "phpunit/phpunit": "^7 || ^8 || ^9" }, "minimum-stability": "RC", "config": { diff --git a/og.info.yml b/og.info.yml index fcafb725b..bc7a55e55 100644 --- a/og.info.yml +++ b/og.info.yml @@ -2,9 +2,8 @@ name: Organic Groups description: API to allow associating content with groups. package: Organic Groups -core_version_requirement: ^9 +core_version_requirement: ^9 || ^10 type: module -php: 7.1 dependencies: - drupal:options diff --git a/src/Controller/OgAdminRoutesController.php b/src/Controller/OgAdminRoutesController.php index 775dc0aa2..41889fbc7 100644 --- a/src/Controller/OgAdminRoutesController.php +++ b/src/Controller/OgAdminRoutesController.php @@ -76,7 +76,7 @@ public function overview(RouteMatchInterface $route_match) { $content = []; $event = new OgAdminRoutesEvent(); - $event = $this->eventDispatcher->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, $event); + $event = $this->eventDispatcher->dispatch($event, OgAdminRoutesEventInterface::EVENT_NAME); foreach ($event->getRoutes($entity_type_id) as $name => $info) { $route_name = "entity.$entity_type_id.og_admin_routes.$name"; diff --git a/src/Event/AccessEventBase.php b/src/Event/AccessEventBase.php index 1eeaf507f..c666b0758 100644 --- a/src/Event/AccessEventBase.php +++ b/src/Event/AccessEventBase.php @@ -10,7 +10,7 @@ use Drupal\Core\Cache\RefinableCacheableDependencyTrait; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Session\AccountInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Base class for OG access events. diff --git a/src/Event/DefaultRoleEvent.php b/src/Event/DefaultRoleEvent.php index 0c444749d..ffea7e884 100644 --- a/src/Event/DefaultRoleEvent.php +++ b/src/Event/DefaultRoleEvent.php @@ -5,7 +5,7 @@ namespace Drupal\og\Event; use Drupal\og\Entity\OgRole; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Event that is fired when default roles are compiled. diff --git a/src/Event/GroupCreationEvent.php b/src/Event/GroupCreationEvent.php index a796f62b4..ecf5dc45c 100644 --- a/src/Event/GroupCreationEvent.php +++ b/src/Event/GroupCreationEvent.php @@ -4,7 +4,7 @@ namespace Drupal\og\Event; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * The group creation event. diff --git a/src/Event/OgAdminRoutesEvent.php b/src/Event/OgAdminRoutesEvent.php index 5bde1ab40..5f65f5c57 100644 --- a/src/Event/OgAdminRoutesEvent.php +++ b/src/Event/OgAdminRoutesEvent.php @@ -6,7 +6,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\og\OgAccess; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Event that is fired when OG admin routes are being compiled. diff --git a/src/Event/PermissionEvent.php b/src/Event/PermissionEvent.php index 4a467f82b..7fdb78d3b 100644 --- a/src/Event/PermissionEvent.php +++ b/src/Event/PermissionEvent.php @@ -6,7 +6,7 @@ use Drupal\og\GroupContentOperationPermission; use Drupal\og\PermissionInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Event that is fired when OG permissions are compiled. diff --git a/src/GroupTypeManager.php b/src/GroupTypeManager.php index 2f5b263c8..b74c3f849 100644 --- a/src/GroupTypeManager.php +++ b/src/GroupTypeManager.php @@ -284,7 +284,7 @@ public function addGroup($entity_type_id, $bundle_id) { // Trigger an event upon the new group creation. $event = new GroupCreationEvent($entity_type_id, $bundle_id); - $this->eventDispatcher->dispatch(GroupCreationEventInterface::EVENT_NAME, $event); + $this->eventDispatcher->dispatch($event, GroupCreationEventInterface::EVENT_NAME); $this->ogRoleManager->createPerBundleRoles($entity_type_id, $bundle_id); $this->refreshGroupMap(); diff --git a/src/OgAccess.php b/src/OgAccess.php index e9862062f..5e0968189 100644 --- a/src/OgAccess.php +++ b/src/OgAccess.php @@ -323,7 +323,7 @@ public function userAccessGroupContentEntityOperation(string $operation, EntityI $event->addCacheContexts(['user']); } - $this->dispatcher->dispatch(GroupContentEntityOperationAccessEvent::EVENT_NAME, $event); + $this->dispatcher->dispatch($event, GroupContentEntityOperationAccessEvent::EVENT_NAME); return $event->getAccessResult(); } diff --git a/src/OgRoleManager.php b/src/OgRoleManager.php index b35d2c828..979830b56 100644 --- a/src/OgRoleManager.php +++ b/src/OgRoleManager.php @@ -88,7 +88,7 @@ public function getDefaultRoles() { $roles = $this->getRequiredDefaultRoles(); $event = new DefaultRoleEvent(); - $this->eventDispatcher->dispatch(DefaultRoleEventInterface::EVENT_NAME, $event); + $this->eventDispatcher->dispatch($event, DefaultRoleEventInterface::EVENT_NAME); // Use the array union operator '+=' to ensure the default roles cannot be // altered by event subscribers. diff --git a/src/PermissionManager.php b/src/PermissionManager.php index 9c4ab7b50..bb91cae4b 100644 --- a/src/PermissionManager.php +++ b/src/PermissionManager.php @@ -35,7 +35,7 @@ public function __construct(EventDispatcherInterface $event_dispatcher) { */ public function getDefaultPermissions($group_entity_type_id, $group_bundle_id, array $group_content_bundle_ids, $role_name = NULL) { $event = new PermissionEvent($group_entity_type_id, $group_bundle_id, $group_content_bundle_ids); - $this->eventDispatcher->dispatch(PermissionEventInterface::EVENT_NAME, $event); + $this->eventDispatcher->dispatch($event, PermissionEventInterface::EVENT_NAME); return $event->getPermissions(); } diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php index d616903aa..336ea319c 100644 --- a/src/Routing/RouteSubscriber.php +++ b/src/Routing/RouteSubscriber.php @@ -120,7 +120,7 @@ protected function alterRoutes(RouteCollection $collection) { */ protected function createRoutesFromEventSubscribers($og_admin_path, $entity_type_id, RouteCollection $collection) { $event = new OgAdminRoutesEvent(); - $this->eventDispatcher->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, $event); + $this->eventDispatcher->dispatch($event, OgAdminRoutesEventInterface::EVENT_NAME); foreach ($event->getRoutes($entity_type_id) as $name => $route_info) { // Add the parent route. diff --git a/tests/src/Kernel/Action/ActionTestBase.php b/tests/src/Kernel/Action/ActionTestBase.php index dda89e165..a7d965ed1 100644 --- a/tests/src/Kernel/Action/ActionTestBase.php +++ b/tests/src/Kernel/Action/ActionTestBase.php @@ -205,6 +205,7 @@ public function getPlugin($configuration = []) { * * @covers ::execute * @dataProvider executeProvider + * @doesNotPerformAssertions */ abstract public function testExecute($membership); diff --git a/tests/src/Kernel/DefaultRoleEventIntegrationTest.php b/tests/src/Kernel/DefaultRoleEventIntegrationTest.php index 48dede816..f94e3581e 100644 --- a/tests/src/Kernel/DefaultRoleEventIntegrationTest.php +++ b/tests/src/Kernel/DefaultRoleEventIntegrationTest.php @@ -68,7 +68,7 @@ public function testPermissionEventIntegration() { // Query the event listener directly to see if the administrator role is // present. - $this->eventDispatcher->dispatch(DefaultRoleEventInterface::EVENT_NAME, $event); + $this->eventDispatcher->dispatch($event, DefaultRoleEventInterface::EVENT_NAME); $this->assertEquals([OgRoleInterface::ADMINISTRATOR], array_keys($event->getRoles())); // Check that the role was created with the correct values. diff --git a/tests/src/Kernel/Entity/FieldCreateTest.php b/tests/src/Kernel/Entity/FieldCreateTest.php index 78af9f9dd..3a21d2b15 100644 --- a/tests/src/Kernel/Entity/FieldCreateTest.php +++ b/tests/src/Kernel/Entity/FieldCreateTest.php @@ -97,6 +97,8 @@ public function testValidFields() { /** * Testing invalid field creation. + * + * @doesNotPerformAssertions */ public function testInvalidFields() { // Unknown plugin. diff --git a/tests/src/Kernel/Entity/GroupMembershipManagerTest.php b/tests/src/Kernel/Entity/GroupMembershipManagerTest.php index 6ef627986..74448eb26 100644 --- a/tests/src/Kernel/Entity/GroupMembershipManagerTest.php +++ b/tests/src/Kernel/Entity/GroupMembershipManagerTest.php @@ -200,6 +200,7 @@ public function testGetGroupIds($group_type_id, $group_bundle, array $expected) * * @covers ::getGroupIds * @dataProvider groupContentProvider + * @doesNotPerformAssertions */ public function testGetGroupIdsInvalidArguments() { /** @var \Drupal\og\MembershipManagerInterface $membership_manager */ @@ -381,6 +382,7 @@ public function testGetGroupMembershipsByRoleNames() { * Tests retrieval of group membership IDs filtered by role names. * * @covers ::getGroupMembershipIdsByRoleNames + * @doesNotPerformAssertions */ public function testGetGroupMembershipIdsByRoleNames() { $membership_storage = $this->container->get('entity_type.manager')->getStorage('og_membership'); diff --git a/tests/src/Kernel/Entity/OgMembershipTest.php b/tests/src/Kernel/Entity/OgMembershipTest.php index bf2fe64a1..2b52278bd 100644 --- a/tests/src/Kernel/Entity/OgMembershipTest.php +++ b/tests/src/Kernel/Entity/OgMembershipTest.php @@ -258,6 +258,8 @@ public function testSetNoGroupException() { * * @todo This test is not related to the OgMembership entity. It should be * moved to a more appropriate test class. + * + * @doesNotPerformAssertions */ public function testNoOwnerException() { // Create a bundle and add as a group. @@ -591,6 +593,7 @@ public function testIsRoleValidException() { * Tests re-saving a membership. * * @covers ::preSave + * @doesNotPerformAssertions */ public function testSaveSameMembershipTwice() { $group = EntityTest::create([ diff --git a/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php b/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php index ef7172409..753df36bd 100644 --- a/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php +++ b/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php @@ -102,37 +102,37 @@ public function testNoDataTableRelationship() { $entity = EntityTest::create(); $entity->field_test_data->target_id = $referenced_entity->id(); $entity->save(); - $this->assertEqual($entity->field_test_data[0]->entity->id(), $referenced_entity->id()); + $this->assertEquals($entity->field_test_data[0]->entity->id(), $referenced_entity->id()); $this->entities[] = $entity; $entity = EntityTest::create(); $entity->field_test_data->target_id = $referenced_entity->id(); $entity->save(); - $this->assertEqual($entity->field_test_data[0]->entity->id(), $referenced_entity->id()); + $this->assertEquals($entity->field_test_data[0]->entity->id(), $referenced_entity->id()); $this->entities[] = $entity; Views::viewsData()->clear(); // Check the generated views data. $views_data = Views::viewsData()->get('entity_test__field_test_data'); - $this->assertEqual($views_data['field_test_data']['relationship']['id'], 'standard'); - $this->assertEqual($views_data['field_test_data']['relationship']['base'], 'entity_test_mul_property_data'); - $this->assertEqual($views_data['field_test_data']['relationship']['base field'], 'id'); - $this->assertEqual($views_data['field_test_data']['relationship']['relationship field'], 'field_test_data_target_id'); - $this->assertEqual($views_data['field_test_data']['relationship']['entity type'], 'entity_test_mul'); + $this->assertEquals($views_data['field_test_data']['relationship']['id'], 'standard'); + $this->assertEquals($views_data['field_test_data']['relationship']['base'], 'entity_test_mul_property_data'); + $this->assertEquals($views_data['field_test_data']['relationship']['base field'], 'id'); + $this->assertEquals($views_data['field_test_data']['relationship']['relationship field'], 'field_test_data_target_id'); + $this->assertEquals($views_data['field_test_data']['relationship']['entity type'], 'entity_test_mul'); // Check the backwards reference. $views_data = Views::viewsData()->get('entity_test_mul_property_data'); - $this->assertEqual($views_data['reverse__entity_test__field_test_data']['relationship']['id'], 'entity_reverse'); - $this->assertEqual($views_data['reverse__entity_test__field_test_data']['relationship']['base'], 'entity_test'); - $this->assertEqual($views_data['reverse__entity_test__field_test_data']['relationship']['base field'], 'id'); - $this->assertEqual($views_data['reverse__entity_test__field_test_data']['relationship']['field table'], 'entity_test__field_test_data'); - $this->assertEqual($views_data['reverse__entity_test__field_test_data']['relationship']['field field'], 'field_test_data_target_id'); - $this->assertEqual($views_data['reverse__entity_test__field_test_data']['relationship']['field_name'], 'field_test_data'); - $this->assertEqual($views_data['reverse__entity_test__field_test_data']['relationship']['entity_type'], 'entity_test'); + $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['id'], 'entity_reverse'); + $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['base'], 'entity_test'); + $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['base field'], 'id'); + $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['field table'], 'entity_test__field_test_data'); + $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['field field'], 'field_test_data_target_id'); + $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['field_name'], 'field_test_data'); + $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['entity_type'], 'entity_test'); $values = ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]; - $this->assertEqual($views_data['reverse__entity_test__field_test_data']['relationship']['join_extra'][0], $values); + $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['join_extra'][0], $values); // Check an actual test view. $view = Views::getView('test_og_standard_reference_entity_test_view'); @@ -140,17 +140,17 @@ public function testNoDataTableRelationship() { /** @var \Drupal\views\ResultRow $row */ foreach ($view->result as $index => $row) { // Check that the actual ID of the entity is the expected one. - $this->assertEqual($row->id, $this->entities[$index]->id()); + $this->assertEquals($row->id, $this->entities[$index]->id()); // Also check that we have the correct result entity. - $this->assertEqual($row->_entity->id(), $this->entities[$index]->id()); + $this->assertEquals($row->_entity->id(), $this->entities[$index]->id()); // Test the forward relationship. - $this->assertEqual($row->entity_test_mul_property_data_entity_test__field_test_data_i, 1); + $this->assertEquals($row->entity_test_mul_property_data_entity_test__field_test_data_i, 1); // Test that the correct relationship entity is on the row. - $this->assertEqual($row->_relationship_entities['field_test_data']->id(), 1); - $this->assertEqual($row->_relationship_entities['field_test_data']->bundle(), 'entity_test_mul'); + $this->assertEquals($row->_relationship_entities['field_test_data']->id(), 1); + $this->assertEquals($row->_relationship_entities['field_test_data']->bundle(), 'entity_test_mul'); } @@ -159,15 +159,15 @@ public function testNoDataTableRelationship() { $this->executeView($view); /** @var \Drupal\views\ResultRow $row */ foreach ($view->result as $index => $row) { - $this->assertEqual($row->id, 1); - $this->assertEqual($row->_entity->id(), 1); + $this->assertEquals($row->id, 1); + $this->assertEquals($row->_entity->id(), 1); // Test the backwards relationship. - $this->assertEqual($row->field_test_data_entity_test_mul_property_data_id, $this->entities[$index]->id()); + $this->assertEquals($row->field_test_data_entity_test_mul_property_data_id, $this->entities[$index]->id()); // Test that the correct relationship entity is on the row. - $this->assertEqual($row->_relationship_entities['reverse__entity_test__field_test_data']->id(), $this->entities[$index]->id()); - $this->assertEqual($row->_relationship_entities['reverse__entity_test__field_test_data']->bundle(), 'entity_test'); + $this->assertEquals($row->_relationship_entities['reverse__entity_test__field_test_data']->id(), $this->entities[$index]->id()); + $this->assertEquals($row->_relationship_entities['reverse__entity_test__field_test_data']->bundle(), 'entity_test'); } } @@ -185,37 +185,37 @@ public function testDataTableRelationship() { $entity = EntityTestMul::create(); $entity->field_data_test->target_id = $referenced_entity->id(); $entity->save(); - $this->assertEqual($entity->field_data_test[0]->entity->id(), $referenced_entity->id()); + $this->assertEquals($entity->field_data_test[0]->entity->id(), $referenced_entity->id()); $this->entities[] = $entity; $entity = EntityTestMul::create(); $entity->field_data_test->target_id = $referenced_entity->id(); $entity->save(); - $this->assertEqual($entity->field_data_test[0]->entity->id(), $referenced_entity->id()); + $this->assertEquals($entity->field_data_test[0]->entity->id(), $referenced_entity->id()); $this->entities[] = $entity; Views::viewsData()->clear(); // Check the generated views data. $views_data = Views::viewsData()->get('entity_test_mul__field_data_test'); - $this->assertEqual($views_data['field_data_test']['relationship']['id'], 'standard'); - $this->assertEqual($views_data['field_data_test']['relationship']['base'], 'entity_test'); - $this->assertEqual($views_data['field_data_test']['relationship']['base field'], 'id'); - $this->assertEqual($views_data['field_data_test']['relationship']['relationship field'], 'field_data_test_target_id'); - $this->assertEqual($views_data['field_data_test']['relationship']['entity type'], 'entity_test'); + $this->assertEquals($views_data['field_data_test']['relationship']['id'], 'standard'); + $this->assertEquals($views_data['field_data_test']['relationship']['base'], 'entity_test'); + $this->assertEquals($views_data['field_data_test']['relationship']['base field'], 'id'); + $this->assertEquals($views_data['field_data_test']['relationship']['relationship field'], 'field_data_test_target_id'); + $this->assertEquals($views_data['field_data_test']['relationship']['entity type'], 'entity_test'); // Check the backwards reference. $views_data = Views::viewsData()->get('entity_test'); - $this->assertEqual($views_data['reverse__entity_test_mul__field_data_test']['relationship']['id'], 'entity_reverse'); - $this->assertEqual($views_data['reverse__entity_test_mul__field_data_test']['relationship']['base'], 'entity_test_mul_property_data'); - $this->assertEqual($views_data['reverse__entity_test_mul__field_data_test']['relationship']['base field'], 'id'); - $this->assertEqual($views_data['reverse__entity_test_mul__field_data_test']['relationship']['field table'], 'entity_test_mul__field_data_test'); - $this->assertEqual($views_data['reverse__entity_test_mul__field_data_test']['relationship']['field field'], 'field_data_test_target_id'); - $this->assertEqual($views_data['reverse__entity_test_mul__field_data_test']['relationship']['field_name'], 'field_data_test'); - $this->assertEqual($views_data['reverse__entity_test_mul__field_data_test']['relationship']['entity_type'], 'entity_test_mul'); + $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['id'], 'entity_reverse'); + $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['base'], 'entity_test_mul_property_data'); + $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['base field'], 'id'); + $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['field table'], 'entity_test_mul__field_data_test'); + $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['field field'], 'field_data_test_target_id'); + $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['field_name'], 'field_data_test'); + $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['entity_type'], 'entity_test_mul'); $values = ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]; - $this->assertEqual($views_data['reverse__entity_test_mul__field_data_test']['relationship']['join_extra'][0], $values); + $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['join_extra'][0], $values); // Check an actual test view. $view = Views::getView('test_og_standard_reference_entity_test_mul_view'); @@ -223,17 +223,17 @@ public function testDataTableRelationship() { /** @var \Drupal\views\ResultRow $row */ foreach ($view->result as $index => $row) { // Check that the actual ID of the entity is the expected one. - $this->assertEqual($row->id, $this->entities[$index]->id()); + $this->assertEquals($row->id, $this->entities[$index]->id()); // Also check that we have the correct result entity. - $this->assertEqual($row->_entity->id(), $this->entities[$index]->id()); + $this->assertEquals($row->_entity->id(), $this->entities[$index]->id()); // Test the forward relationship. - $this->assertEqual($row->entity_test_entity_test_mul__field_data_test_id, 1); + $this->assertEquals($row->entity_test_entity_test_mul__field_data_test_id, 1); // Test that the correct relationship entity is on the row. - $this->assertEqual($row->_relationship_entities['field_data_test']->id(), 1); - $this->assertEqual($row->_relationship_entities['field_data_test']->bundle(), 'entity_test'); + $this->assertEquals($row->_relationship_entities['field_data_test']->id(), 1); + $this->assertEquals($row->_relationship_entities['field_data_test']->bundle(), 'entity_test'); } @@ -242,15 +242,15 @@ public function testDataTableRelationship() { $this->executeView($view); /** @var \Drupal\views\ResultRow $row */ foreach ($view->result as $index => $row) { - $this->assertEqual($row->id, 1); - $this->assertEqual($row->_entity->id(), 1); + $this->assertEquals($row->id, 1); + $this->assertEquals($row->_entity->id(), 1); // Test the backwards relationship. - $this->assertEqual($row->field_data_test_entity_test_id, $this->entities[$index]->id()); + $this->assertEquals($row->field_data_test_entity_test_id, $this->entities[$index]->id()); // Test that the correct relationship entity is on the row. - $this->assertEqual($row->_relationship_entities['reverse__entity_test_mul__field_data_test']->id(), $this->entities[$index]->id()); - $this->assertEqual($row->_relationship_entities['reverse__entity_test_mul__field_data_test']->bundle(), 'entity_test_mul'); + $this->assertEquals($row->_relationship_entities['reverse__entity_test_mul__field_data_test']->id(), $this->entities[$index]->id()); + $this->assertEquals($row->_relationship_entities['reverse__entity_test_mul__field_data_test']->bundle(), 'entity_test_mul'); } } diff --git a/tests/src/Kernel/PermissionEventTest.php b/tests/src/Kernel/PermissionEventTest.php index 3ec6bdbcd..d39dd261e 100644 --- a/tests/src/Kernel/PermissionEventTest.php +++ b/tests/src/Kernel/PermissionEventTest.php @@ -98,7 +98,7 @@ public function testPermissionEventIntegration(array $group_content_bundle_ids, // Retrieve the permissions from the listeners. /** @var \Drupal\og\Event\PermissionEvent $permission_event */ $event = new PermissionEvent($this->randomMachineName(), $this->randomMachineName(), $group_content_bundle_ids); - $permission_event = $this->eventDispatcher->dispatch(PermissionEventInterface::EVENT_NAME, $event); + $permission_event = $this->eventDispatcher->dispatch($event, PermissionEventInterface::EVENT_NAME); $actual_permissions = array_keys($permission_event->getPermissions()); // Sort the permission arrays so they can be compared. diff --git a/tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php b/tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php index 851db0461..02f0c0fc3 100644 --- a/tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php +++ b/tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php @@ -21,6 +21,7 @@ */ class MemberCountBlockTest extends KernelTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; use OgMembershipCreationTrait; use StringTranslationTrait; use UserCreationTrait; diff --git a/tests/src/Unit/Cache/Context/OgContextCacheContextTestBase.php b/tests/src/Unit/Cache/Context/OgContextCacheContextTestBase.php index cfe04d3a9..a6e8ae73e 100644 --- a/tests/src/Unit/Cache/Context/OgContextCacheContextTestBase.php +++ b/tests/src/Unit/Cache/Context/OgContextCacheContextTestBase.php @@ -17,6 +17,8 @@ */ abstract class OgContextCacheContextTestBase extends OgCacheContextTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The mocked OG context service. * @@ -69,6 +71,7 @@ public function testWithContext($context, $expected_result) { * Tests the result of the cache context service without active context. * * @covers ::getContext + * @doesNotPerformAssertions */ abstract public function testWithoutContext(); diff --git a/tests/src/Unit/Cache/Context/OgMembershipStateCacheContextTest.php b/tests/src/Unit/Cache/Context/OgMembershipStateCacheContextTest.php index 077ddfdc5..8dc086333 100644 --- a/tests/src/Unit/Cache/Context/OgMembershipStateCacheContextTest.php +++ b/tests/src/Unit/Cache/Context/OgMembershipStateCacheContextTest.php @@ -17,6 +17,8 @@ */ class OgMembershipStateCacheContextTest extends OgContextCacheContextTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The OG membership entity. * diff --git a/tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php b/tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php index 8cd718bd8..84f7493fb 100644 --- a/tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php +++ b/tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php @@ -23,6 +23,8 @@ */ class OgRoleCacheContextTest extends OgCacheContextTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; + use OgRoleCacheContextTestTrait; /** diff --git a/tests/src/Unit/CreateMembershipTest.php b/tests/src/Unit/CreateMembershipTest.php index d1be7ce71..605b0ba28 100644 --- a/tests/src/Unit/CreateMembershipTest.php +++ b/tests/src/Unit/CreateMembershipTest.php @@ -25,6 +25,8 @@ */ class CreateMembershipTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The entity type manager. * diff --git a/tests/src/Unit/DefaultRoleEventTest.php b/tests/src/Unit/DefaultRoleEventTest.php index a8a1a795b..309c5bcce 100644 --- a/tests/src/Unit/DefaultRoleEventTest.php +++ b/tests/src/Unit/DefaultRoleEventTest.php @@ -19,6 +19,8 @@ */ class DefaultRoleEventTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The DefaultRoleEvent class, which is the system under test. * diff --git a/tests/src/Unit/GroupCheckTest.php b/tests/src/Unit/GroupCheckTest.php index a303e6996..43ab7d50e 100644 --- a/tests/src/Unit/GroupCheckTest.php +++ b/tests/src/Unit/GroupCheckTest.php @@ -25,6 +25,8 @@ */ class GroupCheckTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The entity type manager prophecy used in the test. * diff --git a/tests/src/Unit/GroupTypeManagerTest.php b/tests/src/Unit/GroupTypeManagerTest.php index b46a0e30d..3be2aba59 100644 --- a/tests/src/Unit/GroupTypeManagerTest.php +++ b/tests/src/Unit/GroupTypeManagerTest.php @@ -32,6 +32,8 @@ */ class GroupTypeManagerTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The config prophecy used in the test. * diff --git a/tests/src/Unit/OgAccessEntityTestBase.php b/tests/src/Unit/OgAccessEntityTestBase.php index d0e542d3f..2c077a1b7 100644 --- a/tests/src/Unit/OgAccessEntityTestBase.php +++ b/tests/src/Unit/OgAccessEntityTestBase.php @@ -19,6 +19,8 @@ */ abstract class OgAccessEntityTestBase extends OgAccessTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * A test group content entity. * diff --git a/tests/src/Unit/OgAccessHookTest.php b/tests/src/Unit/OgAccessHookTest.php index b55c9ee0d..b3ff42e79 100644 --- a/tests/src/Unit/OgAccessHookTest.php +++ b/tests/src/Unit/OgAccessHookTest.php @@ -13,6 +13,7 @@ */ class OgAccessHookTest extends OgAccessEntityTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; /** * {@inheritdoc} */ diff --git a/tests/src/Unit/OgAccessTestBase.php b/tests/src/Unit/OgAccessTestBase.php index 959a1867e..119ec7d3e 100644 --- a/tests/src/Unit/OgAccessTestBase.php +++ b/tests/src/Unit/OgAccessTestBase.php @@ -30,6 +30,8 @@ */ class OgAccessTestBase extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The mocked config handler. * diff --git a/tests/src/Unit/OgAdminRoutesControllerTest.php b/tests/src/Unit/OgAdminRoutesControllerTest.php index 9396912fc..7771ac64a 100644 --- a/tests/src/Unit/OgAdminRoutesControllerTest.php +++ b/tests/src/Unit/OgAdminRoutesControllerTest.php @@ -25,6 +25,8 @@ */ class OgAdminRoutesControllerTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The access manager service. * diff --git a/tests/src/Unit/OgContextTest.php b/tests/src/Unit/OgContextTest.php index 92d91c2eb..aab43fcf4 100644 --- a/tests/src/Unit/OgContextTest.php +++ b/tests/src/Unit/OgContextTest.php @@ -26,6 +26,8 @@ */ class OgContextTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * A mocked plugin manager. * diff --git a/tests/src/Unit/OgLocalTaskTest.php b/tests/src/Unit/OgLocalTaskTest.php index b0e451fdc..38167d692 100644 --- a/tests/src/Unit/OgLocalTaskTest.php +++ b/tests/src/Unit/OgLocalTaskTest.php @@ -21,6 +21,8 @@ */ class OgLocalTaskTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The group type manager. * diff --git a/tests/src/Unit/OgResolvedGroupCollectionTest.php b/tests/src/Unit/OgResolvedGroupCollectionTest.php index 862e23250..01f5717a3 100644 --- a/tests/src/Unit/OgResolvedGroupCollectionTest.php +++ b/tests/src/Unit/OgResolvedGroupCollectionTest.php @@ -16,6 +16,8 @@ */ class OgResolvedGroupCollectionTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * An array of mocked test groups, keyed by entity type ID and entity ID. * diff --git a/tests/src/Unit/OgRoleManagerTest.php b/tests/src/Unit/OgRoleManagerTest.php index 293e3eda2..684186f7d 100644 --- a/tests/src/Unit/OgRoleManagerTest.php +++ b/tests/src/Unit/OgRoleManagerTest.php @@ -21,6 +21,8 @@ */ class OgRoleManagerTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The entity type ID of the test group. * diff --git a/tests/src/Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php b/tests/src/Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php index 950baabcd..fe0ee7130 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php @@ -18,6 +18,8 @@ */ abstract class OgGroupResolverTestBase extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The fully qualified class name of the plugin under test. * @@ -118,6 +120,7 @@ protected function setUp(): void { * * @dataProvider resolveProvider * @covers ::resolve() + * @doesNotPerformAssertions */ abstract public function testResolve(); diff --git a/tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php b/tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php index 3fdb3747f..0efd243b3 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php @@ -15,6 +15,8 @@ */ abstract class OgRouteGroupResolverTestBase extends OgGroupResolverTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * A list of link templates that belong to entity types used in the tests. * diff --git a/tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php b/tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php index 8daf87f7d..85475289d 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php @@ -19,6 +19,8 @@ */ class RequestQueryArgumentResolverTest extends OgGroupResolverTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * {@inheritdoc} */ diff --git a/tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php b/tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php index 3fa806087..fed79e914 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php @@ -15,6 +15,8 @@ */ class RouteGroupResolverTest extends OgRouteGroupResolverTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * {@inheritdoc} */ diff --git a/tests/src/Unit/Plugin/OgGroupResolver/UserGroupAccessResolverTest.php b/tests/src/Unit/Plugin/OgGroupResolver/UserGroupAccessResolverTest.php index 0dc28912a..198307ead 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/UserGroupAccessResolverTest.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/UserGroupAccessResolverTest.php @@ -15,6 +15,8 @@ */ class UserGroupAccessResolverTest extends OgGroupResolverTestBase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * {@inheritdoc} */ diff --git a/tests/src/Unit/SubscriptionControllerTest.php b/tests/src/Unit/SubscriptionControllerTest.php index 1335b421f..e07abedbd 100644 --- a/tests/src/Unit/SubscriptionControllerTest.php +++ b/tests/src/Unit/SubscriptionControllerTest.php @@ -27,6 +27,8 @@ */ class SubscriptionControllerTest extends UnitTestCase { + use \Prophecy\PhpUnit\ProphecyTrait; + /** * The entity for builder object. * From c94dea340790d2656df310c8359cf4b3976e4abc Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 20:10:36 +0200 Subject: [PATCH 02/21] Run PHP CS only once --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e36fe4d3c..e0ce9e2c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,8 @@ matrix: env: TEST_SUITE=PHP_CodeSniffer - php: 8.0 env: TEST_SUITE=10.0.x + - php: 8.1 + env: TEST_SUITE=PHP_CodeSniffer mysql: database: og From f021a99b80ff214a76535b5de63e3ac58d3a5dbd Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 20:13:24 +0200 Subject: [PATCH 03/21] Be nice with Travis --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e0ce9e2c3..4e754ec15 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,13 +6,11 @@ php: - '7.4' - '8.0' - '8.1' - - nightly env: global: - COMPOSER_MEMORY_LIMIT=2G matrix: - - TEST_SUITE=9.3.x - TEST_SUITE=9.4.x - TEST_SUITE=10.0.x - TEST_SUITE=PHP_CodeSniffer From 5550aa8e4509bed53b81ba08d3ededc4dc08502d Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 20:15:24 +0200 Subject: [PATCH 04/21] Add back code sniffer test --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4e754ec15..dfd51b7d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,6 @@ matrix: env: TEST_SUITE=PHP_CodeSniffer - php: 8.0 env: TEST_SUITE=10.0.x - - php: 8.1 - env: TEST_SUITE=PHP_CodeSniffer mysql: database: og From ce8b5782b94ae5ccf844ab470234033925a8e0f2 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 20:27:51 +0200 Subject: [PATCH 05/21] Fix tests --- tests/src/Unit/GroupTypeManagerTest.php | 2 +- tests/src/Unit/OgAdminRoutesControllerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/Unit/GroupTypeManagerTest.php b/tests/src/Unit/GroupTypeManagerTest.php index 3be2aba59..53edbd75d 100644 --- a/tests/src/Unit/GroupTypeManagerTest.php +++ b/tests/src/Unit/GroupTypeManagerTest.php @@ -267,7 +267,7 @@ public function testAddGroupNew() { $this->ogRoleManager->createPerBundleRoles('test_entity_new', 'a'); - $this->eventDispatcher->dispatch(GroupCreationEventInterface::EVENT_NAME, Argument::type(GroupCreationEvent::class)) + $this->eventDispatcher->dispatch(Argument::type(GroupCreationEvent::class), GroupCreationEventInterface::EVENT_NAME) ->shouldBeCalled(); // Add a new entity type. diff --git a/tests/src/Unit/OgAdminRoutesControllerTest.php b/tests/src/Unit/OgAdminRoutesControllerTest.php index 7771ac64a..4ca73f591 100644 --- a/tests/src/Unit/OgAdminRoutesControllerTest.php +++ b/tests/src/Unit/OgAdminRoutesControllerTest.php @@ -161,7 +161,7 @@ protected function setUp(): void { $this ->eventDispatcher - ->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, Argument::type(OgAdminRoutesEvent::class)) + ->dispatch(Argument::type(OgAdminRoutesEvent::class), OgAdminRoutesEventInterface::EVENT_NAME) ->willReturn($this->event->reveal()) ->shouldBeCalled(); From 801f3f0df30ba4e3f3021771b457b3ffd0468dc0 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 20:37:06 +0200 Subject: [PATCH 06/21] Use the 'use' statement --- tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php | 3 ++- .../src/Unit/Cache/Context/OgContextCacheContextTestBase.php | 3 ++- .../Unit/Cache/Context/OgMembershipStateCacheContextTest.php | 3 ++- tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php | 4 ++-- tests/src/Unit/CreateMembershipTest.php | 3 ++- tests/src/Unit/DefaultRoleEventTest.php | 3 ++- tests/src/Unit/GroupCheckTest.php | 3 ++- tests/src/Unit/GroupTypeManagerTest.php | 3 ++- tests/src/Unit/OgAccessEntityTestBase.php | 3 ++- tests/src/Unit/OgAccessHookTest.php | 4 +++- tests/src/Unit/OgAccessTestBase.php | 3 ++- tests/src/Unit/OgAdminRoutesControllerTest.php | 3 ++- tests/src/Unit/OgContextTest.php | 3 ++- tests/src/Unit/OgLocalTaskTest.php | 3 ++- tests/src/Unit/OgResolvedGroupCollectionTest.php | 3 ++- tests/src/Unit/OgRoleManagerTest.php | 3 ++- .../Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php | 3 ++- .../Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php | 3 ++- .../OgGroupResolver/RequestQueryArgumentResolverTest.php | 3 ++- .../Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php | 3 ++- .../Plugin/OgGroupResolver/UserGroupAccessResolverTest.php | 3 ++- tests/src/Unit/SubscriptionControllerTest.php | 3 ++- 22 files changed, 45 insertions(+), 23 deletions(-) diff --git a/tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php b/tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php index 02f0c0fc3..6ad6a3232 100644 --- a/tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php +++ b/tests/src/Kernel/Plugin/Block/MemberCountBlockTest.php @@ -12,6 +12,7 @@ use Drupal\og\OgMembershipInterface; use Drupal\Tests\og\Traits\OgMembershipCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Promise\CallbackPromise; /** @@ -21,8 +22,8 @@ */ class MemberCountBlockTest extends KernelTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; use OgMembershipCreationTrait; + use ProphecyTrait; use StringTranslationTrait; use UserCreationTrait; diff --git a/tests/src/Unit/Cache/Context/OgContextCacheContextTestBase.php b/tests/src/Unit/Cache/Context/OgContextCacheContextTestBase.php index a6e8ae73e..7011ae30a 100644 --- a/tests/src/Unit/Cache/Context/OgContextCacheContextTestBase.php +++ b/tests/src/Unit/Cache/Context/OgContextCacheContextTestBase.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\og\OgContextInterface; +use Prophecy\PhpUnit\ProphecyTrait; /** * Base class for testing cache contexts that rely on OgContext. @@ -17,7 +18,7 @@ */ abstract class OgContextCacheContextTestBase extends OgCacheContextTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The mocked OG context service. diff --git a/tests/src/Unit/Cache/Context/OgMembershipStateCacheContextTest.php b/tests/src/Unit/Cache/Context/OgMembershipStateCacheContextTest.php index 8dc086333..792a625a3 100644 --- a/tests/src/Unit/Cache/Context/OgMembershipStateCacheContextTest.php +++ b/tests/src/Unit/Cache/Context/OgMembershipStateCacheContextTest.php @@ -8,6 +8,7 @@ use Drupal\og\Cache\Context\OgMembershipStateCacheContext; use Drupal\og\MembershipManagerInterface; use Drupal\og\OgMembershipInterface; +use Prophecy\PhpUnit\ProphecyTrait; /** * Tests OG membership state cache context. @@ -17,7 +18,7 @@ */ class OgMembershipStateCacheContextTest extends OgContextCacheContextTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The OG membership entity. diff --git a/tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php b/tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php index 84f7493fb..560175c6f 100644 --- a/tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php +++ b/tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php @@ -14,6 +14,7 @@ use Drupal\og\Cache\Context\OgRoleCacheContext; use Drupal\og\MembershipManagerInterface; use Drupal\og\OgMembershipInterface; +use Prophecy\PhpUnit\ProphecyTrait; /** * Tests the OG role cache context. @@ -23,9 +24,8 @@ */ class OgRoleCacheContextTest extends OgCacheContextTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; - use OgRoleCacheContextTestTrait; + use ProphecyTrait; /** * The mocked entity type manager. diff --git a/tests/src/Unit/CreateMembershipTest.php b/tests/src/Unit/CreateMembershipTest.php index 605b0ba28..18802180c 100644 --- a/tests/src/Unit/CreateMembershipTest.php +++ b/tests/src/Unit/CreateMembershipTest.php @@ -16,6 +16,7 @@ use Drupal\og\OgMembershipInterface; use Drupal\user\UserInterface; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; /** * Tests create membership helper function. @@ -25,7 +26,7 @@ */ class CreateMembershipTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The entity type manager. diff --git a/tests/src/Unit/DefaultRoleEventTest.php b/tests/src/Unit/DefaultRoleEventTest.php index 309c5bcce..2d8272344 100644 --- a/tests/src/Unit/DefaultRoleEventTest.php +++ b/tests/src/Unit/DefaultRoleEventTest.php @@ -10,6 +10,7 @@ use Drupal\og\Entity\OgRole; use Drupal\og\Event\DefaultRoleEvent; use Drupal\og\OgRoleInterface; +use Prophecy\PhpUnit\ProphecyTrait; /** * Tests default role events. @@ -19,7 +20,7 @@ */ class DefaultRoleEventTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The DefaultRoleEvent class, which is the system under test. diff --git a/tests/src/Unit/GroupCheckTest.php b/tests/src/Unit/GroupCheckTest.php index 43ab7d50e..6951122f6 100644 --- a/tests/src/Unit/GroupCheckTest.php +++ b/tests/src/Unit/GroupCheckTest.php @@ -15,6 +15,7 @@ use Drupal\og\Access\GroupCheck; use Drupal\og\GroupTypeManagerInterface; use Drupal\og\OgAccessInterface; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Routing\Route; /** @@ -25,7 +26,7 @@ */ class GroupCheckTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The entity type manager prophecy used in the test. diff --git a/tests/src/Unit/GroupTypeManagerTest.php b/tests/src/Unit/GroupTypeManagerTest.php index 53edbd75d..41a1d0b98 100644 --- a/tests/src/Unit/GroupTypeManagerTest.php +++ b/tests/src/Unit/GroupTypeManagerTest.php @@ -22,6 +22,7 @@ use Drupal\og\OgRoleManagerInterface; use Drupal\og\PermissionManagerInterface; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -32,7 +33,7 @@ */ class GroupTypeManagerTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The config prophecy used in the test. diff --git a/tests/src/Unit/OgAccessEntityTestBase.php b/tests/src/Unit/OgAccessEntityTestBase.php index 2c077a1b7..009715d93 100644 --- a/tests/src/Unit/OgAccessEntityTestBase.php +++ b/tests/src/Unit/OgAccessEntityTestBase.php @@ -13,13 +13,14 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\og\OgGroupAudienceHelperInterface; +use Prophecy\PhpUnit\ProphecyTrait; /** * OG access entity base class. */ abstract class OgAccessEntityTestBase extends OgAccessTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * A test group content entity. diff --git a/tests/src/Unit/OgAccessHookTest.php b/tests/src/Unit/OgAccessHookTest.php index b3ff42e79..f9b1bdd8f 100644 --- a/tests/src/Unit/OgAccessHookTest.php +++ b/tests/src/Unit/OgAccessHookTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\og\Unit; use Drupal\Core\Entity\EntityInterface; +use Prophecy\PhpUnit\ProphecyTrait; /** * Tests hook implementation of OG related access. @@ -13,7 +14,8 @@ */ class OgAccessHookTest extends OgAccessEntityTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; + /** * {@inheritdoc} */ diff --git a/tests/src/Unit/OgAccessTestBase.php b/tests/src/Unit/OgAccessTestBase.php index 119ec7d3e..b042263dc 100644 --- a/tests/src/Unit/OgAccessTestBase.php +++ b/tests/src/Unit/OgAccessTestBase.php @@ -23,6 +23,7 @@ use Drupal\user\EntityOwnerInterface; use Drupal\user\RoleInterface; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -30,7 +31,7 @@ */ class OgAccessTestBase extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The mocked config handler. diff --git a/tests/src/Unit/OgAdminRoutesControllerTest.php b/tests/src/Unit/OgAdminRoutesControllerTest.php index 4ca73f591..396f07b40 100644 --- a/tests/src/Unit/OgAdminRoutesControllerTest.php +++ b/tests/src/Unit/OgAdminRoutesControllerTest.php @@ -15,6 +15,7 @@ use Drupal\og\Event\OgAdminRoutesEvent; use Drupal\og\Event\OgAdminRoutesEventInterface; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Routing\Route; /** @@ -25,7 +26,7 @@ */ class OgAdminRoutesControllerTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The access manager service. diff --git a/tests/src/Unit/OgContextTest.php b/tests/src/Unit/OgContextTest.php index aab43fcf4..d82d8b516 100644 --- a/tests/src/Unit/OgContextTest.php +++ b/tests/src/Unit/OgContextTest.php @@ -16,6 +16,7 @@ use Drupal\og\OgGroupResolverInterface; use Drupal\og\OgResolvedGroupCollectionInterface; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\DependencyInjection\Container; /** @@ -26,7 +27,7 @@ */ class OgContextTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * A mocked plugin manager. diff --git a/tests/src/Unit/OgLocalTaskTest.php b/tests/src/Unit/OgLocalTaskTest.php index 38167d692..cab1cd1b0 100644 --- a/tests/src/Unit/OgLocalTaskTest.php +++ b/tests/src/Unit/OgLocalTaskTest.php @@ -9,6 +9,7 @@ use Drupal\Tests\UnitTestCase; use Drupal\og\GroupTypeManagerInterface; use Drupal\og\Plugin\Derivative\OgLocalTask; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Routing\Route; /** @@ -21,7 +22,7 @@ */ class OgLocalTaskTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The group type manager. diff --git a/tests/src/Unit/OgResolvedGroupCollectionTest.php b/tests/src/Unit/OgResolvedGroupCollectionTest.php index 01f5717a3..813b6c765 100644 --- a/tests/src/Unit/OgResolvedGroupCollectionTest.php +++ b/tests/src/Unit/OgResolvedGroupCollectionTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Tests\UnitTestCase; use Drupal\og\OgResolvedGroupCollection; +use Prophecy\PhpUnit\ProphecyTrait; /** * Tests the collecting of resolved groups to pass as a route context. @@ -16,7 +17,7 @@ */ class OgResolvedGroupCollectionTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * An array of mocked test groups, keyed by entity type ID and entity ID. diff --git a/tests/src/Unit/OgRoleManagerTest.php b/tests/src/Unit/OgRoleManagerTest.php index 684186f7d..b56e33b52 100644 --- a/tests/src/Unit/OgRoleManagerTest.php +++ b/tests/src/Unit/OgRoleManagerTest.php @@ -11,6 +11,7 @@ use Drupal\og\OgRoleInterface; use Drupal\og\OgRoleManager; use Drupal\og\PermissionManagerInterface; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -21,7 +22,7 @@ */ class OgRoleManagerTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The entity type ID of the test group. diff --git a/tests/src/Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php b/tests/src/Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php index fe0ee7130..e44e556ba 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php @@ -10,6 +10,7 @@ use Drupal\og\GroupTypeManagerInterface; use Drupal\og\MembershipManagerInterface; use Drupal\og\OgGroupAudienceHelperInterface; +use Prophecy\PhpUnit\ProphecyTrait; /** * Base class for testing OgGroupResolver plugins. @@ -18,7 +19,7 @@ */ abstract class OgGroupResolverTestBase extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The fully qualified class name of the plugin under test. diff --git a/tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php b/tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php index 0efd243b3..f185bd6c6 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\og\OgResolvedGroupCollectionInterface; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Routing\Route; /** @@ -15,7 +16,7 @@ */ abstract class OgRouteGroupResolverTestBase extends OgGroupResolverTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * A list of link templates that belong to entity types used in the tests. diff --git a/tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php b/tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php index 85475289d..08e0653f9 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\og\OgResolvedGroupCollectionInterface; use Drupal\og\Plugin\OgGroupResolver\RequestQueryArgumentResolver; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -19,7 +20,7 @@ */ class RequestQueryArgumentResolverTest extends OgGroupResolverTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * {@inheritdoc} diff --git a/tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php b/tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php index fed79e914..4f71857a8 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/RouteGroupResolverTest.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\og\Plugin\OgGroupResolver\RouteGroupResolver; +use Prophecy\PhpUnit\ProphecyTrait; /** * Tests the RouteGroupResolver plugin. @@ -15,7 +16,7 @@ */ class RouteGroupResolverTest extends OgRouteGroupResolverTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * {@inheritdoc} diff --git a/tests/src/Unit/Plugin/OgGroupResolver/UserGroupAccessResolverTest.php b/tests/src/Unit/Plugin/OgGroupResolver/UserGroupAccessResolverTest.php index 198307ead..2f04499c8 100644 --- a/tests/src/Unit/Plugin/OgGroupResolver/UserGroupAccessResolverTest.php +++ b/tests/src/Unit/Plugin/OgGroupResolver/UserGroupAccessResolverTest.php @@ -6,6 +6,7 @@ use Drupal\og\OgResolvedGroupCollectionInterface; use Drupal\og\Plugin\OgGroupResolver\UserGroupAccessResolver; +use Prophecy\PhpUnit\ProphecyTrait; /** * Tests the UserGroupAccessResolver plugin. @@ -15,7 +16,7 @@ */ class UserGroupAccessResolverTest extends OgGroupResolverTestBase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * {@inheritdoc} diff --git a/tests/src/Unit/SubscriptionControllerTest.php b/tests/src/Unit/SubscriptionControllerTest.php index e07abedbd..362b65f93 100644 --- a/tests/src/Unit/SubscriptionControllerTest.php +++ b/tests/src/Unit/SubscriptionControllerTest.php @@ -17,6 +17,7 @@ use Drupal\og\OgAccessInterface; use Drupal\og\OgMembershipInterface; use Drupal\user\EntityOwnerInterface; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** @@ -27,7 +28,7 @@ */ class SubscriptionControllerTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * The entity for builder object. From 3c7946e6d63fa1f4b32a604f4a0de822d8263aac Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 20:52:01 +0200 Subject: [PATCH 07/21] Expectation come first --- .../OgStandardReferenceRelationshipTest.php | 91 +++++++++---------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php b/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php index 753df36bd..7ea82299d 100644 --- a/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php +++ b/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php @@ -102,37 +102,37 @@ public function testNoDataTableRelationship() { $entity = EntityTest::create(); $entity->field_test_data->target_id = $referenced_entity->id(); $entity->save(); - $this->assertEquals($entity->field_test_data[0]->entity->id(), $referenced_entity->id()); + $this->assertEquals($referenced_entity->id(), $entity->field_test_data[0]->entity->id()); $this->entities[] = $entity; $entity = EntityTest::create(); $entity->field_test_data->target_id = $referenced_entity->id(); $entity->save(); - $this->assertEquals($entity->field_test_data[0]->entity->id(), $referenced_entity->id()); + $this->assertEquals($referenced_entity->id(), $entity->field_test_data[0]->entity->id()); $this->entities[] = $entity; Views::viewsData()->clear(); // Check the generated views data. $views_data = Views::viewsData()->get('entity_test__field_test_data'); - $this->assertEquals($views_data['field_test_data']['relationship']['id'], 'standard'); - $this->assertEquals($views_data['field_test_data']['relationship']['base'], 'entity_test_mul_property_data'); - $this->assertEquals($views_data['field_test_data']['relationship']['base field'], 'id'); - $this->assertEquals($views_data['field_test_data']['relationship']['relationship field'], 'field_test_data_target_id'); - $this->assertEquals($views_data['field_test_data']['relationship']['entity type'], 'entity_test_mul'); + $this->assertEquals('standard', $views_data['field_test_data']['relationship']['id']); + $this->assertEquals('entity_test_mul_property_data', $views_data['field_test_data']['relationship']['base']); + $this->assertEquals('id', $views_data['field_test_data']['relationship']['base field']); + $this->assertEquals('field_test_data_target_id', $views_data['field_test_data']['relationship']['relationship field']); + $this->assertEquals('entity_test_mul', $views_data['field_test_data']['relationship']['entity type']); // Check the backwards reference. $views_data = Views::viewsData()->get('entity_test_mul_property_data'); - $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['id'], 'entity_reverse'); - $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['base'], 'entity_test'); - $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['base field'], 'id'); - $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['field table'], 'entity_test__field_test_data'); - $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['field field'], 'field_test_data_target_id'); - $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['field_name'], 'field_test_data'); - $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['entity_type'], 'entity_test'); + $this->assertEquals('entity_reverse', $views_data['reverse__entity_test__field_test_data']['relationship']['id']); + $this->assertEquals('entity_test', $views_data['reverse__entity_test__field_test_data']['relationship']['base']); + $this->assertEquals('id', $views_data['reverse__entity_test__field_test_data']['relationship']['base field']); + $this->assertEquals('entity_test__field_test_data', $views_data['reverse__entity_test__field_test_data']['relationship']['field table']); + $this->assertEquals('field_test_data_target_id', $views_data['reverse__entity_test__field_test_data']['relationship']['field field']); + $this->assertEquals('field_test_data', $views_data['reverse__entity_test__field_test_data']['relationship']['field_name']); + $this->assertEquals('entity_test', $views_data['reverse__entity_test__field_test_data']['relationship']['entity_type']); $values = ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]; - $this->assertEquals($views_data['reverse__entity_test__field_test_data']['relationship']['join_extra'][0], $values); + $this->assertEquals($values, $views_data['reverse__entity_test__field_test_data']['relationship']['join_extra'][0]); // Check an actual test view. $view = Views::getView('test_og_standard_reference_entity_test_view'); @@ -140,18 +140,17 @@ public function testNoDataTableRelationship() { /** @var \Drupal\views\ResultRow $row */ foreach ($view->result as $index => $row) { // Check that the actual ID of the entity is the expected one. - $this->assertEquals($row->id, $this->entities[$index]->id()); + $this->assertEquals($this->entities[$index]->id(), $row->id); // Also check that we have the correct result entity. - $this->assertEquals($row->_entity->id(), $this->entities[$index]->id()); + $this->assertEquals($this->entities[$index]->id(), $row->_entity->id()); // Test the forward relationship. - $this->assertEquals($row->entity_test_mul_property_data_entity_test__field_test_data_i, 1); + $this->assertEquals(1, $row->entity_test_mul_property_data_entity_test__field_test_data_i); // Test that the correct relationship entity is on the row. - $this->assertEquals($row->_relationship_entities['field_test_data']->id(), 1); - $this->assertEquals($row->_relationship_entities['field_test_data']->bundle(), 'entity_test_mul'); - + $this->assertEquals(1, $row->_relationship_entities['field_test_data']->id()); + $this->assertEquals('entity_test_mul', $row->_relationship_entities['field_test_data']->bundle()); } // Check the backwards reference view. @@ -185,37 +184,37 @@ public function testDataTableRelationship() { $entity = EntityTestMul::create(); $entity->field_data_test->target_id = $referenced_entity->id(); $entity->save(); - $this->assertEquals($entity->field_data_test[0]->entity->id(), $referenced_entity->id()); + $this->assertEquals($referenced_entity->id(), $entity->field_data_test[0]->entity->id()); $this->entities[] = $entity; $entity = EntityTestMul::create(); $entity->field_data_test->target_id = $referenced_entity->id(); $entity->save(); - $this->assertEquals($entity->field_data_test[0]->entity->id(), $referenced_entity->id()); + $this->assertEquals($referenced_entity->id(), $entity->field_data_test[0]->entity->id()); $this->entities[] = $entity; Views::viewsData()->clear(); // Check the generated views data. $views_data = Views::viewsData()->get('entity_test_mul__field_data_test'); - $this->assertEquals($views_data['field_data_test']['relationship']['id'], 'standard'); - $this->assertEquals($views_data['field_data_test']['relationship']['base'], 'entity_test'); - $this->assertEquals($views_data['field_data_test']['relationship']['base field'], 'id'); - $this->assertEquals($views_data['field_data_test']['relationship']['relationship field'], 'field_data_test_target_id'); - $this->assertEquals($views_data['field_data_test']['relationship']['entity type'], 'entity_test'); + $this->assertEquals('standard', $views_data['field_data_test']['relationship']['id']); + $this->assertEquals('entity_test', $views_data['field_data_test']['relationship']['base']); + $this->assertEquals('id', $views_data['field_data_test']['relationship']['base field']); + $this->assertEquals('field_data_test_target_id', $views_data['field_data_test']['relationship']['relationship field']); + $this->assertEquals('entity_test', $views_data['field_data_test']['relationship']['entity type']); // Check the backwards reference. $views_data = Views::viewsData()->get('entity_test'); - $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['id'], 'entity_reverse'); - $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['base'], 'entity_test_mul_property_data'); - $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['base field'], 'id'); - $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['field table'], 'entity_test_mul__field_data_test'); - $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['field field'], 'field_data_test_target_id'); - $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['field_name'], 'field_data_test'); - $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['entity_type'], 'entity_test_mul'); + $this->assertEquals('entity_reverse', $views_data['reverse__entity_test_mul__field_data_test']['relationship']['id']); + $this->assertEquals('entity_test_mul_property_data', $views_data['reverse__entity_test_mul__field_data_test']['relationship']['base']); + $this->assertEquals('id', $views_data['reverse__entity_test_mul__field_data_test']['relationship']['base field']); + $this->assertEquals('entity_test_mul__field_data_test', $views_data['reverse__entity_test_mul__field_data_test']['relationship']['field table']); + $this->assertEquals('field_data_test_target_id', $views_data['reverse__entity_test_mul__field_data_test']['relationship']['field field']); + $this->assertEquals('field_data_test', $views_data['reverse__entity_test_mul__field_data_test']['relationship']['field_name']); + $this->assertEquals('entity_test_mul', $views_data['reverse__entity_test_mul__field_data_test']['relationship']['entity_type']); $values = ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]; - $this->assertEquals($views_data['reverse__entity_test_mul__field_data_test']['relationship']['join_extra'][0], $values); + $this->assertEquals($values, $views_data['reverse__entity_test_mul__field_data_test']['relationship']['join_extra'][0]); // Check an actual test view. $view = Views::getView('test_og_standard_reference_entity_test_mul_view'); @@ -223,17 +222,17 @@ public function testDataTableRelationship() { /** @var \Drupal\views\ResultRow $row */ foreach ($view->result as $index => $row) { // Check that the actual ID of the entity is the expected one. - $this->assertEquals($row->id, $this->entities[$index]->id()); + $this->assertEquals($this->entities[$index]->id(), $row->id); // Also check that we have the correct result entity. - $this->assertEquals($row->_entity->id(), $this->entities[$index]->id()); + $this->assertEquals($this->entities[$index]->id(), $row->_entity->id()); // Test the forward relationship. - $this->assertEquals($row->entity_test_entity_test_mul__field_data_test_id, 1); + $this->assertEquals(1, $row->entity_test_entity_test_mul__field_data_test_id); // Test that the correct relationship entity is on the row. - $this->assertEquals($row->_relationship_entities['field_data_test']->id(), 1); - $this->assertEquals($row->_relationship_entities['field_data_test']->bundle(), 'entity_test'); + $this->assertEquals(1, $row->_relationship_entities['field_data_test']->id()); + $this->assertEquals('entity_test', $row->_relationship_entities['field_data_test']->bundle()); } @@ -242,15 +241,15 @@ public function testDataTableRelationship() { $this->executeView($view); /** @var \Drupal\views\ResultRow $row */ foreach ($view->result as $index => $row) { - $this->assertEquals($row->id, 1); - $this->assertEquals($row->_entity->id(), 1); + $this->assertEquals(1, $row->id); + $this->assertEquals(1, $row->_entity->id()); // Test the backwards relationship. - $this->assertEquals($row->field_data_test_entity_test_id, $this->entities[$index]->id()); + $this->assertEquals($this->entities[$index]->id(), $row->field_data_test_entity_test_id); // Test that the correct relationship entity is on the row. - $this->assertEquals($row->_relationship_entities['reverse__entity_test_mul__field_data_test']->id(), $this->entities[$index]->id()); - $this->assertEquals($row->_relationship_entities['reverse__entity_test_mul__field_data_test']->bundle(), 'entity_test_mul'); + $this->assertEquals($this->entities[$index]->id(), $row->_relationship_entities['reverse__entity_test_mul__field_data_test']->id()); + $this->assertEquals('entity_test_mul', $row->_relationship_entities['reverse__entity_test_mul__field_data_test']->bundle()); } } From 8c3feb9f0b50e575c3010d9f36c9d01e2986d5d6 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 20:54:21 +0200 Subject: [PATCH 08/21] Testing modules --- .../og_standard_reference_test_views.info.yml | 2 +- tests/modules/og_test/og_test.info.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/modules/og_standard_reference_test_views/og_standard_reference_test_views.info.yml b/tests/modules/og_standard_reference_test_views/og_standard_reference_test_views.info.yml index e77186363..2ef5a91b8 100644 --- a/tests/modules/og_standard_reference_test_views/og_standard_reference_test_views.info.yml +++ b/tests/modules/og_standard_reference_test_views/og_standard_reference_test_views.info.yml @@ -2,6 +2,6 @@ name: 'OG standard reference test views' type: module description: 'Provides default views for views OG standard reference tests.' package: Testing -core_version_requirement: ^9 +core_version_requirement: ^9 || ^10 dependencies: - drupal:views diff --git a/tests/modules/og_test/og_test.info.yml b/tests/modules/og_test/og_test.info.yml index 3697da875..564763bc3 100644 --- a/tests/modules/og_test/og_test.info.yml +++ b/tests/modules/og_test/og_test.info.yml @@ -2,6 +2,6 @@ name: 'Organic Groups test' type: module description: 'Support module for Organic Groups testing.' package: Testing -core_version_requirement: ^9 +core_version_requirement: ^9 || ^10 dependencies: - drupal:options From c5aa0d0ef9f2e06ebd919e0f0302977e1dc5df6f Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 21:02:43 +0200 Subject: [PATCH 09/21] Follow the parent --- src/Routing/RouteSubscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php index 336ea319c..6b7959deb 100644 --- a/src/Routing/RouteSubscriber.php +++ b/src/Routing/RouteSubscriber.php @@ -165,7 +165,7 @@ protected function addRoute(RouteCollection $collection, $route_name, $path, arr * We have such a case with the "members" OG admin route, that requires Views * module to be enabled. */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { $events[RoutingEvents::ALTER] = ['onAlterRoutes', 100]; return $events; } From 6adea6e85cafa28b59fa63f7b5ae7e3fae431da0 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 21:04:47 +0200 Subject: [PATCH 10/21] Testing modules should be protected --- og_ui/tests/src/Functional/BundleFormAlterTest.php | 2 +- tests/src/Functional/GroupSubscribeFormatterTest.php | 2 +- tests/src/Functional/GroupSubscribeTest.php | 2 +- tests/src/Functional/GroupTabTest.php | 2 +- tests/src/Functional/OgComplexWidgetTest.php | 2 +- tests/src/Kernel/Access/AccessByOgMembershipTest.php | 2 +- .../src/Kernel/Access/GroupContentOperationAccessAlterTest.php | 2 +- tests/src/Kernel/Access/GroupLevelAccessTest.php | 2 +- tests/src/Kernel/Access/OgAccessHookTest.php | 2 +- tests/src/Kernel/Access/OgGroupContentOperationAccessTest.php | 2 +- tests/src/Kernel/Action/ActionTestBase.php | 2 +- tests/src/Kernel/Cache/Context/OgRoleCacheContextTest.php | 2 +- tests/src/Kernel/DefaultRoleEventIntegrationTest.php | 2 +- tests/src/Kernel/Entity/EntityCreateAccessTest.php | 2 +- tests/src/Kernel/Entity/FieldCreateTest.php | 2 +- tests/src/Kernel/Entity/GetBundleByBundleTest.php | 2 +- tests/src/Kernel/Entity/GetGroupContentTest.php | 2 +- tests/src/Kernel/Entity/GetMembershipsTest.php | 2 +- tests/src/Kernel/Entity/GetUserGroupsTest.php | 2 +- tests/src/Kernel/Entity/GroupAudienceTest.php | 2 +- tests/src/Kernel/Entity/GroupMembershipManagerTest.php | 2 +- tests/src/Kernel/Entity/GroupTypeTest.php | 2 +- tests/src/Kernel/Entity/OgMembershipRoleReferenceTest.php | 2 +- tests/src/Kernel/Entity/OgMembershipTest.php | 2 +- tests/src/Kernel/Entity/OgRoleTest.php | 2 +- tests/src/Kernel/Entity/OgStandardReferenceItemTest.php | 2 +- tests/src/Kernel/Entity/ReferenceStringIdTest.php | 2 +- tests/src/Kernel/Entity/SelectionHandlerTest.php | 2 +- .../Views/OgStandardReferenceRelationshipTest.php | 2 +- tests/src/Kernel/Field/AudienceFieldFormatterTest.php | 2 +- tests/src/Kernel/Form/GroupSubscribeFormTest.php | 2 +- tests/src/Kernel/GroupManagerSubscriptionTest.php | 2 +- tests/src/Kernel/GroupTypeConditionTest.php | 2 +- tests/src/Kernel/OgDeleteOrphansTest.php | 2 +- tests/src/Kernel/OgRoleManagerTest.php | 2 +- tests/src/Kernel/PermissionEventTest.php | 2 +- tests/src/Kernel/Views/OgAdminMembersViewTest.php | 2 +- 37 files changed, 37 insertions(+), 37 deletions(-) diff --git a/og_ui/tests/src/Functional/BundleFormAlterTest.php b/og_ui/tests/src/Functional/BundleFormAlterTest.php index 6e2a38b99..7768bf837 100644 --- a/og_ui/tests/src/Functional/BundleFormAlterTest.php +++ b/og_ui/tests/src/Functional/BundleFormAlterTest.php @@ -21,7 +21,7 @@ class BundleFormAlterTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['block_content', 'entity_test', 'node', 'og_ui']; + protected static $modules = ['block_content', 'entity_test', 'node', 'og_ui']; /** * {@inheritdoc} diff --git a/tests/src/Functional/GroupSubscribeFormatterTest.php b/tests/src/Functional/GroupSubscribeFormatterTest.php index 733a14f0a..249d24484 100644 --- a/tests/src/Functional/GroupSubscribeFormatterTest.php +++ b/tests/src/Functional/GroupSubscribeFormatterTest.php @@ -21,7 +21,7 @@ class GroupSubscribeFormatterTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['node', 'og', 'options']; + protected static $modules = ['node', 'og', 'options']; /** * {@inheritdoc} diff --git a/tests/src/Functional/GroupSubscribeTest.php b/tests/src/Functional/GroupSubscribeTest.php index ce66ce307..f6b19eb1f 100644 --- a/tests/src/Functional/GroupSubscribeTest.php +++ b/tests/src/Functional/GroupSubscribeTest.php @@ -27,7 +27,7 @@ class GroupSubscribeTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['node', 'og']; + protected static $modules = ['node', 'og']; /** * {@inheritdoc} diff --git a/tests/src/Functional/GroupTabTest.php b/tests/src/Functional/GroupTabTest.php index cb489d8ab..ca9a1503b 100644 --- a/tests/src/Functional/GroupTabTest.php +++ b/tests/src/Functional/GroupTabTest.php @@ -29,7 +29,7 @@ class GroupTabTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['node', 'og', 'views', 'entity_test']; + protected static $modules = ['node', 'og', 'views', 'entity_test']; /** * {@inheritdoc} diff --git a/tests/src/Functional/OgComplexWidgetTest.php b/tests/src/Functional/OgComplexWidgetTest.php index 28fbe54ba..df1d05105 100644 --- a/tests/src/Functional/OgComplexWidgetTest.php +++ b/tests/src/Functional/OgComplexWidgetTest.php @@ -26,7 +26,7 @@ class OgComplexWidgetTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = ['block_content', 'node', 'og']; + protected static $modules = ['block_content', 'node', 'og']; /** * {@inheritdoc} diff --git a/tests/src/Kernel/Access/AccessByOgMembershipTest.php b/tests/src/Kernel/Access/AccessByOgMembershipTest.php index 2a60deee9..f53006f9e 100644 --- a/tests/src/Kernel/Access/AccessByOgMembershipTest.php +++ b/tests/src/Kernel/Access/AccessByOgMembershipTest.php @@ -34,7 +34,7 @@ class AccessByOgMembershipTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'block_content', 'field', 'node', diff --git a/tests/src/Kernel/Access/GroupContentOperationAccessAlterTest.php b/tests/src/Kernel/Access/GroupContentOperationAccessAlterTest.php index b144cdbb2..bc914857e 100644 --- a/tests/src/Kernel/Access/GroupContentOperationAccessAlterTest.php +++ b/tests/src/Kernel/Access/GroupContentOperationAccessAlterTest.php @@ -26,7 +26,7 @@ class GroupContentOperationAccessAlterTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'comment', 'entity_test', 'field', diff --git a/tests/src/Kernel/Access/GroupLevelAccessTest.php b/tests/src/Kernel/Access/GroupLevelAccessTest.php index 3185e3d81..29392035d 100644 --- a/tests/src/Kernel/Access/GroupLevelAccessTest.php +++ b/tests/src/Kernel/Access/GroupLevelAccessTest.php @@ -25,7 +25,7 @@ class GroupLevelAccessTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'system', 'user', 'field', diff --git a/tests/src/Kernel/Access/OgAccessHookTest.php b/tests/src/Kernel/Access/OgAccessHookTest.php index 36765d11e..c5d71c1ff 100644 --- a/tests/src/Kernel/Access/OgAccessHookTest.php +++ b/tests/src/Kernel/Access/OgAccessHookTest.php @@ -30,7 +30,7 @@ class OgAccessHookTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'block_content', 'field', 'node', diff --git a/tests/src/Kernel/Access/OgGroupContentOperationAccessTest.php b/tests/src/Kernel/Access/OgGroupContentOperationAccessTest.php index ac933989f..81b6cc98f 100644 --- a/tests/src/Kernel/Access/OgGroupContentOperationAccessTest.php +++ b/tests/src/Kernel/Access/OgGroupContentOperationAccessTest.php @@ -28,7 +28,7 @@ class OgGroupContentOperationAccessTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'comment', 'entity_test', 'field', diff --git a/tests/src/Kernel/Action/ActionTestBase.php b/tests/src/Kernel/Action/ActionTestBase.php index a7d965ed1..6640c3498 100644 --- a/tests/src/Kernel/Action/ActionTestBase.php +++ b/tests/src/Kernel/Action/ActionTestBase.php @@ -33,7 +33,7 @@ abstract class ActionTestBase extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['node', 'og', 'system', 'user', 'options']; + protected static $modules = ['node', 'og', 'system', 'user', 'options']; /** * An array of test users. diff --git a/tests/src/Kernel/Cache/Context/OgRoleCacheContextTest.php b/tests/src/Kernel/Cache/Context/OgRoleCacheContextTest.php index 87d3aeebc..e8057fff4 100644 --- a/tests/src/Kernel/Cache/Context/OgRoleCacheContextTest.php +++ b/tests/src/Kernel/Cache/Context/OgRoleCacheContextTest.php @@ -32,7 +32,7 @@ class OgRoleCacheContextTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'node', 'og', diff --git a/tests/src/Kernel/DefaultRoleEventIntegrationTest.php b/tests/src/Kernel/DefaultRoleEventIntegrationTest.php index f94e3581e..c1d0b0530 100644 --- a/tests/src/Kernel/DefaultRoleEventIntegrationTest.php +++ b/tests/src/Kernel/DefaultRoleEventIntegrationTest.php @@ -20,7 +20,7 @@ class DefaultRoleEventIntegrationTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['entity_test', 'og', 'system', 'user', 'field']; + protected static $modules = ['entity_test', 'og', 'system', 'user', 'field']; /** * The Symfony event dispatcher. diff --git a/tests/src/Kernel/Entity/EntityCreateAccessTest.php b/tests/src/Kernel/Entity/EntityCreateAccessTest.php index a8c57392d..c2c7d2fe3 100644 --- a/tests/src/Kernel/Entity/EntityCreateAccessTest.php +++ b/tests/src/Kernel/Entity/EntityCreateAccessTest.php @@ -29,7 +29,7 @@ class EntityCreateAccessTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'field', 'node', 'og', diff --git a/tests/src/Kernel/Entity/FieldCreateTest.php b/tests/src/Kernel/Entity/FieldCreateTest.php index 3a21d2b15..6c47e6c70 100644 --- a/tests/src/Kernel/Entity/FieldCreateTest.php +++ b/tests/src/Kernel/Entity/FieldCreateTest.php @@ -21,7 +21,7 @@ class FieldCreateTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'user', 'field', 'node', diff --git a/tests/src/Kernel/Entity/GetBundleByBundleTest.php b/tests/src/Kernel/Entity/GetBundleByBundleTest.php index c063e11ff..77b1587a6 100644 --- a/tests/src/Kernel/Entity/GetBundleByBundleTest.php +++ b/tests/src/Kernel/Entity/GetBundleByBundleTest.php @@ -22,7 +22,7 @@ class GetBundleByBundleTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'block_content', 'field', 'node', diff --git a/tests/src/Kernel/Entity/GetGroupContentTest.php b/tests/src/Kernel/Entity/GetGroupContentTest.php index 3dbc1bff6..b7c336d9e 100644 --- a/tests/src/Kernel/Entity/GetGroupContentTest.php +++ b/tests/src/Kernel/Entity/GetGroupContentTest.php @@ -23,7 +23,7 @@ class GetGroupContentTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'field', 'node', diff --git a/tests/src/Kernel/Entity/GetMembershipsTest.php b/tests/src/Kernel/Entity/GetMembershipsTest.php index e4e192ceb..89c66882b 100644 --- a/tests/src/Kernel/Entity/GetMembershipsTest.php +++ b/tests/src/Kernel/Entity/GetMembershipsTest.php @@ -25,7 +25,7 @@ class GetMembershipsTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'field', 'node', diff --git a/tests/src/Kernel/Entity/GetUserGroupsTest.php b/tests/src/Kernel/Entity/GetUserGroupsTest.php index caadd6161..581a3cbff 100644 --- a/tests/src/Kernel/Entity/GetUserGroupsTest.php +++ b/tests/src/Kernel/Entity/GetUserGroupsTest.php @@ -26,7 +26,7 @@ class GetUserGroupsTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'system', 'user', 'field', diff --git a/tests/src/Kernel/Entity/GroupAudienceTest.php b/tests/src/Kernel/Entity/GroupAudienceTest.php index 192ce6cd2..bce8f7c8b 100644 --- a/tests/src/Kernel/Entity/GroupAudienceTest.php +++ b/tests/src/Kernel/Entity/GroupAudienceTest.php @@ -26,7 +26,7 @@ class GroupAudienceTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_reference', 'entity_test', 'field', diff --git a/tests/src/Kernel/Entity/GroupMembershipManagerTest.php b/tests/src/Kernel/Entity/GroupMembershipManagerTest.php index 74448eb26..ecc4d2851 100644 --- a/tests/src/Kernel/Entity/GroupMembershipManagerTest.php +++ b/tests/src/Kernel/Entity/GroupMembershipManagerTest.php @@ -32,7 +32,7 @@ class GroupMembershipManagerTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'field', 'node', diff --git a/tests/src/Kernel/Entity/GroupTypeTest.php b/tests/src/Kernel/Entity/GroupTypeTest.php index d9191bf73..0021c9261 100644 --- a/tests/src/Kernel/Entity/GroupTypeTest.php +++ b/tests/src/Kernel/Entity/GroupTypeTest.php @@ -17,7 +17,7 @@ class GroupTypeTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['field', 'node', 'og', 'options', 'system', 'user']; + protected static $modules = ['field', 'node', 'og', 'options', 'system', 'user']; /** * The group type manager. diff --git a/tests/src/Kernel/Entity/OgMembershipRoleReferenceTest.php b/tests/src/Kernel/Entity/OgMembershipRoleReferenceTest.php index fbdf9fb12..202590985 100644 --- a/tests/src/Kernel/Entity/OgMembershipRoleReferenceTest.php +++ b/tests/src/Kernel/Entity/OgMembershipRoleReferenceTest.php @@ -22,7 +22,7 @@ class OgMembershipRoleReferenceTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'field', 'node', 'og', diff --git a/tests/src/Kernel/Entity/OgMembershipTest.php b/tests/src/Kernel/Entity/OgMembershipTest.php index 2b52278bd..c58913cd1 100644 --- a/tests/src/Kernel/Entity/OgMembershipTest.php +++ b/tests/src/Kernel/Entity/OgMembershipTest.php @@ -29,7 +29,7 @@ class OgMembershipTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'field', 'node', diff --git a/tests/src/Kernel/Entity/OgRoleTest.php b/tests/src/Kernel/Entity/OgRoleTest.php index 089bd2aab..1488a49dd 100644 --- a/tests/src/Kernel/Entity/OgRoleTest.php +++ b/tests/src/Kernel/Entity/OgRoleTest.php @@ -22,7 +22,7 @@ class OgRoleTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'field', 'node', diff --git a/tests/src/Kernel/Entity/OgStandardReferenceItemTest.php b/tests/src/Kernel/Entity/OgStandardReferenceItemTest.php index d981cd8cd..40e8e7c5c 100644 --- a/tests/src/Kernel/Entity/OgStandardReferenceItemTest.php +++ b/tests/src/Kernel/Entity/OgStandardReferenceItemTest.php @@ -20,7 +20,7 @@ class OgStandardReferenceItemTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'user', 'entity_test', 'field', diff --git a/tests/src/Kernel/Entity/ReferenceStringIdTest.php b/tests/src/Kernel/Entity/ReferenceStringIdTest.php index 2467dfd0d..209b240d0 100644 --- a/tests/src/Kernel/Entity/ReferenceStringIdTest.php +++ b/tests/src/Kernel/Entity/ReferenceStringIdTest.php @@ -19,7 +19,7 @@ class ReferenceStringIdTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'user', 'entity_test', 'field', diff --git a/tests/src/Kernel/Entity/SelectionHandlerTest.php b/tests/src/Kernel/Entity/SelectionHandlerTest.php index eb2fb14fc..4fefe90c1 100644 --- a/tests/src/Kernel/Entity/SelectionHandlerTest.php +++ b/tests/src/Kernel/Entity/SelectionHandlerTest.php @@ -29,7 +29,7 @@ class SelectionHandlerTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'system', 'user', 'field', diff --git a/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php b/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php index 7ea82299d..145a99178 100644 --- a/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php +++ b/tests/src/Kernel/EntityReference/Views/OgStandardReferenceRelationshipTest.php @@ -38,7 +38,7 @@ class OgStandardReferenceRelationshipTest extends ViewsKernelTestBase { * * @var array */ - public static $modules = [ + protected static $modules = [ 'user', 'field', 'entity_test', diff --git a/tests/src/Kernel/Field/AudienceFieldFormatterTest.php b/tests/src/Kernel/Field/AudienceFieldFormatterTest.php index 69cb3de37..b5c1a7145 100644 --- a/tests/src/Kernel/Field/AudienceFieldFormatterTest.php +++ b/tests/src/Kernel/Field/AudienceFieldFormatterTest.php @@ -17,7 +17,7 @@ class AudienceFieldFormatterTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['field', 'og']; + protected static $modules = ['field', 'og']; /** * Testing og_field_formatter_info_alter(). diff --git a/tests/src/Kernel/Form/GroupSubscribeFormTest.php b/tests/src/Kernel/Form/GroupSubscribeFormTest.php index 0c46be0f1..5643122be 100644 --- a/tests/src/Kernel/Form/GroupSubscribeFormTest.php +++ b/tests/src/Kernel/Form/GroupSubscribeFormTest.php @@ -26,7 +26,7 @@ class GroupSubscribeFormTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'system', 'user', 'field', diff --git a/tests/src/Kernel/GroupManagerSubscriptionTest.php b/tests/src/Kernel/GroupManagerSubscriptionTest.php index d4a0880a4..f6dbfffb9 100644 --- a/tests/src/Kernel/GroupManagerSubscriptionTest.php +++ b/tests/src/Kernel/GroupManagerSubscriptionTest.php @@ -21,7 +21,7 @@ class GroupManagerSubscriptionTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'field', 'node', 'og', diff --git a/tests/src/Kernel/GroupTypeConditionTest.php b/tests/src/Kernel/GroupTypeConditionTest.php index 0a9ac13a8..d2622e72d 100644 --- a/tests/src/Kernel/GroupTypeConditionTest.php +++ b/tests/src/Kernel/GroupTypeConditionTest.php @@ -19,7 +19,7 @@ class GroupTypeConditionTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'field', 'node', diff --git a/tests/src/Kernel/OgDeleteOrphansTest.php b/tests/src/Kernel/OgDeleteOrphansTest.php index d19ad1edf..8301e204b 100644 --- a/tests/src/Kernel/OgDeleteOrphansTest.php +++ b/tests/src/Kernel/OgDeleteOrphansTest.php @@ -21,7 +21,7 @@ class OgDeleteOrphansTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'system', 'user', 'field', diff --git a/tests/src/Kernel/OgRoleManagerTest.php b/tests/src/Kernel/OgRoleManagerTest.php index 7935a0aad..62f07ce81 100644 --- a/tests/src/Kernel/OgRoleManagerTest.php +++ b/tests/src/Kernel/OgRoleManagerTest.php @@ -21,7 +21,7 @@ class OgRoleManagerTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'field', 'node', diff --git a/tests/src/Kernel/PermissionEventTest.php b/tests/src/Kernel/PermissionEventTest.php index d39dd261e..98e164158 100644 --- a/tests/src/Kernel/PermissionEventTest.php +++ b/tests/src/Kernel/PermissionEventTest.php @@ -25,7 +25,7 @@ class PermissionEventTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'field', 'node', diff --git a/tests/src/Kernel/Views/OgAdminMembersViewTest.php b/tests/src/Kernel/Views/OgAdminMembersViewTest.php index 450292a9c..bbbf84ec7 100644 --- a/tests/src/Kernel/Views/OgAdminMembersViewTest.php +++ b/tests/src/Kernel/Views/OgAdminMembersViewTest.php @@ -23,7 +23,7 @@ class OgAdminMembersViewTest extends ViewsKernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'system', 'user', 'field', From cbcf77c8afdb283d3de72f7df59c24b839b12834 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 21:09:13 +0200 Subject: [PATCH 11/21] Fix og_ui metadata --- og_ui/og_ui.info.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/og_ui/og_ui.info.yml b/og_ui/og_ui.info.yml index 8e6167799..3554fb47a 100644 --- a/og_ui/og_ui.info.yml +++ b/og_ui/og_ui.info.yml @@ -3,9 +3,9 @@ description: User interface for Organic Groups. package: Organic Groups type: module -core_version_requirement: ^9 +core_version_requirement: ^9 || ^10 dependencies: - - og + - og:og configure: og_ui.admin_index From 2d138df03c34726499ecddfcfb6ce28c5b354dce Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sat, 19 Nov 2022 21:09:59 +0200 Subject: [PATCH 12/21] Compatibility with parent --- src/Event/DefaultRoleEvent.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Event/DefaultRoleEvent.php b/src/Event/DefaultRoleEvent.php index ffea7e884..86ed55715 100644 --- a/src/Event/DefaultRoleEvent.php +++ b/src/Event/DefaultRoleEvent.php @@ -97,6 +97,7 @@ public function hasRole($name) { /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function offsetGet($key) { return $this->getRole($key); } @@ -104,7 +105,7 @@ public function offsetGet($key) { /** * {@inheritdoc} */ - public function offsetSet($key, $role) { + public function offsetSet($key, $role): void { $this->validate($role); if ($role->getName() !== $key) { throw new \InvalidArgumentException('The key and the "name" property of the role should be identical.'); @@ -115,21 +116,21 @@ public function offsetSet($key, $role) { /** * {@inheritdoc} */ - public function offsetUnset($key) { + public function offsetUnset($key): void { $this->deleteRole($key); } /** * {@inheritdoc} */ - public function offsetExists($key) { + public function offsetExists($key): bool { return $this->hasRole($key); } /** * {@inheritdoc} */ - public function getIterator() { + public function getIterator(): \Traversable { return new \ArrayIterator($this->roles); } From 81229f41cd469cbb627a18b4b32834259162f3cb Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 20 Nov 2022 00:06:49 +0200 Subject: [PATCH 13/21] More D10 conversions --- src/Entity/OgMembership.php | 4 ++-- src/Entity/OgRole.php | 9 +++++++++ src/MembershipManager.php | 4 ++++ src/OgDeleteOrphansBase.php | 1 + .../UniqueOgMembershipConstraintValidator.php | 1 + tests/src/Functional/GroupTabTest.php | 12 +++++++----- ...ChangeMultipleOgMembershipRolesActionTestBase.php | 2 -- tests/src/Kernel/Entity/EntityCreateAccessTest.php | 11 +++++------ tests/src/Kernel/Entity/GetMembershipsTest.php | 1 + tests/src/Kernel/Entity/GroupAudienceTest.php | 1 - .../Kernel/Entity/OgStandardReferenceItemTest.php | 4 +++- tests/src/Kernel/Entity/ReferenceStringIdTest.php | 4 +++- tests/src/Kernel/Entity/SelectionHandlerTest.php | 1 - tests/src/Kernel/OgDeleteOrphansTest.php | 3 +-- tests/src/Unit/OgRoleManagerTest.php | 8 ++++++++ 15 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/Entity/OgMembership.php b/src/Entity/OgMembership.php index e43e271cc..0b2294b67 100644 --- a/src/Entity/OgMembership.php +++ b/src/Entity/OgMembership.php @@ -544,8 +544,8 @@ public function preSave(EntityStorageInterface $storage) { } // Check for an existing membership. - $query = \Drupal::entityQuery('og_membership'); - $query + $query = \Drupal::entityQuery('og_membership') + ->accessCheck() ->condition('uid', $uid) ->condition('entity_id', $entity_id) ->condition('entity_type', $this->get('entity_type')->value); diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 89361ad41..a3b1d26e6 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -323,7 +323,16 @@ protected function ogAccess() { * {@inheritdoc} */ public function calculateDependencies() { + // The parent method is checking for the existence of each role-assigned + // permission. But in OG this isn't mandatory. Backup the permissions before + // calling the parent method and avoid preforming the check. + // @see https://www.drupal.org/node/3193348 + // @todo Consider decoupling 'og_role' from 'role' entity config and + // implementing the missing methods in 'og_role'. + $permissions = $this->permissions; + $this->permissions = []; parent::calculateDependencies(); + $this->permissions = $permissions; // Create a dependency on the group bundle. $bundle_config_dependency = \Drupal::entityTypeManager()->getDefinition($this->getGroupType())->getBundleConfigDependency($this->getGroupBundle()); diff --git a/src/MembershipManager.php b/src/MembershipManager.php index cf5e720b9..8cdb0e6af 100644 --- a/src/MembershipManager.php +++ b/src/MembershipManager.php @@ -113,6 +113,7 @@ public function getMemberships($user_id, array $states = [OgMembershipInterface: $query = $this->entityTypeManager ->getStorage('og_membership') ->getQuery() + ->accessCheck() ->condition('uid', $user_id) ->condition('state', $states, 'IN'); @@ -185,6 +186,7 @@ public function getGroupMembershipCount(EntityInterface $group, array $states = $query = $this->entityTypeManager ->getStorage('og_membership') ->getQuery() + ->accessCheck() ->condition('entity_id', $group->id()); if ($states) { @@ -231,6 +233,7 @@ public function getGroupMembershipIdsByRoleNames(EntityInterface $group, array $ $query = $this->entityTypeManager ->getStorage('og_membership') ->getQuery() + ->accessCheck() ->condition('entity_type', $entity_type_id) ->condition('entity_id', $group->id()) ->condition('state', $states, 'IN'); @@ -418,6 +421,7 @@ public function getGroupContentIds(EntityInterface $entity, array $entity_types $results = $this->entityTypeManager ->getStorage($group_content_entity_type) ->getQuery() + ->accessCheck() ->condition($field->getName() . '.target_id', $entity->id()) ->execute(); diff --git a/src/OgDeleteOrphansBase.php b/src/OgDeleteOrphansBase.php index 9d25b3012..fc5d483f0 100644 --- a/src/OgDeleteOrphansBase.php +++ b/src/OgDeleteOrphansBase.php @@ -120,6 +120,7 @@ protected function query(EntityInterface $entity) { // Register orphaned user memberships. $membership_ids = $this->entityTypeManager->getStorage('og_membership') ->getQuery() + ->accessCheck() ->condition('entity_type', $entity->getEntityTypeId()) ->condition('entity_id', $entity->id()) ->execute(); diff --git a/src/Plugin/Validation/Constraint/UniqueOgMembershipConstraintValidator.php b/src/Plugin/Validation/Constraint/UniqueOgMembershipConstraintValidator.php index bfcb33904..90cea2d73 100644 --- a/src/Plugin/Validation/Constraint/UniqueOgMembershipConstraintValidator.php +++ b/src/Plugin/Validation/Constraint/UniqueOgMembershipConstraintValidator.php @@ -76,6 +76,7 @@ public function validate($value, Constraint $constraint) { $query = $this->entityTypeManager ->getStorage('og_membership') ->getQuery() + ->accessCheck() ->condition('entity_type', $entity->getGroupEntityType()) ->condition('entity_id', $entity->getGroupId()) ->condition('uid', $new_member_uid); diff --git a/tests/src/Functional/GroupTabTest.php b/tests/src/Functional/GroupTabTest.php index ca9a1503b..be7588303 100644 --- a/tests/src/Functional/GroupTabTest.php +++ b/tests/src/Functional/GroupTabTest.php @@ -220,12 +220,14 @@ public function testMembershipAdd() { $value = $exiting_member->getDisplayName() . ' (' . $exiting_member->id() . ')'; $this->submitForm(['Username' => $value], 'Save'); $this->assertSession()->pageTextMatches('/The user .+ is already a member in this group/'); - // Test entity query match. - $query = $entity_type_manger->getStorage('user')->getQuery(); - $query->condition('uid', 0, '<>'); $match = 'adminz'; - $query->condition('name', $match, 'CONTAINS'); - $found = $query->execute(); + // Test entity query match. + $found = $entity_type_manger->getStorage('user') + ->getQuery() + ->accessCheck() + ->condition('uid', 0, '<>') + ->condition('name', $match, 'CONTAINS') + ->execute(); $this->assertCount(3, $found, print_r($found, TRUE)); // Two of the three possible matches are already members. $this->assertAutoCompleteMatches($group, $match, 1); diff --git a/tests/src/Kernel/Action/ChangeMultipleOgMembershipRolesActionTestBase.php b/tests/src/Kernel/Action/ChangeMultipleOgMembershipRolesActionTestBase.php index 0b5bfab74..16aed4996 100644 --- a/tests/src/Kernel/Action/ChangeMultipleOgMembershipRolesActionTestBase.php +++ b/tests/src/Kernel/Action/ChangeMultipleOgMembershipRolesActionTestBase.php @@ -29,8 +29,6 @@ class ChangeMultipleOgMembershipRolesActionTestBase extends ChangeOgMembershipAc protected function setUp(): void { parent::setUp(); - $this->installSchema('system', ['key_value_expire']); - $this->tempStorageFactory = $this->container->get('tempstore.private'); // Set up the group administrator as the user that will be logged in during diff --git a/tests/src/Kernel/Entity/EntityCreateAccessTest.php b/tests/src/Kernel/Entity/EntityCreateAccessTest.php index c2c7d2fe3..3109e5033 100644 --- a/tests/src/Kernel/Entity/EntityCreateAccessTest.php +++ b/tests/src/Kernel/Entity/EntityCreateAccessTest.php @@ -4,6 +4,8 @@ namespace Drupal\Tests\og\Kernel\Entity; +use Drupal\Core\Access\AccessResultAllowed; +use Drupal\Core\Url; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\node\Traits\ContentTypeCreationTrait; use Drupal\Tests\node\Traits\NodeCreationTrait; @@ -115,18 +117,15 @@ public function testViewPermissionDoesNotGrantCreateAccess() { // Verify that the user does not have access to the entity create form of // the group content type. - /** @var \Drupal\node\Access\NodeAddAccessCheck $node_access_check */ - $node_access_check = $this->container->get('access_check.node.add'); - $result = $node_access_check->access(User::getAnonymousUser(), $this->groupContentType); - $this->assertNotInstanceOf('\Drupal\Core\Access\AccessResultAllowed', $result); + $url = Url::fromRoute('node.add_page'); + $this->assertNotInstanceOf(AccessResultAllowed::class, $url->access(User::getAnonymousUser(), TRUE)); // Test that the user can access the entity create form when the permission // to create group content is granted. Note that node access control is // cached, so we need to reset it when we change permissions. $this->container->get('entity_type.manager')->getAccessControlHandler('node')->resetCache(); $role->grantPermission('create post content')->trustData()->save(); - $result = $node_access_check->access(User::getAnonymousUser(), $this->groupContentType); - $this->assertInstanceOf('\Drupal\Core\Access\AccessResultAllowed', $result); + $this->assertInstanceOf('\Drupal\Core\Access\AccessResultAllowed', $url->access(User::getAnonymousUser(), TRUE)); } } diff --git a/tests/src/Kernel/Entity/GetMembershipsTest.php b/tests/src/Kernel/Entity/GetMembershipsTest.php index 89c66882b..6dd3f6991 100644 --- a/tests/src/Kernel/Entity/GetMembershipsTest.php +++ b/tests/src/Kernel/Entity/GetMembershipsTest.php @@ -278,6 +278,7 @@ public function testOrphanedMembershipsDeletion() { $memberships = $this->entityTypeManager ->getStorage('og_membership') ->getQuery() + ->accessCheck() ->condition('uid', $user_id) ->execute(); diff --git a/tests/src/Kernel/Entity/GroupAudienceTest.php b/tests/src/Kernel/Entity/GroupAudienceTest.php index bce8f7c8b..95f813a13 100644 --- a/tests/src/Kernel/Entity/GroupAudienceTest.php +++ b/tests/src/Kernel/Entity/GroupAudienceTest.php @@ -27,7 +27,6 @@ class GroupAudienceTest extends KernelTestBase { * {@inheritdoc} */ protected static $modules = [ - 'entity_reference', 'entity_test', 'field', 'og', diff --git a/tests/src/Kernel/Entity/OgStandardReferenceItemTest.php b/tests/src/Kernel/Entity/OgStandardReferenceItemTest.php index 40e8e7c5c..4c7cac983 100644 --- a/tests/src/Kernel/Entity/OgStandardReferenceItemTest.php +++ b/tests/src/Kernel/Entity/OgStandardReferenceItemTest.php @@ -90,7 +90,9 @@ protected function setUp(): void { */ public function testStandardReference() { $groups_query = function ($gid) { - return $this->container->get('entity_type.manager')->getStorage('entity_test')->getQuery() + return $this->container->get('entity_type.manager')->getStorage('entity_test') + ->getQuery() + ->accessCheck() ->condition($this->fieldName, $gid) ->execute(); }; diff --git a/tests/src/Kernel/Entity/ReferenceStringIdTest.php b/tests/src/Kernel/Entity/ReferenceStringIdTest.php index 209b240d0..2f551ba22 100644 --- a/tests/src/Kernel/Entity/ReferenceStringIdTest.php +++ b/tests/src/Kernel/Entity/ReferenceStringIdTest.php @@ -106,7 +106,9 @@ public function testReferencingStringIds() { $entity->save(); // Check that the group content entity is referenced. - $references = $this->container->get('entity_type.manager')->getStorage('entity_test_string_id')->getQuery() + $references = $this->container->get('entity_type.manager')->getStorage('entity_test_string_id') + ->getQuery() + ->accessCheck() ->condition($this->fieldName, $this->group->id()) ->execute(); $this->assertEquals([$entity->id()], array_keys($references), 'The correct group is referenced.'); diff --git a/tests/src/Kernel/Entity/SelectionHandlerTest.php b/tests/src/Kernel/Entity/SelectionHandlerTest.php index 4fefe90c1..0d5da117e 100644 --- a/tests/src/Kernel/Entity/SelectionHandlerTest.php +++ b/tests/src/Kernel/Entity/SelectionHandlerTest.php @@ -33,7 +33,6 @@ class SelectionHandlerTest extends KernelTestBase { 'system', 'user', 'field', - 'entity_reference', 'node', 'og', 'options', diff --git a/tests/src/Kernel/OgDeleteOrphansTest.php b/tests/src/Kernel/OgDeleteOrphansTest.php index 8301e204b..07325f14e 100644 --- a/tests/src/Kernel/OgDeleteOrphansTest.php +++ b/tests/src/Kernel/OgDeleteOrphansTest.php @@ -25,7 +25,6 @@ class OgDeleteOrphansTest extends KernelTestBase { 'system', 'user', 'field', - 'entity_reference', 'node', 'og', 'options', @@ -256,7 +255,7 @@ protected function assertQueueCount($queue_id, $count) { * The expected number of user memberships. */ protected function assertUserMembershipCount($expected) { - $count = \Drupal::entityQuery('og_membership')->count()->execute(); + $count = \Drupal::entityQuery('og_membership')->accessCheck()->count()->execute(); $this->assertEquals($expected, $count); } diff --git a/tests/src/Unit/OgRoleManagerTest.php b/tests/src/Unit/OgRoleManagerTest.php index b56e33b52..17e0568da 100644 --- a/tests/src/Unit/OgRoleManagerTest.php +++ b/tests/src/Unit/OgRoleManagerTest.php @@ -6,11 +6,14 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\og\Event\DefaultRoleEvent; +use Drupal\og\Event\DefaultRoleEventInterface; use Drupal\Tests\UnitTestCase; use Drupal\og\Entity\OgRole; use Drupal\og\OgRoleInterface; use Drupal\og\OgRoleManager; use Drupal\og\PermissionManagerInterface; +use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -231,6 +234,11 @@ public function testRoleRemoval() { * The initialized OG role manager. */ protected function getOgRoleManager() { + $this->eventDispatcher + ->dispatch( + Argument::type(DefaultRoleEvent::class), + DefaultRoleEventInterface::EVENT_NAME, + )->willReturnArgument(); return new OgRoleManager( $this->entityTypeManager->reveal(), $this->eventDispatcher->reveal(), From c5c3d2f481a4691cf38b3397f115dc2bf3c88edf Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 20 Nov 2022 00:40:16 +0200 Subject: [PATCH 14/21] Typo --- src/Entity/OgRole.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index a3b1d26e6..882664936 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -325,7 +325,7 @@ protected function ogAccess() { public function calculateDependencies() { // The parent method is checking for the existence of each role-assigned // permission. But in OG this isn't mandatory. Backup the permissions before - // calling the parent method and avoid preforming the check. + // calling the parent method and avoid performing the check. // @see https://www.drupal.org/node/3193348 // @todo Consider decoupling 'og_role' from 'role' entity config and // implementing the missing methods in 'og_role'. From 7744526c9b2c736d3bd1630c10eca1b2914dacc4 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 20 Nov 2022 00:41:28 +0200 Subject: [PATCH 15/21] Entity query access --- tests/src/Functional/OgComplexWidgetTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/src/Functional/OgComplexWidgetTest.php b/tests/src/Functional/OgComplexWidgetTest.php index df1d05105..898f39294 100644 --- a/tests/src/Functional/OgComplexWidgetTest.php +++ b/tests/src/Functional/OgComplexWidgetTest.php @@ -95,8 +95,9 @@ public function testFields($field, $field_name) { $this->assertSession()->statusCodeEquals(200); // Retrieve the post that was created from the database. - $query = $this->container->get('entity_type.manager')->getStorage('node')->getQuery(); - $result = $query + $result = $this->container->get('entity_type.manager')->getStorage('node') + ->getQuery() + ->accessCheck() ->condition('type', 'post') ->range(0, 1) ->sort('nid', 'DESC') From 77f0ac0ed803823b3c8c485b2cc8a42db89a4311 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 20 Nov 2022 00:41:43 +0200 Subject: [PATCH 16/21] PHP CS --- tests/src/Kernel/Entity/GroupTypeTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/src/Kernel/Entity/GroupTypeTest.php b/tests/src/Kernel/Entity/GroupTypeTest.php index 0021c9261..fb5c3326e 100644 --- a/tests/src/Kernel/Entity/GroupTypeTest.php +++ b/tests/src/Kernel/Entity/GroupTypeTest.php @@ -17,7 +17,14 @@ class GroupTypeTest extends KernelTestBase { /** * {@inheritdoc} */ - protected static $modules = ['field', 'node', 'og', 'options', 'system', 'user']; + protected static $modules = [ + 'field', + 'node', + 'og', + 'options', + 'system', + 'user', + ]; /** * The group type manager. From 62a4613675d2b6eb8aaf50be33e23df14a0ca48f Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 20 Nov 2022 01:23:16 +0200 Subject: [PATCH 17/21] Provide the block label --- tests/src/Functional/OgComplexWidgetTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/src/Functional/OgComplexWidgetTest.php b/tests/src/Functional/OgComplexWidgetTest.php index 898f39294..6fa9eccb7 100644 --- a/tests/src/Functional/OgComplexWidgetTest.php +++ b/tests/src/Functional/OgComplexWidgetTest.php @@ -78,6 +78,7 @@ public function testFields($field, $field_name) { $values = [ 'type' => 'group', 'uid' => $group_owner->id(), + 'info' => $this->randomString(), ]; $group = BlockContent::create($values); $group->save(); From 404391a5646f7b369d0063be9dee9c42ffddefa6 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 20 Nov 2022 11:36:15 +0200 Subject: [PATCH 18/21] Site is installed in a subdirectory --- tests/src/Functional/GroupTabTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/src/Functional/GroupTabTest.php b/tests/src/Functional/GroupTabTest.php index be7588303..e3256e533 100644 --- a/tests/src/Functional/GroupTabTest.php +++ b/tests/src/Functional/GroupTabTest.php @@ -364,6 +364,10 @@ protected function assertAutoCompleteMatches(EntityInterface $group, string $mat $page = $this->getSession()->getPage(); $input = $page->findField('edit-uid-0-target-id'); $path = $input->getAttribute('data-autocomplete-path'); + // Remove potential base path when the site is under a subdirectory. + if (str_starts_with($path, base_path())) { + $path = str_replace(base_path(), '', $path); + } $this->drupalGet($path, ['query' => ['q' => $match]]); $header = $this->getSession()->getResponseHeader('content-type'); $this->assertSame('application/json', $header); From 95f3f41428bd74c814d6495795341d3e92ec4941 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 20 Nov 2022 11:43:29 +0200 Subject: [PATCH 19/21] EntityTest's label is 'name' --- tests/src/Functional/GroupTabTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Functional/GroupTabTest.php b/tests/src/Functional/GroupTabTest.php index e3256e533..97baf775e 100644 --- a/tests/src/Functional/GroupTabTest.php +++ b/tests/src/Functional/GroupTabTest.php @@ -175,7 +175,7 @@ protected function setUp(): void { $this->anotherNodeMembership = $this->createOgMembership($this->groupNode, $another_user); $this->groupTestEntity = EntityTest::create([ - 'title' => $this->randomString(), + 'name' => $this->randomString(), 'user_id' => $this->authorUser->id(), ]); $this->groupTestEntity->save(); From 37234a22180fe9784895ce85a524640e35968041 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 20 Nov 2022 12:25:35 +0200 Subject: [PATCH 20/21] Fix base path issue --- tests/src/Functional/GroupTabTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/src/Functional/GroupTabTest.php b/tests/src/Functional/GroupTabTest.php index 97baf775e..4aba69aa1 100644 --- a/tests/src/Functional/GroupTabTest.php +++ b/tests/src/Functional/GroupTabTest.php @@ -364,9 +364,10 @@ protected function assertAutoCompleteMatches(EntityInterface $group, string $mat $page = $this->getSession()->getPage(); $input = $page->findField('edit-uid-0-target-id'); $path = $input->getAttribute('data-autocomplete-path'); - // Remove potential base path when the site is under a subdirectory. - if (str_starts_with($path, base_path())) { - $path = str_replace(base_path(), '', $path); + // Remove potential base path when the site is under a subdirectory. + $base_path = rtrim(base_path(), '/'); + if ($base_path && strpos($path, $base_path) === 0) { + $path = substr($path, strlen($base_path)); } $this->drupalGet($path, ['query' => ['q' => $match]]); $header = $this->getSession()->getResponseHeader('content-type'); From 4303a9b39581a85dc3049d82e5f68d6b95ef0c50 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 20 Nov 2022 14:09:26 +0200 Subject: [PATCH 21/21] Cast NULL to empty string --- og_ui/src/BundleFormAlter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/BundleFormAlter.php b/og_ui/src/BundleFormAlter.php index 0c08163a9..78563d3d2 100644 --- a/og_ui/src/BundleFormAlter.php +++ b/og_ui/src/BundleFormAlter.php @@ -95,7 +95,7 @@ protected function prepare(array &$form, FormStateInterface $form_state) { // Example: article. $this->bundle = $this->entity->id(); // Example: Article. - $this->bundleLabel = Unicode::lcfirst($this->entity->label()); + $this->bundleLabel = Unicode::lcfirst((string) $this->entity->label()); $this->definition = $this->entity->getEntityType(); // Example: node. $this->entityTypeId = $this->definition->getBundleOf();