/**
  * Tests the form ID generation.
  *
  * @covers ::getFormId()
  *
  * @dataProvider providerTestFormIds
  */
 public function testFormId($expected, $definition)
 {
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $entity_type->expects($this->any())->method('hasKey')->with('bundle')->will($this->returnValue($definition['bundle']));
     $entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', array(array(), $definition['entity_type']), '', TRUE, TRUE, TRUE, array('getEntityType', 'bundle'));
     $entity->expects($this->any())->method('getEntityType')->will($this->returnValue($entity_type));
     $entity->expects($this->any())->method('bundle')->will($this->returnValue($definition['bundle']));
     $this->entityForm->setEntity($entity);
     $this->entityForm->setOperation($definition['operation']);
     $this->assertSame($expected, $this->entityForm->getFormId());
 }
Exemplo n.º 2
0
 /**
  * @covers ::copyFormValuesToEntity
  */
 public function testCopyFormValuesToEntity()
 {
     $entity_id = 'test_config_entity_id';
     $values = ['id' => $entity_id];
     $entity = $this->getMockBuilder('\\Drupal\\Tests\\Core\\Config\\Entity\\Fixtures\\ConfigEntityBaseWithPluginCollections')->setConstructorArgs([$values, 'test_config_entity'])->setMethods(['getPluginCollections'])->getMock();
     $entity->expects($this->atLeastOnce())->method('getPluginCollections')->willReturn(['key_controlled_by_plugin_collection' => NULL]);
     $this->entityForm->setEntity($entity);
     $form_state = (new FormState())->setValues(['regular_key' => 'foo', 'key_controlled_by_plugin_collection' => 'bar']);
     $result = $this->entityForm->buildEntity([], $form_state);
     $this->assertSame($entity_id, $result->id());
     // The regular key should have a value, but the one controlled by a plugin
     // collection should not have been set.
     $this->assertSame('foo', $result->get('regular_key'));
     $this->assertNull($result->get('key_controlled_by_plugin_collection'));
 }
Exemplo n.º 3
0
 /**
  * Sets up the storage accessed via the entity type manager in the form.
  *
  * @return \Prophecy\Prophecy\ObjectProphecy
  *   The storage prophecy.
  */
 protected function setUpStorage()
 {
     $storage = $this->prophesize(EntityStorageInterface::class);
     $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
     $entity_type_manager->getDefinition($this->entityType->id())->willReturn($this->entityType);
     $entity_type_manager->getStorage($this->entityType->id())->willReturn($storage->reveal());
     $this->entityForm->setEntityTypeManager($entity_type_manager->reveal());
     return $storage;
 }