예제 #1
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');
    $field = $field_definition->reveal();

    $storage = $this->prophesize(DynamicallyFieldableEntityStorageInterface::class);
    $storage->onFieldDefinitionDelete($field)
      ->shouldBeCalledTimes(1);
    $this->entityManager->setHandler('storage', 'test_entity_type', $storage->reveal());
    $entity = $this->prophesize(EntityTypeInterface::class);
    $this->setUpEntityManager(array('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->entityManager->onFieldDefinitionDelete($field);
  }
예제 #2
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());
 }
예제 #3
0
 /**
  * @covers ::onFieldDefinitionDelete
  */
 public function testonFieldDefinitionDeleteSingleBundles()
 {
     $field_definition = $this->getMock('Drupal\\Core\\Field\\FieldDefinitionInterface');
     $field_definition->expects($this->atLeastOnce())->method('getTargetEntityTypeId')->willReturn('test_entity_type');
     $field_definition->expects($this->atLeastOnce())->method('getTargetBundle')->willReturn('test_bundle');
     $field_definition->expects($this->atLeastOnce())->method('getName')->willReturn('test_field');
     $storage = $this->getMock('Drupal\\Core\\Entity\\DynamicallyFieldableEntityStorageInterface');
     $class = get_class($storage);
     $entity = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $entity->expects($this->once())->method('getHandlerClass')->with('storage')->will($this->returnValue($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);
     // Set up the stored bundle field map.
     $key_value_store = $this->getMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreInterface');
     $this->keyValueFactory->expects($this->exactly(2))->method('get')->with('entity.definitions.bundle_field_map')->willReturn($key_value_store);
     $key_value_store->expects($this->once())->method('get')->with('test_entity_type')->willReturn(['test_field' => ['type' => 'test_type', 'bundles' => ['test_bundle' => 'test_bundle', 'second_bundle' => 'second_bundle']]]);
     $key_value_store->expects($this->once())->method('set')->with('test_entity_type', ['test_field' => ['type' => 'test_type', 'bundles' => ['second_bundle' => 'second_bundle']]]);
     $this->entityManager->onFieldDefinitionDelete($field_definition);
 }