You are here

public function GroupTypeManagerTest::testAddGroupExisting in Organic groups 8

Tests adding an existing group.

@covers ::addGroup

File

tests/src/Unit/GroupTypeManagerTest.php, line 212

Class

GroupTypeManagerTest
Tests the group manager.

Namespace

Drupal\Tests\og\Unit

Code

public function testAddGroupExisting() {

  // It is expected that the group map will be retrieved from config.
  $groups_before = [
    'test_entity' => [
      'a',
      'b',
    ],
  ];
  $this
    ->expectGroupMapRetrieval($groups_before);
  $groups_after = [
    'test_entity' => [
      'a',
      'b',
      'c',
    ],
  ];
  $this->config
    ->get('groups')
    ->willReturn($groups_after)
    ->shouldBeCalled();
  $manager = $this
    ->createGroupManager();

  // Add to existing.
  $this
    ->expectException(\InvalidArgumentException::class);
  $manager
    ->addGroup('test_entity', 'c');
  $this
    ->assertSame([
    'a',
    'b',
    'c',
  ], $manager
    ->getGroupBundleIdsByEntityType('test_entity'));
  $this
    ->assertTrue($manager
    ->isGroup('test_entity', 'c'));
}