コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     // Mock a logger.
     $this->logger = $this->prophesize(LoggerInterface::class);
     // Mock the logger service, make it return our mocked logger, and register
     // it in the container.
     $this->loggerFactory = $this->prophesize(LoggerChannelFactoryInterface::class);
     $this->loggerFactory->get('rules')->willReturn($this->logger->reveal());
     $this->container->set('logger.factory', $this->loggerFactory->reveal());
     // Mock a parameter bag.
     $this->parameterBag = $this->prophesize(ParameterBag::class);
     // Mock a request, and set our mocked parameter bag as it attributes
     // property.
     $this->currentRequest = $this->prophesize(Request::class);
     $this->currentRequest->attributes = $this->parameterBag->reveal();
     // Mock the request stack, make it return our mocked request when the
     // current request is requested, and register it in the container.
     $this->requestStack = $this->prophesize(RequestStack::class);
     $this->requestStack->getCurrentRequest()->willReturn($this->currentRequest);
     $this->container->set('request_stack', $this->requestStack->reveal());
     // Mock the current path stack.
     $this->currentPathStack = $this->prophesize(CurrentPathStack::class);
     $this->container->set('path.current', $this->currentPathStack->reveal());
     // Instantiate the redirect action.
     $this->action = $this->actionManager->createInstance('rules_page_redirect');
 }
コード例 #2
0
 /**
  * Tests the getAllBundleInfo() method.
  *
  * @covers ::getAllBundleInfo
  */
 public function testGetAllBundleInfo()
 {
     $this->moduleHandler->invokeAll('entity_bundle_info')->willReturn([]);
     $this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL);
     $apple = $this->prophesize(EntityTypeInterface::class);
     $apple->getLabel()->willReturn('Apple');
     $apple->getBundleOf()->willReturn(NULL);
     $banana = $this->prophesize(EntityTypeInterface::class);
     $banana->getLabel()->willReturn('Banana');
     $banana->getBundleOf()->willReturn(NULL);
     $this->setUpEntityTypeDefinitions(['apple' => $apple, 'banana' => $banana]);
     $this->cacheBackend->get('entity_bundle_info:en')->willReturn(FALSE);
     $this->cacheBackend->set('entity_bundle_info:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_bundles'])->will(function () {
         $this->get('entity_bundle_info:en')->willReturn((object) ['data' => 'cached data'])->shouldBeCalled();
     })->shouldBeCalled();
     $this->cacheTagsInvalidator->invalidateTags(['entity_bundles'])->shouldBeCalled();
     $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled();
     $expected = ['apple' => ['apple' => ['label' => 'Apple']], 'banana' => ['banana' => ['label' => 'Banana']]];
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $this->entityTypeBundleInfo->clearCachedBundles();
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame('cached data', $bundle_info);
 }
コード例 #3
0
 /**
  * @covers ::onFieldDefinitionDelete
  */
 public function testOnFieldDefinitionDeleteSingleBundles()
 {
     $field_definition = $this->prophesize(FieldDefinitionInterface::class);
     $field_definition->getTargetEntityTypeId()->willReturn('test_entity_type');
     $field_definition->getTargetBundle()->willReturn('test_bundle');
     $field_definition->getName()->willReturn('test_field');
     $storage = $this->prophesize(DynamicallyFieldableEntityStorageInterface::class);
     $storage->onFieldDefinitionDelete($field_definition->reveal())->shouldBeCalledTimes(1);
     $this->entityTypeManager->getStorage('test_entity_type')->willReturn($storage->reveal());
     $entity = $this->prophesize(EntityTypeInterface::class);
     $this->setUpEntityManager(['test_entity_type' => $entity]);
     // Set up the stored bundle field map.
     $key_value_store = $this->prophesize(KeyValueStoreInterface::class);
     $this->keyValueFactory->get('entity.definitions.bundle_field_map')->willReturn($key_value_store->reveal());
     $key_value_store->get('test_entity_type')->willReturn(['test_field' => ['type' => 'test_type', 'bundles' => ['test_bundle' => 'test_bundle', 'second_bundle' => 'second_bundle']]]);
     $key_value_store->set('test_entity_type', ['test_field' => ['type' => 'test_type', 'bundles' => ['second_bundle' => 'second_bundle']]])->shouldBeCalled();
     $this->fieldDefinitionListener->onFieldDefinitionDelete($field_definition->reveal());
 }
