You are here

public function OgResolvedGroupCollectionTest::testGetGroupInfo in Organic groups 8

Tests retrieving group info from the collection.

This simply tests that the group info is returned and contains the correct number of results. The actual content of the group info is tested in testAddGroup().

@covers ::getGroupInfo

@dataProvider groupVotesProvider

Parameters

array $votes: An array of associative arrays representing voting information, with the following keys:

  • group: the ID of the group to add a vote for.
  • cache_contexts: an array of cache_contexts to associate with the group. To omit associating cache contexts, set to an empty array.
  • weight: an integer representing the vote weight. Set to NULL to omit.

array $expected_groups: The groups that are expected to be present after all votes are added, ordered by ranking.

See also

testAddGroup()

File

tests/src/Unit/OgResolvedGroupCollectionTest.php, line 146

Class

OgResolvedGroupCollectionTest
Tests the collecting of resolved groups to pass as a route context.

Namespace

Drupal\Tests\og\Unit

Code

public function testGetGroupInfo(array $votes, array $expected_groups) {
  $collection = new OgResolvedGroupCollection();
  foreach ($votes as $vote) {
    $collection
      ->addGroup($this->groups[$vote['group']], $vote['cache_contexts'], $vote['weight']);
  }
  $info = $collection
    ->getGroupInfo();

  // Check that the expected number of groups have been added.
  $this
    ->assertEquals(count($expected_groups), count($info));
}