本文整理汇总了PHP中Drupal\Core\Entity\EntityManagerInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::expects方法的具体用法?PHP EntityManagerInterface::expects怎么用?PHP EntityManagerInterface::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreatePayment
/**
* @covers ::createPayment
*/
public function testCreatePayment()
{
$bundle = $this->randomMachineName();
$currency_code = $this->randomMachineName();
$entity_type_id = $this->randomMachineName();
$field_name = $this->randomMachineName();
$payment_type = $this->getMockBuilder(PaymentReference::class)->disableOriginalConstructor()->getMock();
$payment_type->expects($this->once())->method('setBundle')->with($bundle);
$payment_type->expects($this->once())->method('setEntityTypeId')->with($entity_type_id);
$payment_type->expects($this->once())->method('setFieldName')->with($field_name);
$payment = $this->getMock(PaymentInterface::class);
$payment->expects($this->once())->method('setCurrencyCode')->with($currency_code);
$payment->expects($this->once())->method('getPaymentType')->willReturn($payment_type);
$payment_storage = $this->getMock(EntityStorageInterface::class);
$payment_storage->expects($this->once())->method('create')->with(array('bundle' => 'payment_reference'))->willReturn($payment);
$this->entityManager->expects($this->once())->method('getStorage')->with('payment')->willReturn($payment_storage);
$line_item_a = $this->getMock(PaymentLineItemInterface::class);
$line_item_plugin_id_a = $this->randomMachineName();
$line_item_plugin_configuration_a = array('foo' => $this->randomMachineName());
$line_item_b = $this->getMock(PaymentLineItemInterface::class);
$line_item_plugin_id_b = $this->randomMachineName();
$line_item_plugin_configuration_b = array('bar' => $this->randomMachineName());
$field_storage_definition = $this->getMock(FieldStorageDefinitionInterface::class);
$field_storage_definition->expects($this->once())->method('getTargetEntityTypeId')->willReturn($entity_type_id);
$field_definition = $this->getMock(FieldDefinitionInterface::class);
$field_definition->expects($this->once())->method('getTargetBundle')->willReturn($bundle);
$field_definition->expects($this->once())->method('getFieldStorageDefinition')->willReturn($field_storage_definition);
$field_definition->expects($this->once())->method('getName')->willreturn($field_name);
$map = array(array('currency_code', $currency_code), array('line_items_data', array(array('plugin_configuration' => $line_item_plugin_configuration_a, 'plugin_id' => $line_item_plugin_id_a), array('plugin_configuration' => $line_item_plugin_configuration_b, 'plugin_id' => $line_item_plugin_id_b))));
$field_definition->expects($this->exactly(2))->method('getSetting')->willReturnMap($map);
$this->paymentLineItemManager->expects($this->at(0))->method('createInstance')->with($line_item_plugin_id_a, $line_item_plugin_configuration_a)->willReturn($line_item_a);
$this->paymentLineItemManager->expects($this->at(1))->method('createInstance')->with($line_item_plugin_id_b, $line_item_plugin_configuration_b)->willReturn($line_item_b);
$this->assertSame($payment, $this->sut->createPayment($field_definition));
}
示例2: setUp
protected function setUp()
{
$this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->viewStorage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->disableOriginalConstructor()->getMock();
$this->entityManager->expects($this->any())->method('getStorage')->with('view')->will($this->returnValue($this->viewStorage));
$this->state = $this->getMock('\\Drupal\\Core\\State\\StateInterface');
$this->routeSubscriber = new TestRouteSubscriber($this->entityManager, $this->state);
}
示例3: testLabel
/**
* @covers ::setLabel
* @covers ::label
*/
public function testLabel()
{
$entity_type = $this->getMock(ConfigEntityTypeInterface::class);
$entity_type->expects($this->atLeastOnce())->method('getKey')->with('label')->willReturn('label');
$this->entityManager->expects($this->atLeastOnce())->method('getDefinition')->with($this->entityTypeId)->willReturn($entity_type);
$label = $this->randomMachineName();
$this->assertSame($this->sut, $this->sut->setLabel($label));
$this->assertSame($label, $this->sut->label());
}
示例4: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
$this->entityTypeId = $this->randomMachineName();
$this->provider = $this->randomMachineName();
$this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityType->expects($this->any())->method('getProvider')->will($this->returnValue($this->provider));
$this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
}
示例5: testGetForm
/**
* Tests the getForm() method.
*
* @covers ::getForm()
*/
public function testGetForm()
{
$form_controller = $this->getMock('Drupal\\Core\\Entity\\EntityFormInterface');
$form_controller->expects($this->any())->method('getFormId')->will($this->returnValue('the_form_id'));
$this->entityManager->expects($this->any())->method('getFormObject')->with('the_entity_type', 'default')->will($this->returnValue($form_controller));
$this->formBuilder->expects($this->once())->method('buildForm')->with($form_controller, $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'))->will($this->returnValue('the form contents'));
$entity = $this->getMock('Drupal\\Core\\Entity\\EntityInterface');
$entity->expects($this->once())->method('getEntityTypeId')->will($this->returnValue('the_entity_type'));
$this->assertSame('the form contents', $this->entityFormBuilder->getForm($entity));
}
示例6: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->conditionManager = $this->getMock('Drupal\\Core\\Executable\\ExecutableManagerInterface');
$this->language = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
$this->contextRepository = $this->getMock('Drupal\\Core\\Plugin\\Context\\ContextRepositoryInterface');
$this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->storage = $this->getMock('Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
$this->themeHandler = $this->getMock('Drupal\\Core\\Extension\\ThemeHandlerInterface');
$this->entityManager->expects($this->any())->method('getStorage')->will($this->returnValue($this->storage));
}
示例7: testCalculateDependencies
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies()
{
$target_entity_type_id = $this->randomMachineName(16);
$target_entity_type = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$target_entity_type->expects($this->any())->method('getProvider')->will($this->returnValue('test_module'));
$values = array('targetEntityType' => $target_entity_type_id);
$this->entityManager->expects($this->at(0))->method('getDefinition')->with($target_entity_type_id)->will($this->returnValue($target_entity_type));
$this->entityManager->expects($this->at(1))->method('getDefinition')->with($this->entityType)->will($this->returnValue($this->entityInfo));
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityDisplayModeBase')->setConstructorArgs(array($values, $this->entityType))->setMethods(array('getFilterFormat'))->getMock();
$dependencies = $this->entity->calculateDependencies()->getDependencies();
$this->assertContains('test_module', $dependencies['module']);
}
示例8: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityType->expects($this->any())->method('getProvider')->will($this->returnValue('responsive_image'));
$this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entityManager->expects($this->any())->method('getDefinition')->with('responsive_image_mapping')->will($this->returnValue($this->entityType));
$this->breakpointManager = $this->getMock('\\Drupal\\breakpoint\\BreakpointManagerInterface');
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('breakpoint.manager', $this->breakpointManager);
\Drupal::setContainer($container);
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:15,代码来源:ResponsiveImageMappingConfigEntityUnitTest.php
示例9: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
$this->entityTypeId = $this->randomMachineName();
$this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityType->expects($this->any())->method('getProvider')->will($this->returnValue('block'));
$this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
$this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('uuid', $this->uuid);
\Drupal::setContainer($container);
}
示例10: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
$entity_type_id_key = $this->randomMachineName();
$entity_type_id = $this->randomMachineName();
$this->database = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$this->fieldStorageDefinitions = array($entity_type_id_key => $this->getMock(FieldDefinitionInterface::class));
$this->entityManager = $this->getMock(EntityManagerInterface::class);
$this->entityManager->expects($this->atLeastOnce())->method('getFieldStorageDefinitions')->with($entity_type_id)->willReturn($this->fieldStorageDefinitions);
$this->entityType = $this->getMock(ContentEntityTypeInterface::class);
$this->entityType->expects($this->atLeastOnce())->method('id')->willReturn($entity_type_id);
$this->storage = $this->getMockBuilder(SqlContentEntityStorage::class)->disableOriginalConstructor()->getMock();
$this->sut = new PaymentStorageSchema($this->entityManager, $this->entityType, $this->storage, $this->database);
}
示例11: testCalculateDependenciesWithEntityBundle
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependenciesWithEntityBundle()
{
$target_entity_type_id = $this->randomMachineName(16);
$target_entity_type = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$target_entity_type->expects($this->any())->method('getProvider')->will($this->returnValue('test_module'));
$bundle_id = $this->randomMachineName(10);
$values = array('targetEntityType' => $target_entity_type_id, 'bundle' => $bundle_id);
$target_entity_type->expects($this->any())->method('getBundleConfigDependency')->will($this->returnValue(array('type' => 'config', 'name' => 'test_module.type.' . $bundle_id)));
$this->entityManager->expects($this->at(0))->method('getDefinition')->with($target_entity_type_id)->will($this->returnValue($target_entity_type));
$this->entityManager->expects($this->at(1))->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
$entity = new RdfMapping($values, $this->entityTypeId);
$dependencies = $entity->calculateDependencies();
$this->assertContains('test_module.type.' . $bundle_id, $dependencies['config']);
$this->assertContains('test_module', $dependencies['module']);
}
示例12: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->mailManager = $this->getMock('\\Drupal\\Core\\Mail\\MailManagerInterface');
$this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
$this->logger = $this->getMock('\\Psr\\Log\\LoggerInterface');
$this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->userStorage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface');
$this->entityManager->expects($this->any())->method('getStorage')->with('user')->willReturn($this->userStorage);
$string_translation = $this->getStringTranslationStub();
$this->contactMailHandler = new MailHandler($this->mailManager, $this->languageManager, $this->logger, $string_translation, $this->entityManager);
$language = new Language(array('id' => 'en'));
$this->languageManager->expects($this->any())->method('getDefaultLanguage')->will($this->returnValue($language));
$this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue($language));
}
示例13: setUp
/**
* {@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);
}
示例14: testSort
/**
* @covers ::sort
*/
public function testSort()
{
$this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue(array('entity_keys' => array('label' => 'label'))));
$entity_a = $this->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
$entity_a->expects($this->atLeastOnce())->method('label')->willReturn('foo');
$entity_b = $this->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
$entity_b->expects($this->atLeastOnce())->method('label')->willReturn('bar');
// Test sorting by label.
$list = array($entity_a, $entity_b);
// Suppress errors because of https://bugs.php.net/bug.php?id=50688.
@usort($list, '\\Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
$this->assertSame($entity_b, $list[0]);
$list = array($entity_b, $entity_a);
// Suppress errors because of https://bugs.php.net/bug.php?id=50688.
@usort($list, '\\Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
$this->assertSame($entity_b, $list[0]);
// Test sorting by weight.
$entity_a->weight = 0;
$entity_b->weight = 1;
$list = array($entity_b, $entity_a);
// Suppress errors because of https://bugs.php.net/bug.php?id=50688.
@usort($list, '\\Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
$this->assertSame($entity_a, $list[0]);
$list = array($entity_a, $entity_b);
// Suppress errors because of https://bugs.php.net/bug.php?id=50688.
@usort($list, '\\Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
$this->assertSame($entity_a, $list[0]);
}
示例15: setUp
/**
* {@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);
}