コード例 #4
0
 /**
  * @covers ::getFieldMapByFieldType
  */
 public function testGetFieldMapByFieldType()
 {
     // Set up a content entity type.
     $entity_type = $this->prophesize(ContentEntityTypeInterface::class);
     $entity_class = EntityManagerTestEntity::class;
     // Set up the entity type bundle info to return two bundles for the
     // fieldable entity type.
     $this->entityTypeBundleInfo->getBundleInfo('test_entity_type')->willReturn(['first_bundle' => 'first_bundle', 'second_bundle' => 'second_bundle'])->shouldBeCalled();
     $this->moduleHandler->getImplementations('entity_base_field_info')->willReturn([])->shouldBeCalled();
     // Define an ID field definition as a base field.
     $id_definition = $this->prophesize(FieldDefinitionInterface::class);
     $id_definition->getType()->willReturn('integer')->shouldBeCalled();
     $base_field_definitions = ['id' => $id_definition->reveal()];
     $entity_class::$baseFieldDefinitions = $base_field_definitions;
     // Set up the stored bundle field map.
     $key_value_store = $this->prophesize(KeyValueStoreInterface::class);
     $this->keyValueFactory->get('entity.definitions.bundle_field_map')->willReturn($key_value_store->reveal())->shouldBeCalled();
     $key_value_store->getAll()->willReturn(['test_entity_type' => ['by_bundle' => ['type' => 'string', 'bundles' => ['second_bundle' => 'second_bundle']]]])->shouldBeCalled();
     // Mock the base field definition override.
     $override_entity_type = $this->prophesize(EntityTypeInterface::class);
     $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity_type, 'base_field_override' => $override_entity_type]);
     $entity_type->getClass()->willReturn($entity_class)->shouldBeCalled();
     $entity_type->getKeys()->willReturn(['default_langcode' => 'default_langcode'])->shouldBeCalled();
     $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE)->shouldBeCalled();
     $entity_type->isTranslatable()->shouldBeCalled();
     $entity_type->getProvider()->shouldBeCalled();
     $override_entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE)->shouldBeCalled();
     $integerFields = $this->entityFieldManager->getFieldMapByFieldType('integer');
     $this->assertCount(1, $integerFields['test_entity_type']);
     $this->assertArrayNotHasKey('non_fieldable', $integerFields);
     $this->assertArrayHasKey('id', $integerFields['test_entity_type']);
     $this->assertArrayNotHasKey('by_bundle', $integerFields['test_entity_type']);
     $stringFields = $this->entityFieldManager->getFieldMapByFieldType('string');
     $this->assertCount(1, $stringFields['test_entity_type']);
     $this->assertArrayNotHasKey('non_fieldable', $stringFields);
     $this->assertArrayHasKey('by_bundle', $stringFields['test_entity_type']);
     $this->assertArrayNotHasKey('id', $stringFields['test_entity_type']);
 }
コード例 #5
0
 /**
  * @covers ::onFieldDefinitionDelete
  */
 public function testOnFieldDefinitionDeleteSingleBundles()
 {
     $field_definition = $this->prophesize(FieldDefinitionInterface::class);
     $field_definition->getTargetEntityTypeId()->willReturn('test_entity_type');
     $field_definition->getTargetBundle()->willReturn('test_bundle');
     $field_definition->getName()->willReturn('test_field');
     $class = $this->getMockClass(DynamicallyFieldableEntityStorageInterface::class);
     $entity = $this->prophesize(EntityTypeInterface::class);
     $entity->getHandlerClass('storage')->willReturn($class);
     $this->setUpEntityManager(array('test_entity_type' => $entity));
     // The entity manager will instantiate a new object with the given class
     // name. Define the mock expectations on that.
     $storage = $this->entityManager->getStorage('test_entity_type');
     $storage->expects($this->once())->method('onFieldDefinitionDelete')->with($field_definition->reveal());
     // Set up the stored bundle field map.
     $key_value_store = $this->prophesize(KeyValueStoreInterface::class);
     $this->keyValueFactory->get('entity.definitions.bundle_field_map')->willReturn($key_value_store->reveal());
     $key_value_store->get('test_entity_type')->willReturn(['test_field' => ['type' => 'test_type', 'bundles' => ['test_bundle' => 'test_bundle', 'second_bundle' => 'second_bundle']]]);
     $key_value_store->set('test_entity_type', ['test_field' => ['type' => 'test_type', 'bundles' => ['second_bundle' => 'second_bundle']]])->shouldBeCalled();
     $this->entityManager->onFieldDefinitionDelete($field_definition->reveal());
 }