/** * {@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() { $this->typedConfigManager->expects($this->once())->method('getDefinition')->will($this->returnValue(array('mapping' => array('id' => '', 'dependencies' => '')))); $properties = $this->entity->toArray(); $this->assertInternalType('array', $properties); $this->assertEquals(array('id' => $this->entity->id(), 'dependencies' => array()), $properties); }
/** * @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' => LanguageInterface::LANGCODE_NOT_SPECIFIED, '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); }
/** * Tests ConfigMapperManager::hasTranslatable(). * * @param \Drupal\Core\TypedData\TypedDataInterface $element * The schema element to test. * @param bool $expected * The expected return value of ConfigMapperManager::hasTranslatable(). * * @dataProvider providerTestHasTranslatable */ public function testHasTranslatable(TypedDataInterface $element, $expected) { $this->typedConfigManager->expects($this->once())->method('get')->with('test')->will($this->returnValue($element)); $result = $this->configMapperManager->hasTranslatable('test'); $this->assertSame($expected, $result); }
/** * {@inheritdoc} * * @covers ::__construct() */ protected function setUp() { parent::setUp(); $this->entityType = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $this->entityTypeId = 'test_entity_type'; $this->entityType->expects($this->any())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'), array('uuid', 'uuid')))); $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->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('getDefaultLanguage')->will($this->returnValue(new Language(array('langcode' => 'en')))); $this->configStorage = $this->getConfigStorageStub(array()); $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->configStorage, $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->cacheBackend = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface'); $this->typedConfigManager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface'); $this->typedConfigManager->expects($this->any())->method('getDefinition')->will($this->returnValue(array('mapping' => array('id' => '', 'uuid' => '', 'dependencies' => '')))); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('config.typed', $this->typedConfigManager); $container->set('cache.test', $this->cacheBackend); $container->setParameter('cache_bins', array('cache.test' => 'test')); \Drupal::setContainer($container); }