{"action":"created","comment":{"url":"https://api.github.com/repos/amitaibu/og/pulls/comments/64153127","id":64153127,"diff_hunk":"@@ -0,0 +1,557 @@\n+<?php\n+\n+namespace Drupal\\Tests\\og\\Kernel\\Entity;\n+\n+use Drupal\\KernelTests\\KernelTestBase;\n+use Drupal\\block_content\\Entity\\BlockContentType;\n+use Drupal\\node\\Entity\\NodeType;\n+use Drupal\\og\\Og;\n+use Drupal\\og\\OgGroupAudienceHelper;\n+\n+/**\n+ * Tests retrieving group (content) bundles by group (content) bundles.\n+ *\n+ * @group og\n+ * @coversDefaultClass \\Drupal\\og\\GroupManager\n+ */\n+class GetBundleByBundleTest extends KernelTestBase {\n+\n+  /**\n+   * {@inheritdoc}\n+   */\n+  public static $modules = [\n+    'block_content',\n+    'field',\n+    'node',\n+    'og',\n+    'system',\n+    'user',\n+  ];\n+\n+  /**\n+   * Test groups.\n+   *\n+   * @var \\Drupal\\Core\\Entity\\EntityInterface[][]\n+   */\n+  protected $groups = [];\n+\n+  /**\n+   * Test group content.\n+   *\n+   * @var \\Drupal\\Core\\Entity\\EntityInterface\n+   */\n+  protected $groupContent;\n+\n+  /**\n+   * The group manager.\n+   *\n+   * @var \\Drupal\\og\\GroupManager\n+   */\n+  protected $groupManager;\n+\n+  /**\n+   * {@inheritdoc}\n+   */\n+  protected function setUp() {\n+    parent::setUp();\n+\n+    $this->installConfig(['og']);\n+    $this->installEntitySchema('block_content');\n+    $this->installEntitySchema('node');\n+    $this->installEntitySchema('og_membership');\n+    $this->installEntitySchema('user');\n+    $this->installSchema('system', 'sequences');\n+\n+    $this->groupManager = $this->container->get('og.group.manager');\n+\n+    // Create four groups of two different entity types.\n+    for ($i = 0; $i < 2; $i++) {\n+      $bundle = \"group_$i\";\n+      NodeType::create([\n+        'name' => $this->randomString(),\n+        'type' => $bundle,\n+      ])->save();\n+      Og::groupManager()->addGroup('node', $bundle);\n+\n+      BlockContentType::create(['id' => $bundle])->save();\n+      Og::groupManager()->addGroup('block_content', $bundle);\n+    }\n+  }\n+\n+  /**\n+   * Tests retrieval of bundles that are referenc[ed|ing] bundles.\n+   *\n+   * This tests the retrieval of the relations between groups and group content\n+   * and vice versa. The retrieval of groups that are referenced by group\n+   * content is done by GroupManager::getGroupBundleIdsByGroupContenBundle()\n+   * while GroupManager::getGroupContentBundleIdsByGroupBundle() handles the\n+   * opposite case.\n+   *\n+   * Both methods are tested here in a single test since they are very similar,\n+   * and not having to set up the entire relationship structure twice reduces\n+   * the total test running time.\n+   *\n+   * @param array $relationships\n+   *   An array indicating the relationships between groups and group content\n+   *   bundles that need to be set up in the test.\n+   * @param array $expected_group_by_group_content\n+   *   An array containing the expected results for the call to\n+   *   getGroupBundleIdsByGroupContentBundle().\n+   * @param array $expected_group_content_by_group\n+   *   An array containing the expected results for the 4 calls to\n+   *   getGroupContentBundleIdsByGroupBundle() that will be made in the test.\n+   *\n+   * @covers ::getGroupBundleIdsByGroupContentBundle\n+   * @covers ::getGroupContentBundleIdsByGroupBundle\n+   *\n+   * @dataProvider getBundleIdsByBundleProvider\n+   */\n+  public function testGetBundleIdsByBundle(array $relationships, array $expected_group_by_group_content, array $expected_group_content_by_group) {\n+    // Set up the relations as indicated in the test.\n+    foreach ($relationships as $group_content_entity_type_id => $group_content_bundle_ids) {\n+      foreach ($group_content_bundle_ids as $group_content_bundle_id => $group_audience_fields) {\n+        switch ($group_content_entity_type_id) {\n+          case 'node':\n+            NodeType::create([\n+              'name' => $this->randomString(),\n+              'type' => $group_content_bundle_id,\n+            ])->save();\n+            break;\n+          case 'block_content':\n+            BlockContentType::create(['id' => $group_content_bundle_id])->save();\n+            break;\n+        }\n+        foreach ($group_audience_fields as $group_audience_field_key => $group_audience_field_data) {\n+          foreach ($group_audience_field_data as $group_entity_type_id => $group_bundle_ids) {\n+            $settings = [\n+              'field_name' => 'group_audience_' . $group_audience_field_key,\n+              'field_storage_config' => [\n+                'settings' => [\n+                  'target_type' => $group_entity_type_id,\n+                ],\n+              ],\n+            ];\n+\n+            if (!empty($group_bundle_ids)) {\n+              $settings['field_config'] = [\n+                'settings' => [\n+                  'handler_settings' => [\n+                    'target_bundles' => array_combine($group_bundle_ids, $group_bundle_ids),\n+                  ],\n+                ],\n+              ];\n+            }\n+            Og::createField(OgGroupAudienceHelper::DEFAULT_FIELD, $group_content_entity_type_id, $group_content_bundle_id, $settings);\n+          }\n+        }\n+      }\n+    }\n+\n+    // Test ::getGroupBundleIdsByGroupContentBundle().\n+    foreach ($expected_group_by_group_content as $group_content_entity_type_id => $group_content_bundle_ids) {\n+      foreach ($group_content_bundle_ids as $group_content_bundle_id => $expected_result) {\n+        $this->assertEquals($expected_result, $this->groupManager->getGroupBundleIdsByGroupContentBundle($group_content_entity_type_id, $group_content_bundle_id));\n+      }\n+    }\n+\n+    // Test ::getGroupContentBundleIdsByGroupBundle().\n+    foreach (['node', 'block_content'] as $group_entity_type_id) {\n+      for ($i = 0; $i < 2; $i++) {","path":"tests/src/Kernel/Entity/GetBundleByBundleTest.php","position":159,"original_position":159,"commit_id":"5c16b4de1343b0175d88c520ab40d2239051518b","original_commit_id":"5c16b4de1343b0175d88c520ab40d2239051518b","user":{"login":"pfrenssen","id":442924,"avatar_url":"https://avatars.githubusercontent.com/u/442924?v=3","gravatar_id":"","url":"https://api.github.com/users/pfrenssen","html_url":"https://github.com/pfrenssen","followers_url":"https://api.github.com/users/pfrenssen/followers","following_url":"https://api.github.com/users/pfrenssen/following{/other_user}","gists_url":"https://api.github.com/users/pfrenssen/gists{/gist_id}","starred_url":"https://api.github.com/users/pfrenssen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfrenssen/subscriptions","organizations_url":"https://api.github.com/users/pfrenssen/orgs","repos_url":"https://api.github.com/users/pfrenssen/repos","events_url":"https://api.github.com/users/pfrenssen/events{/privacy}","received_events_url":"https://api.github.com/users/pfrenssen/received_events","type":"User","site_admin":false},"body":"In the setup 2 node groups and 2 block_content groups were made. This iterates over all of them and checks if the results are correct.","created_at":"2016-05-22T17:19:32Z","updated_at":"2016-05-22T17:19:32Z","html_url":"https://github.com/amitaibu/og/pull/206#discussion_r64153127","pull_request_url":"https://api.github.com/repos/amitaibu/og/pulls/206","_links":{"self":{"href":"https://api.github.com/repos/amitaibu/og/pulls/comments/64153127"},"html":{"href":"https://github.com/amitaibu/og/pull/206#discussion_r64153127"},"pull_request":{"href":"https://api.github.com/repos/amitaibu/og/pulls/206"}}},"pull_request":{"url":"https://api.github.com/repos/amitaibu/og/pulls/206","id":70907480,"html_url":"https://github.com/amitaibu/og/pull/206","diff_url":"https://github.com/amitaibu/og/pull/206.diff","patch_url":"https://github.com/amitaibu/og/pull/206.patch","issue_url":"https://api.github.com/repos/amitaibu/og/issues/206","number":206,"state":"open","locked":false,"title":"Provide methods to retrieve group bundles by group content bundles and vice versa","user":{"login":"pfrenssen","id":442924,"avatar_url":"https://avatars.githubusercontent.com/u/442924?v=3","gravatar_id":"","url":"https://api.github.com/users/pfrenssen","html_url":"https://github.com/pfrenssen","followers_url":"https://api.github.com/users/pfrenssen/followers","following_url":"https://api.github.com/users/pfrenssen/following{/other_user}","gists_url":"https://api.github.com/users/pfrenssen/gists{/gist_id}","starred_url":"https://api.github.com/users/pfrenssen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfrenssen/subscriptions","organizations_url":"https://api.github.com/users/pfrenssen/orgs","repos_url":"https://api.github.com/users/pfrenssen/repos","events_url":"https://api.github.com/users/pfrenssen/events{/privacy}","received_events_url":"https://api.github.com/users/pfrenssen/received_events","type":"User","site_admin":false},"body":"This has been split off from PR #192.\r\n\r\nIn order to build a permission matrix for a given group type we need to be able to get the inverse relationship from group types to group content types.\r\n\r\nIn this PR I propose two methods in `GroupManager`:\r\n\r\n* `getGroupContentBundleIdsByGroupBundle($group_entity_type_id, $group_bundle_id)` returns an array containing all group content bundles that reference the given group type.\r\n* `getGroupBundleIdsByGroupContentBundle($group_content_entity_type_id, $group_content_bundle_id)` does the inverse: it will return an array containing all group bundles that are referenced by the group content type.","created_at":"2016-05-20T19:44:29Z","updated_at":"2016-05-22T17:19:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"53c4cf6184069733dd22d596f867584cd5b8baee","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amitaibu/og/pulls/206/commits","review_comments_url":"https://api.github.com/repos/amitaibu/og/pulls/206/comments","review_comment_url":"https://api.github.com/repos/amitaibu/og/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amitaibu/og/issues/206/comments","statuses_url":"https://api.github.com/repos/amitaibu/og/statuses/5c16b4de1343b0175d88c520ab40d2239051518b","head":{"label":"amitaibu:get-bundle-by-bundle","ref":"get-bundle-by-bundle","sha":"5c16b4de1343b0175d88c520ab40d2239051518b","user":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"repo":{"id":42034806,"name":"og","full_name":"amitaibu/og","owner":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amitaibu/og","description":"https://www.drupal.org/project/og","fork":true,"url":"https://api.github.com/repos/amitaibu/og","forks_url":"https://api.github.com/repos/amitaibu/og/forks","keys_url":"https://api.github.com/repos/amitaibu/og/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amitaibu/og/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amitaibu/og/teams","hooks_url":"https://api.github.com/repos/amitaibu/og/hooks","issue_events_url":"https://api.github.com/repos/amitaibu/og/issues/events{/number}","events_url":"https://api.github.com/repos/amitaibu/og/events","assignees_url":"https://api.github.com/repos/amitaibu/og/assignees{/user}","branches_url":"https://api.github.com/repos/amitaibu/og/branches{/branch}","tags_url":"https://api.github.com/repos/amitaibu/og/tags","blobs_url":"https://api.github.com/repos/amitaibu/og/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amitaibu/og/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amitaibu/og/git/refs{/sha}","trees_url":"https://api.github.com/repos/amitaibu/og/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amitaibu/og/statuses/{sha}","languages_url":"https://api.github.com/repos/amitaibu/og/languages","stargazers_url":"https://api.github.com/repos/amitaibu/og/stargazers","contributors_url":"https://api.github.com/repos/amitaibu/og/contributors","subscribers_url":"https://api.github.com/repos/amitaibu/og/subscribers","subscription_url":"https://api.github.com/repos/amitaibu/og/subscription","commits_url":"https://api.github.com/repos/amitaibu/og/commits{/sha}","git_commits_url":"https://api.github.com/repos/amitaibu/og/git/commits{/sha}","comments_url":"https://api.github.com/repos/amitaibu/og/comments{/number}","issue_comment_url":"https://api.github.com/repos/amitaibu/og/issues/comments{/number}","contents_url":"https://api.github.com/repos/amitaibu/og/contents/{+path}","compare_url":"https://api.github.com/repos/amitaibu/og/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amitaibu/og/merges","archive_url":"https://api.github.com/repos/amitaibu/og/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amitaibu/og/downloads","issues_url":"https://api.github.com/repos/amitaibu/og/issues{/number}","pulls_url":"https://api.github.com/repos/amitaibu/og/pulls{/number}","milestones_url":"https://api.github.com/repos/amitaibu/og/milestones{/number}","notifications_url":"https://api.github.com/repos/amitaibu/og/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amitaibu/og/labels{/name}","releases_url":"https://api.github.com/repos/amitaibu/og/releases{/id}","deployments_url":"https://api.github.com/repos/amitaibu/og/deployments","created_at":"2015-09-07T06:16:12Z","updated_at":"2016-05-19T21:15:55Z","pushed_at":"2016-05-22T15:58:09Z","git_url":"git://github.com/amitaibu/og.git","ssh_url":"git@github.com:amitaibu/og.git","clone_url":"https://github.com/amitaibu/og.git","svn_url":"https://github.com/amitaibu/og","homepage":"","size":6108,"stargazers_count":26,"watchers_count":26,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":65,"forks":14,"open_issues":65,"watchers":26,"default_branch":"8.x-1.x"}},"base":{"label":"amitaibu:8.x-1.x","ref":"8.x-1.x","sha":"0f6941add9fdf0b03f59e553c28a22dfefe45e55","user":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"repo":{"id":42034806,"name":"og","full_name":"amitaibu/og","owner":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amitaibu/og","description":"https://www.drupal.org/project/og","fork":true,"url":"https://api.github.com/repos/amitaibu/og","forks_url":"https://api.github.com/repos/amitaibu/og/forks","keys_url":"https://api.github.com/repos/amitaibu/og/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amitaibu/og/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amitaibu/og/teams","hooks_url":"https://api.github.com/repos/amitaibu/og/hooks","issue_events_url":"https://api.github.com/repos/amitaibu/og/issues/events{/number}","events_url":"https://api.github.com/repos/amitaibu/og/events","assignees_url":"https://api.github.com/repos/amitaibu/og/assignees{/user}","branches_url":"https://api.github.com/repos/amitaibu/og/branches{/branch}","tags_url":"https://api.github.com/repos/amitaibu/og/tags","blobs_url":"https://api.github.com/repos/amitaibu/og/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amitaibu/og/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amitaibu/og/git/refs{/sha}","trees_url":"https://api.github.com/repos/amitaibu/og/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amitaibu/og/statuses/{sha}","languages_url":"https://api.github.com/repos/amitaibu/og/languages","stargazers_url":"https://api.github.com/repos/amitaibu/og/stargazers","contributors_url":"https://api.github.com/repos/amitaibu/og/contributors","subscribers_url":"https://api.github.com/repos/amitaibu/og/subscribers","subscription_url":"https://api.github.com/repos/amitaibu/og/subscription","commits_url":"https://api.github.com/repos/amitaibu/og/commits{/sha}","git_commits_url":"https://api.github.com/repos/amitaibu/og/git/commits{/sha}","comments_url":"https://api.github.com/repos/amitaibu/og/comments{/number}","issue_comment_url":"https://api.github.com/repos/amitaibu/og/issues/comments{/number}","contents_url":"https://api.github.com/repos/amitaibu/og/contents/{+path}","compare_url":"https://api.github.com/repos/amitaibu/og/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amitaibu/og/merges","archive_url":"https://api.github.com/repos/amitaibu/og/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amitaibu/og/downloads","issues_url":"https://api.github.com/repos/amitaibu/og/issues{/number}","pulls_url":"https://api.github.com/repos/amitaibu/og/pulls{/number}","milestones_url":"https://api.github.com/repos/amitaibu/og/milestones{/number}","notifications_url":"https://api.github.com/repos/amitaibu/og/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amitaibu/og/labels{/name}","releases_url":"https://api.github.com/repos/amitaibu/og/releases{/id}","deployments_url":"https://api.github.com/repos/amitaibu/og/deployments","created_at":"2015-09-07T06:16:12Z","updated_at":"2016-05-19T21:15:55Z","pushed_at":"2016-05-22T15:58:09Z","git_url":"git://github.com/amitaibu/og.git","ssh_url":"git@github.com:amitaibu/og.git","clone_url":"https://github.com/amitaibu/og.git","svn_url":"https://github.com/amitaibu/og","homepage":"","size":6108,"stargazers_count":26,"watchers_count":26,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":65,"forks":14,"open_issues":65,"watchers":26,"default_branch":"8.x-1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/amitaibu/og/pulls/206"},"html":{"href":"https://github.com/amitaibu/og/pull/206"},"issue":{"href":"https://api.github.com/repos/amitaibu/og/issues/206"},"comments":{"href":"https://api.github.com/repos/amitaibu/og/issues/206/comments"},"review_comments":{"href":"https://api.github.com/repos/amitaibu/og/pulls/206/comments"},"review_comment":{"href":"https://api.github.com/repos/amitaibu/og/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amitaibu/og/pulls/206/commits"},"statuses":{"href":"https://api.github.com/repos/amitaibu/og/statuses/5c16b4de1343b0175d88c520ab40d2239051518b"}}}}
{"actor":{"display_login":"pfrenssen"}}