ConditionalFieldControllerTest.php in Conditional Fields 4.x        
                          
                  
                        
  
  
  
  
File
  tests/src/Unit/ConditionalFieldControllerTest.php
  
    View source  
  <?php
namespace Drupal\Tests\conditional_fields\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\conditional_fields\Controller\ConditionalFieldController;
class ConditionalFieldControllerTest extends UnitTestCase {
  
  protected $controller;
  
  protected function setUp() {
    parent::setUp();
    $entity_types = [];
    
    $entity_types['content_a'] = $this
      ->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityType')
      ->disableOriginalConstructor()
      ->getMock();
    $entity_types['content_a']
      ->expects($this
      ->any())
      ->method('getLabel')
      ->will($this
      ->returnValue("contentA"));
    
    $entity_types['content_b'] = $this
      ->createMock('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
    $entity_types['content_b']
      ->expects($this
      ->any())
      ->method('getLabel')
      ->will($this
      ->returnValue("contentB"));
    
    $entity_type_manager = $this
      ->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
    $entity_type_manager
      ->expects($this
      ->any())
      ->method('getDefinitions')
      ->will($this
      ->returnValue($entity_types));
    
    $form_builder = $this
      ->createMock('Drupal\\Core\\Form\\FormBuilderInterface');
    $form_builder
      ->expects($this
      ->never())
      ->method($this
      ->anything());
    $entity_type_bundle_info = $this
      ->createMock('Drupal\\Core\\Entity\\EntityTypeBundleInfoInterface');
    $entity_type_bundle_info
      ->expects($this
      ->never())
      ->method($this
      ->anything());
    $entity_field_manager = $this
      ->createMock('Drupal\\Core\\Entity\\EntityFieldManagerInterface');
    $entity_field_manager
      ->expects($this
      ->never())
      ->method($this
      ->anything());
    
    $this->controller = new ConditionalFieldController($entity_type_manager, $form_builder, $entity_type_bundle_info, $entity_field_manager);
  }
  
  public function testEntityTypeList() {
    $available_entity_types = $this->controller
      ->entityTypeList()['#content'];
    $this
      ->assertEquals(1, count($available_entity_types));
    $this
      ->assertEquals($available_entity_types[0]['title'], 'contentA');
  }
}