/** * @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)); }
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); }
/** * @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()); }
/** * {@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)); }
/** * 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)); }
/** * {@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)); }
/** * @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']); }
/** * {@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); }
/** * {@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); }
/** * {@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); }
/** * @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']); }
/** * {@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)); }
/** * {@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 ::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]); }
/** * {@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); }
/** * Sets up the content entity database storage. */ protected function setUpEntityStorage() { $this->connection = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')->disableOriginalConstructor()->getMock(); $this->entityManager->expects($this->any())->method('getDefinition')->will($this->returnValue($this->entityType)); $this->entityManager->expects($this->any())->method('getFieldStorageDefinitions')->will($this->returnValue($this->fieldDefinitions)); $this->entityManager->expects($this->any())->method('getBaseFieldDefinitions')->will($this->returnValue($this->fieldDefinitions)); $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache); }
protected function setUp() { parent::setUp(); $entity_storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface'); $this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface'); $this->entityManager->expects($this->any())->method('getStorage')->with('date_format')->willReturn($entity_storage); $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface'); $this->stringTranslation = $this->getMock('Drupal\\Core\\StringTranslation\\TranslationInterface'); $this->requestStack = $this->getMock('Symfony\\Component\\HttpFoundation\\RequestStack'); $config_factory = $this->getConfigFactoryStub(['system.date' => ['country' => ['default' => 'GB']]]); $container = new ContainerBuilder(); $container->set('config.factory', $config_factory); $container->set('string_translation', $this->getStringTranslationStub()); \Drupal::setContainer($container); $this->dateFormatter = new DateFormatter($this->entityManager, $this->languageManager, $this->stringTranslation, $this->getConfigFactoryStub(), $this->requestStack); $this->dateFormatterStub = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatter')->setConstructorArgs([$this->entityManager, $this->languageManager, $this->stringTranslation, $this->getConfigFactoryStub(), $this->requestStack])->setMethods(['formatDiff'])->getMock(); }
/** * Tests ConfigFieldMapper::setEntity(). * * @covers ::setEntity */ public function testSetEntity() { $entity_type = $this->getMock('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface'); $entity_type->expects($this->any())->method('getConfigPrefix')->will($this->returnValue('config_prefix')); $this->entityManager->expects($this->any())->method('getDefinition')->will($this->returnValue($entity_type)); $field_storage = $this->getMock('Drupal\\field\\FieldStorageConfigInterface'); $field_storage->expects($this->any())->method('id')->will($this->returnValue('field_storage_id')); $this->entity->expects($this->any())->method('getFieldStorageDefinition')->will($this->returnValue($field_storage)); $result = $this->configFieldMapper->setEntity($this->entity); $this->assertTrue($result); // Ensure that the configuration name was added to the mapper. $plugin_definition = $this->configFieldMapper->getPluginDefinition(); $this->assertTrue(in_array('config_prefix.field_storage_id', $plugin_definition['names'])); // Make sure setEntity() returns FALSE when called a second time. $result = $this->configFieldMapper->setEntity($this->entity); $this->assertFalse($result); }
/** * @covers ::link * * @dataProvider providerTestLink */ public function testLink($entity_label, $link_text, $expected_text, $link_rel = 'canonical', array $link_options = []) { $route_name_map = ['canonical' => 'entity.test_entity_type.canonical', 'edit-form' => 'entity.test_entity_type.edit_form']; $route_name = $route_name_map[$link_rel]; $entity_id = 'test_entity_id'; $entity_type_id = 'test_entity_type'; $expected = '<a href="/test_entity_type/test_entity_id">' . $expected_text . '</a>'; $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $entity_type->expects($this->once())->method('getLinkTemplates')->willReturn($route_name_map); $entity_type->expects($this->any())->method('getKey')->with('label')->willReturn('label'); $this->entityManager->expects($this->any())->method('getDefinition')->with($entity_type_id)->will($this->returnValue($entity_type)); /** @var \Drupal\Core\Entity\Entity $entity */ $entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', [['id' => $entity_id, 'label' => $entity_label], $entity_type_id]); $expected_link = Link::createFromRoute($expected_text, $route_name, [$entity_type_id => $entity_id], ['entity_type' => $entity_type_id, 'entity' => $entity] + $link_options)->setLinkGenerator($this->linkGenerator); $this->linkGenerator->expects($this->once())->method('generateFromLink')->with($this->equalTo($expected_link))->willReturn($expected); $this->assertSame($expected, $entity->link($link_text, $link_rel, $link_options)); }
/** * Tests ConfigEntityMapper::getTypeLabel(). */ public function testGetTypeLabel() { $entity_type = $this->getMock('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface'); $entity_type->expects($this->once())->method('getLabel')->will($this->returnValue('test')); $this->entityManager->expects($this->once())->method('getDefinition')->with('configurable_language')->will($this->returnValue($entity_type)); $result = $this->configEntityMapper->getTypeLabel(); $this->assertSame('test', $result); }
/** * @covers ::getPaymentDescription */ public function testGetPaymentDescriptionWithNonExistingField() { $entity_type_id = $this->randomMachineName(); $bundle = $this->randomMachineName(); $this->entityManager->expects($this->atLeastOnce())->method('getFieldDefinitions')->with($entity_type_id, $bundle)->willReturn([]); $this->sut->setEntityTypeId($entity_type_id); $this->sut->setBundle($bundle); $this->assertInstanceOf(TranslationWrapper::class, $this->sut->getPaymentDescription()); }
/** * @covers ::calculateDependencies */ public function testCalculateDependencies() { $format_id = 'filter.format.test'; $values = array('editor' => $this->editorId, 'format' => $format_id); $plugin = $this->getMockBuilder('Drupal\\editor\\Plugin\\EditorPluginInterface')->disableOriginalConstructor()->getMock(); $plugin->expects($this->once())->method('getPluginDefinition')->will($this->returnValue(array('provider' => 'test_module'))); $plugin->expects($this->once())->method('getDefaultSettings')->will($this->returnValue(array())); $this->editorPluginManager->expects($this->any())->method('createInstance')->with($this->editorId)->will($this->returnValue($plugin)); $entity = new Editor($values, $this->entityTypeId); $filter_format = $this->getMock('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface'); $filter_format->expects($this->once())->method('getConfigDependencyName')->will($this->returnValue('filter.format.test')); $storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface'); $storage->expects($this->once())->method('load')->with($format_id)->will($this->returnValue($filter_format)); $this->entityManager->expects($this->once())->method('getStorage')->with('filter_format')->will($this->returnValue($storage)); $dependencies = $entity->calculateDependencies()->getDependencies(); $this->assertContains('test_module', $dependencies['module']); $this->assertContains('filter.format.test', $dependencies['config']); }
/** * @covers ::delete */ public function testDelete() { $this->entity->id = $this->randomMachineName(); $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface'); // Testing the argument of the delete() method consumes too much memory. $storage->expects($this->once())->method('delete'); $this->entityManager->expects($this->once())->method('getStorage')->with($this->entityTypeId)->will($this->returnValue($storage)); $this->entity->delete(); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $entity_type = $this->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface'); $entity_type->expects($this->any())->method('getConfigPrefix')->willReturn('custom'); $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface'); $this->entityManager->expects($this->any())->method('getDefinition')->willReturn($entity_type); $this->configFactory = $this->getMock(ConfigFactoryInterface::class); $this->configStorage = $this->getMock(StorageInterface::class); $this->configManager = $this->getMock(ConfigManagerInterface::class); $this->moduleHandler = $this->getMock(ModuleHandlerInterface::class); $this->featuresManager = new FeaturesManager($this->root, $this->entityManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler); $string_translation = $this->getStringTranslationStub(); $container = new ContainerBuilder(); $container->set('string_translation', $string_translation); $container->set('app.root', $this->root); \Drupal::setContainer($container); }
/** * @covers ::getType */ public function testGetType() { // Ensure that FieldConfig::getType() is not delegated to // FieldStorage. $this->entityManager->expects($this->never())->method('getFieldStorageDefinitions'); $this->fieldStorage->expects($this->never())->method('getType'); $field = new FieldConfig(array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle', 'field_type' => 'test_field'), $this->entityTypeId); $this->assertEquals('test_field', $field->getType()); }
/** * Tests the access method with a non existing entity. */ public function testAccessWithNotExistingEntity() { $request = new Request(); $request->attributes->set('entity_type', 'entity_test'); $request->attributes->set('entity', 1); $this->entityManager->expects($this->once())->method('getDefinition')->with('entity_test')->will($this->returnValue(array('id' => 'entity_test'))); $this->entityStorage->expects($this->once())->method('load')->with(1)->will($this->returnValue(NULL)); $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); $this->assertSame(AccessCheckInterface::KILL, $this->editAccessCheck->access($request, $account)); }
/** * {@inheritdoc} */ public function setUp() { $this->entityTypeId = $this->randomName(); $this->provider = $this->randomName(); $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)); $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface'); $this->breakpointGroupId = $this->randomName(9); $this->breakpointGroup = $this->getMock('Drupal\\breakpoint\\Entity\\BreakpointGroup', array(), array(array('name' => 'test', 'id' => $this->breakpointGroupId))); $this->breakpointGroupStorage = $this->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface'); $this->breakpointGroupStorage->expects($this->any())->method('load')->with($this->breakpointGroupId)->will($this->returnValue($this->breakpointGroup)); $this->entityManager->expects($this->any())->method('getStorage')->will($this->returnValue($this->breakpointGroupStorage)); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); \Drupal::setContainer($container); }
/** * Tests the loadMultiple() method. */ public function testLoadMultiple() { $ids = array(1, 2); $storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface'); $storage->expects($this->once())->method('loadMultiple')->with($ids)->will($this->returnValue($this->entities)); $this->entityManager->expects($this->once())->method('getStorage')->with($this->entityTypeId)->will($this->returnValue($storage)); $workspace_manager = new WorkspaceManager($this->requestStack, $this->entityManager, $this->cacheRender); $entities = $workspace_manager->loadMultiple($ids); $this->assertSame($this->entities, $entities); }
/** * @covers ::access */ public function testAccess() { $access = $this->getMock('\\Drupal\\Core\\Entity\\EntityAccessControllerInterface'); $operation = $this->randomName(); $access->expects($this->at(0))->method('access')->with($this->entity, $operation)->will($this->returnValue(TRUE)); $access->expects($this->at(1))->method('createAccess')->will($this->returnValue(TRUE)); $this->entityManager->expects($this->exactly(2))->method('getAccessController')->will($this->returnValue($access)); $this->assertTrue($this->entity->access($operation)); $this->assertTrue($this->entity->access('create')); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface'); $mock_entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(), '', FALSE, TRUE, TRUE, array('bundle', 'access')); $mock_entity->expects($this->any())->method('bundle')->will($this->returnValue('test_bundle')); $mock_entity->expects($this->any())->method('access')->will($this->returnValueMap(array(array('test_op', NULL, FALSE, TRUE), array('test_op_2', NULL, FALSE, FALSE), array('test_op_3', NULL, FALSE, TRUE)))); $mock_entity_bundle_2 = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(), '', FALSE, TRUE, TRUE, array('bundle', 'access')); $mock_entity_bundle_2->expects($this->any())->method('bundle')->will($this->returnValue('test_bundle_2')); $mock_entity_bundle_2->expects($this->any())->method('access')->will($this->returnValueMap(array(array('test_op', NULL, FALSE, FALSE), array('test_op_2', NULL, FALSE, FALSE), array('test_op_3', NULL, FALSE, TRUE)))); $storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface'); // Setup values for IDs passed as strings or numbers. $value_map = array(array(array(), array()), array(array(1), array(1 => $mock_entity)), array(array('1'), array(1 => $mock_entity)), array(array(1, 2), array(1 => $mock_entity, 2 => $mock_entity_bundle_2)), array(array('1', '2'), array(1 => $mock_entity, 2 => $mock_entity_bundle_2)), array(array(2), array(2 => $mock_entity_bundle_2)), array(array('2'), array(2 => $mock_entity_bundle_2))); $storage->expects($this->any())->method('loadMultiple')->will($this->returnValueMap($value_map)); $this->entityManager->expects($this->any())->method('getStorage')->with('entity_test')->will($this->returnValue($storage)); $this->executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock(); $this->display = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')->disableOriginalConstructor()->getMock(); $definition = array('entity_type' => 'entity_test'); $this->argumentValidator = new Entity(array(), 'entity_test', $definition, $this->entityManager); }