You are here

public function ForumBreadcrumbBuilderBaseTest::testConstructor in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/forum/tests/src/Unit/Breadcrumb/ForumBreadcrumbBuilderBaseTest.php \Drupal\Tests\forum\Unit\Breadcrumb\ForumBreadcrumbBuilderBaseTest::testConstructor()

Tests ForumBreadcrumbBuilderBase::__construct().

@covers ::__construct

File

core/modules/forum/tests/src/Unit/Breadcrumb/ForumBreadcrumbBuilderBaseTest.php, line 37

Class

ForumBreadcrumbBuilderBaseTest
@coversDefaultClass \Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase @group forum

Namespace

Drupal\Tests\forum\Unit\Breadcrumb

Code

public function testConstructor() {

  // Make some test doubles.
  $entity_type_manager = $this
    ->createMock(EntityTypeManagerInterface::class);
  $config_factory = $this
    ->getConfigFactoryStub([
    'forum.settings' => [
      'IAmATestKey' => 'IAmATestValue',
    ],
  ]);
  $forum_manager = $this
    ->createMock('Drupal\\forum\\ForumManagerInterface');
  $translation_manager = $this
    ->createMock('Drupal\\Core\\StringTranslation\\TranslationInterface');

  // Make an object to test.
  $builder = $this
    ->getMockForAbstractClass('Drupal\\forum\\Breadcrumb\\ForumBreadcrumbBuilderBase', [
    $entity_type_manager,
    $config_factory,
    $forum_manager,
    $translation_manager,
  ]);

  // Reflect upon our properties, except for config which is a special case.
  $property_names = [
    'entityTypeManager' => $entity_type_manager,
    'forumManager' => $forum_manager,
    'stringTranslation' => $translation_manager,
  ];
  foreach ($property_names as $property_name => $property_value) {
    $this
      ->assertAttributeEquals($property_value, $property_name, $builder);
  }

  // Test that the constructor made a config object with our info in it.
  $reflector = new \ReflectionClass($builder);
  $ref_property = $reflector
    ->getProperty('config');
  $ref_property
    ->setAccessible(TRUE);
  $config = $ref_property
    ->getValue($builder);
  $this
    ->assertEquals('IAmATestValue', $config
    ->get('IAmATestKey'));
}