You are here

public function GroupTypeManagerTest::testAddGroupNew in Organic groups 8

Tests adding a new group.

@covers ::addGroup

File

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

Class

GroupTypeManagerTest
Tests the group manager.

Namespace

Drupal\Tests\og\Unit

Code

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

  // It is expected that the group map will be retrieved from config.
  $groups_before = [];
  $this
    ->expectGroupMapRetrieval($groups_before);
  $groups_after = [
    'test_entity_new' => [
      'a',
    ],
  ];
  $config_prophecy = $this->config;
  $this->config
    ->set('groups', $groups_after)
    ->will(function () use ($groups_after, $config_prophecy) {
    $config_prophecy
      ->get('groups')
      ->willReturn($groups_after)
      ->shouldBeCalled();
  })
    ->shouldBeCalled();
  $this->config
    ->save()
    ->shouldBeCalled();
  $manager = $this
    ->createGroupManager();
  $this->ogRoleManager
    ->createPerBundleRoles('test_entity_new', 'a');
  $this->eventDispatcher
    ->dispatch(GroupCreationEventInterface::EVENT_NAME, Argument::type(GroupCreationEvent::class))
    ->shouldBeCalled();

  // Add a new entity type.
  $manager
    ->addGroup('test_entity_new', 'a');
  $this
    ->assertSame([
    'a',
  ], $manager
    ->getGroupBundleIdsByEntityType('test_entity_new'));
  $this
    ->assertTrue($manager
    ->isGroup('test_entity_new', 'a'));
}