You are here

public function ForumBreadcrumbBuilderBaseTest::testConstructor in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 41
Contains \Drupal\Tests\forum\Unit\Breadcrumb\ForumBreadcrumbBuilderBaseTest.

Class

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

Namespace

Drupal\Tests\forum\Unit\Breadcrumb

Code

public function testConstructor() {

  // Make some test doubles.
  $entity_manager = $this
    ->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
  $config_factory = $this
    ->getConfigFactoryStub(array(
    'forum.settings' => array(
      'IAmATestKey' => 'IAmATestValue',
    ),
  ));
  $forum_manager = $this
    ->getMock('Drupal\\forum\\ForumManagerInterface');

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

  // Reflect upon our properties, except for config which is a special case.
  $property_names = array(
    'entityManager' => $entity_manager,
    'forumManager' => $forum_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'));
}