function setUp()
 {
     parent::setUp();
     $this->field_name = 'test_options';
     entity_create('field_storage_config', array('name' => $this->field_name, 'entity_type' => 'entity_test_rev', 'type' => 'list_text', 'cardinality' => 1, 'settings' => array('allowed_values_function' => 'options_test_dynamic_values_callback')))->save();
     $this->instance = entity_create('field_instance_config', array('field_name' => $this->field_name, 'entity_type' => 'entity_test_rev', 'bundle' => 'entity_test_rev', 'required' => TRUE))->save();
     entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default')->setComponent($this->field_name, array('type' => 'options_select'))->save();
     // Create an entity and prepare test data that will be used by
     // options_test_dynamic_values_callback().
     $values = array('user_id' => mt_rand(1, 10), 'name' => $this->randomMachineName());
     $this->entity = entity_create('entity_test_rev', $values);
     $this->entity->save();
     $this->test = array('label' => $this->entity->label(), 'uuid' => $this->entity->uuid(), 'bundle' => $this->entity->bundle(), 'uri' => $this->entity->url());
 }
 protected function setUp()
 {
     parent::setUp();
     $field_name = 'test_options';
     $this->fieldStorage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test_rev', 'type' => 'list_string', 'cardinality' => 1, 'settings' => ['allowed_values_function' => 'options_test_dynamic_values_callback']]);
     $this->fieldStorage->save();
     $this->field = FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test_rev', 'bundle' => 'entity_test_rev', 'required' => TRUE])->save();
     entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default')->setComponent($field_name, ['type' => 'options_select'])->save();
     // Create an entity and prepare test data that will be used by
     // options_test_dynamic_values_callback().
     $values = ['user_id' => mt_rand(1, 10), 'name' => $this->randomMachineName()];
     $this->entity = EntityTestRev::create($values);
     $this->entity->save();
     $this->test = ['label' => $this->entity->label(), 'uuid' => $this->entity->uuid(), 'bundle' => $this->entity->bundle(), 'uri' => $this->entity->url()];
 }
Exemple #3
0
 /**
  * @covers ::label
  */
 public function testLabel()
 {
     // Make a mock with one method that we use as the entity's uri_callback. We
     // check that it is called, and that the entity's label is the callback's
     // return value.
     $callback_label = $this->randomMachineName();
     $property_label = $this->randomMachineName();
     $callback_container = $this->getMock(get_class());
     $callback_container->expects($this->once())->method(__FUNCTION__)->will($this->returnValue($callback_label));
     $this->entityType->expects($this->at(0))->method('getLabelCallback')->will($this->returnValue(array($callback_container, __FUNCTION__)));
     $this->entityType->expects($this->at(1))->method('getLabelCallback')->will($this->returnValue(NULL));
     $this->entityType->expects($this->at(2))->method('getKey')->with('label')->will($this->returnValue('label'));
     // Set a dummy property on the entity under test to test that the label can
     // be returned form a property if there is no callback.
     $this->entityManager->expects($this->at(1))->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue(array('entity_keys' => array('label' => 'label'))));
     $this->entity->label = $property_label;
     $this->assertSame($callback_label, $this->entity->label());
     $this->assertSame($property_label, $this->entity->label());
 }