<?php

namespace Drupal\KernelTests\Core\Entity;

/**
 * Tests the getBundleEntity() method.
 *
 * @group Entity
 */
class EntityBundleEntityTest extends EntityKernelTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('entity_schema_test');

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The database connection used.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $database;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->installSchema('user', array('users_data'));
    $this->moduleHandler = $this->container->get('module_handler');
    $this->database = $this->container->get('database');
  }
  
  /**
   * Tests the getBundleEntity() method.
   */
  public function testEntityBundleEntity() {
    $storage = $this->entityManager->getStorage('entity_test_bundle');
    $bundle_entity = $storage->create([
      'id' => 'bundle_alpha',
      'label' => 'Alpha',
    ]);
    $bundle_entity->save();
    // WTF does debug() crash a test?????????????????????????????
    //debug($bundle_entity->id());    
    
    $storage = $this->entityManager->getStorage('entity_test');
    $content_entity = $storage->create([
      'type' => 'bundle_alpha',
    ]);
    $content_entity->save();
    
    $obtained_bundle_entity = $content_entity->getBundleEntity();
    // Appears to be NULL. WTF????????????
  }

}
