You are here

public function GroupContentEnablerManagerTest::testGetHandler in Group 8

Tests the getHandler() method.

@covers ::getHandler @depends testCreateHandlerInstance

File

tests/src/Unit/GroupContentEnablerManagerTest.php, line 180

Class

GroupContentEnablerManagerTest
Tests the GroupContentEnabler plugin manager.

Namespace

Drupal\Tests\group\Unit

Code

public function testGetHandler() {
  $apple = [
    'handlers' => [
      'foo_handler' => TestGroupContentHandler::class,
    ],
  ];
  $this
    ->setUpPluginDefinitions([
    'apple' => $apple,
  ]);
  $first_call_result = $this->groupContentEnablerManager
    ->getHandler('apple', 'foo_handler');
  $second_call_result = $this->groupContentEnablerManager
    ->getHandler('apple', 'foo_handler');
  $direct_call_result = $this->groupContentEnablerManager
    ->createHandlerInstance($apple['handlers']['foo_handler'], 'apple', $apple);
  $this
    ->assertEquals($first_call_result, $direct_call_result, 'Got the same result as if createHandlerInstance() were called directly.');
  $this
    ->assertSame($first_call_result, $second_call_result, 'Got the exact same handler instance when called another time.');
  $this
    ->assertNotSame($first_call_result, $direct_call_result, 'Calling createHandlerInstance() creates a fresh copy regardless of internal cache.');
}