public function OgResolvedGroupCollectionTest::groupVotesProvider in Organic groups 8
Provides data for testing the retrieval of group information.
Return value
array An array of test data, each item an array with these two values:
- An associative array 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.
- An array containing the IDs of the groups that are expected to be present in the collection after all votes are added, in the order they are expected to be according to their votes.
File
- tests/
src/ Unit/ OgResolvedGroupCollectionTest.php, line 362
Class
- OgResolvedGroupCollectionTest
- Tests the collecting of resolved groups to pass as a route context.
Namespace
Drupal\Tests\og\UnitCode
public function groupVotesProvider() {
return [
// A simple vote for a group.
[
[
[
'group' => 'node-0',
'cache_contexts' => [],
'weight' => NULL,
],
],
// There is one group.
[
'node-0',
],
],
// 3 votes for the same group.
[
[
[
'group' => 'entity_test-0',
'cache_contexts' => [],
'weight' => NULL,
],
[
'group' => 'entity_test-0',
'cache_contexts' => [
'user',
],
'weight' => 0,
],
[
'group' => 'entity_test-0',
'cache_contexts' => [
'route',
'user',
],
'weight' => -1,
],
],
// There is one group.
[
'entity_test-0',
],
],
// A 'typical' test case with 5 votes for 3 different groups.
[
[
[
'group' => 'taxonomy_term-1',
'cache_contexts' => [],
'weight' => NULL,
],
[
'group' => 'block_content-0',
'cache_contexts' => [
'user',
],
'weight' => NULL,
],
[
'group' => 'node-1',
'cache_contexts' => [
'route',
],
'weight' => -1,
],
[
'group' => 'block_content-0',
'cache_contexts' => [
'route',
'user',
],
'weight' => -1,
],
[
'group' => 'taxonomy_term-1',
'cache_contexts' => [],
'weight' => -2,
],
],
// The resulting groups in the collection, ordered by votes and weight.
[
// 2 votes, total weight -1.
'block_content-0',
// 2 votes, total weight -2.
'taxonomy_term-1',
// 1 vote.
'node-1',
],
],
// Groups with more votes should rank higher than groups with fewer votes,
// regardless of the vote weight.
[
[
[
'group' => 'taxonomy_term-0',
'cache_contexts' => [
'route',
],
'weight' => 100,
],
[
'group' => 'block_content-0',
'cache_contexts' => [
'user',
],
'weight' => NULL,
],
[
'group' => 'block_content-1',
'cache_contexts' => [],
'weight' => 99999,
],
[
'group' => 'taxonomy_term-0',
'cache_contexts' => [],
'weight' => -300,
],
[
'group' => 'block_content-0',
'cache_contexts' => [
'route',
'user',
],
'weight' => NULL,
],
[
'group' => 'taxonomy_term-0',
'cache_contexts' => [],
'weight' => -3,
],
],
[
'taxonomy_term-0',
'block_content-0',
'block_content-1',
],
],
// If multiple groups have the same number of votes, then the ones with
// higher vote weights should be ranked higher.
[
[
[
'group' => 'entity_test-0',
'cache_contexts' => [
'user',
],
'weight' => 10,
],
[
'group' => 'block_content-0',
'cache_contexts' => [
'route',
'user',
],
'weight' => NULL,
],
[
'group' => 'node-1',
'cache_contexts' => [],
'weight' => 99999,
],
[
'group' => 'taxonomy_term-1',
'cache_contexts' => [
'url',
],
'weight' => 123,
],
[
'group' => 'taxonomy_term-1',
'cache_contexts' => [],
'weight' => 0,
],
[
'group' => 'entity_test-0',
'cache_contexts' => [],
'weight' => -3,
],
[
'group' => 'block_content-0',
'cache_contexts' => [
'route',
],
'weight' => -1,
],
[
'group' => 'node-1',
'cache_contexts' => [],
'weight' => -8,
],
],
[
'node-1',
'taxonomy_term-1',
'entity_test-0',
'block_content-0',
],
],
];
}