You are here

public function GroupTypeManagerTest::testRemoveGroup in Organic groups 8

Tests removing a group.

@covers ::addGroup

File

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

Class

GroupTypeManagerTest
Tests the group manager.

Namespace

Drupal\Tests\og\Unit

Code

public function testRemoveGroup() {
  $this->configFactory
    ->getEditable('og.settings')
    ->willReturn($this->config
    ->reveal())
    ->shouldBeCalled();

  // 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',
    ],
  ];
  $this->config
    ->set('groups', $groups_after)
    ->shouldBeCalled();
  $this->config
    ->save()
    ->shouldBeCalled();
  $this->config
    ->get('groups')
    ->willReturn($groups_after)
    ->shouldBeCalled();
  $manager = $this
    ->createGroupManager();

  // Add to existing.
  $manager
    ->removeGroup('test_entity', 'b');
  $this
    ->assertSame([
    'a',
  ], $manager
    ->getGroupBundleIdsByEntityType('test_entity'));
  $this
    ->assertFalse($manager
    ->isGroup('test_entity', 'b'));
  $this
    ->assertTrue($manager
    ->isGroup('test_entity', 'a'));
}