Example #1
0
 /**
  * {@inheritdoc}
  *
  * @covers ::__construct
  */
 protected function setUp()
 {
     parent::setUp();
     $this->entityType = $this->getMock('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
     $this->entityTypeId = 'test_entity_type';
     $this->entityType->expects($this->any())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'), array('uuid', 'uuid'), array('langcode', 'langcode'))));
     $this->entityType->expects($this->any())->method('id')->will($this->returnValue($this->entityTypeId));
     $this->entityType->expects($this->any())->method('getConfigPrefix')->will($this->returnValue('the_config_prefix'));
     $this->entityType->expects($this->any())->method('getClass')->will($this->returnValue(get_class($this->getMockEntity())));
     $this->entityType->expects($this->any())->method('getListCacheTags')->willReturn(array('test_entity_type_list'));
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->uuidService = $this->getMock('Drupal\\Component\\Uuid\\UuidInterface');
     $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->willReturn(new Language(array('id' => 'hu')));
     $this->configFactory = $this->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
     $this->entityQuery = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
     $this->entityStorage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->setConstructorArgs(array($this->entityType, $this->configFactory, $this->uuidService, $this->languageManager))->setMethods(array('getQuery'))->getMock();
     $this->entityStorage->expects($this->any())->method('getQuery')->will($this->returnValue($this->entityQuery));
     $this->entityStorage->setModuleHandler($this->moduleHandler);
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with('test_entity_type')->will($this->returnValue($this->entityType));
     $this->cacheTagsInvalidator = $this->getMock('Drupal\\Core\\Cache\\CacheTagsInvalidatorInterface');
     $this->typedConfigManager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
     $this->typedConfigManager->expects($this->any())->method('getDefinition')->will($this->returnValue(array('mapping' => array('id' => '', 'uuid' => '', 'dependencies' => ''))));
     $this->configManager = $this->getMock('Drupal\\Core\\Config\\ConfigManagerInterface');
     $this->cacheContextsManager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')->disableOriginalConstructor()->getMock();
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('config.typed', $this->typedConfigManager);
     $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
     $container->set('config.manager', $this->configManager);
     $container->set('language_manager', $this->languageManager);
     $container->set('cache_contexts_manager', $this->cacheContextsManager);
     \Drupal::setContainer($container);
 }
 /**
  * @covers ::toArray
  */
 public function testToArray()
 {
     $field = new FieldConfig(array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle', 'field_type' => 'test_field'), $this->entityTypeId);
     $expected = array('id' => 'test_entity_type.test_bundle.field_test', 'uuid' => NULL, 'status' => TRUE, 'langcode' => 'en', 'field_name' => 'field_test', 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle', 'label' => '', 'description' => '', 'required' => FALSE, 'default_value' => array(), 'default_value_callback' => '', 'settings' => array(), 'dependencies' => array(), 'field_type' => 'test_field');
     $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
     $this->entityType->expects($this->once())->method('getKey')->with('id')->will($this->returnValue('id'));
     $this->typedConfigManager->expects($this->once())->method('getDefinition')->will($this->returnValue(array('mapping' => array_fill_keys(array_keys($expected), ''))));
     $export = $field->toArray();
     $this->assertEquals($expected, $export);
 }
 /**
  * @covers ::toArray
  *
  * @expectedException \Drupal\Core\Config\Schema\SchemaIncompleteException
  */
 public function testToArrayFallback()
 {
     $this->entityType->expects($this->any())->method('getPropertiesToExport')->willReturn([]);
     $this->entity->toArray();
 }