From 0f51cb40d552215632fa6bbbf38f0315a5b7a3fc Mon Sep 17 00:00:00 2001 From: Insasse Date: Thu, 22 Nov 2018 09:35:57 +0100 Subject: [PATCH] Fix GroupTabTest --- src/Controller/OgAdminRoutesController.php | 6 ++++- tests/src/Functional/GroupTabTest.php | 27 ++++++++-------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/Controller/OgAdminRoutesController.php b/src/Controller/OgAdminRoutesController.php index d6a9002ef..b20a27bdf 100644 --- a/src/Controller/OgAdminRoutesController.php +++ b/src/Controller/OgAdminRoutesController.php @@ -57,7 +57,11 @@ public static function create(ContainerInterface $container) { public function overview(RouteMatchInterface $route_match) { /** @var \Drupal\Core\Entity\EntityInterface $group */ $group = $route_match->getParameter('group'); - + $entity_type_id = NULL; + if (!is_object($group)) { + $entity_type_id = $route_match->getRouteObject()->getOption('_og_entity_type_id'); + $group = $route_match->getParameter($entity_type_id); + } // Get list from routes. $content = []; diff --git a/tests/src/Functional/GroupTabTest.php b/tests/src/Functional/GroupTabTest.php index 65aafc709..30d61e872 100644 --- a/tests/src/Functional/GroupTabTest.php +++ b/tests/src/Functional/GroupTabTest.php @@ -26,13 +26,6 @@ class GroupTabTest extends BrowserTestBase { */ protected $group; - /** - * Test entity group. - * - * @var \Drupal\node\NodeInterface - */ - protected $nonGroup; - /** * A group bundle name. * @@ -82,24 +75,19 @@ protected function setUp() { Og::groupTypeManager()->addGroup('node', $this->bundle1); // Create node author user. - $user = $this->createUser(); + $this->user1 = $this->drupalCreateUser(['administer group']); + + // Create normal user. + $this->user2 = $this->drupalCreateUser(['access content']); // Create nodes. $this->group = Node::create([ 'type' => $this->bundle1, 'title' => $this->randomString(), - 'uid' => $user->id(), + 'uid' => $this->user1->id(), ]); $this->group->save(); - $this->nonGroup = Node::create([ - 'type' => $this->bundle2, - 'title' => $this->randomString(), - 'uid' => $user->id(), - ]); - $this->nonGroup->save(); - - $this->user1 = $this->drupalCreateUser(['administer group']); } /** @@ -109,8 +97,11 @@ public function testGroupTab() { $this->drupalLogin($this->user1); $this->drupalGet('group/node/' . $this->group->id() . '/admin'); $this->assertResponse(200); + $this->drupalLogout(); + } - $this->drupalGet('group/node/' . $this->nonGroup->id() . '/admin'); + public function testGroupTabAccessDenied() { + $this->drupalGet('group/node/' . $this->group->id() . '/admin'); $this->assertResponse(403); }