public function NodeTypePreviewImageFormTest::testGetFormWithFieldAndStyle in Acquia Content Hub 8
Tests the getForm() method, with an image field and with style.
@covers ::getForm
File
- tests/
src/ Unit/ Form/ NodeTypePreviewImageFormTest.php, line 151
Class
- NodeTypePreviewImageFormTest
- PHPUnit test for the NodeTypePreviewImageForm class.
Namespace
Drupal\Tests\acquia_contenthub\Unit\FormCode
public function testGetFormWithFieldAndStyle() {
$preview_image_form = new NodeTypePreviewImageForm($this->contenthubEntityManager, $this->entityTypeManager, $this->entityFieldManager);
$preview_image_form
->setStringTranslation($this
->getStringTranslationStub());
$field_image_definition = $this
->getFieldDefinition('image');
$field_definitions = [
'field_description' => $this
->getFieldDefinition('description'),
'field_image' => $field_image_definition,
'field_entity_reference' => $this
->getFieldDefinition('entity_reference'),
];
$entity_reference_field_definitions = [
'field_child_image' => $this
->getFieldDefinition('image'),
// This line is testing circular reference handling.
// See $processedFieldHashes.
'field_image' => $field_image_definition,
];
$entity_type_definition = $this
->createMock('Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityFieldManager
->expects($this
->at(0))
->method('getFieldDefinitions')
->with('node', 'article')
->willReturn($field_definitions);
$this->contenthubEntityConfig
->expects($this
->once())
->method('getPreviewImageField')
->with('article')
->willReturn('field_media->field_image');
$this->contenthubEntityConfig
->expects($this
->once())
->method('getPreviewImageStyle')
->with('article')
->willReturn('medium');
$this->entityTypeManager
->expects($this
->once())
->method('getDefinition')
->with('entity_reference_setting')
->willReturn($entity_type_definition);
$entity_type_definition
->expects($this
->once())
->method('entityClassImplements')
->with('\\Drupal\\Core\\Entity\\FieldableEntityInterface')
->willReturn(TRUE);
$this->entityFieldManager
->expects($this
->at(1))
->method('getFieldDefinitions')
->with('entity_reference_setting', 'entity_reference')
->willReturn($entity_reference_field_definitions);
acquia_polyfill_controller_set_return('image_style_options', [
'medium' => 'Medium',
]);
$form = $preview_image_form
->getForm('article');
$expected_field_options = [
'field_image' => 'Image Label (field_image)',
'field_entity_reference->field_child_image' => 'Entity_reference Label->Image Label (field_entity_reference->field_child_image)',
];
$this
->assertEquals('Acquia Content Hub', $form['#title']);
$this
->assertEquals($expected_field_options, $form['field']['#options']);
$this
->assertEquals('field_media->field_image', $form['field']['#default_value']);
$this
->assertEquals([
'acquia_contenthub_preview_image_add' => 'Acquia Content Hub Preview Image (150×150)',
'medium' => 'Medium',
], $form['style']['#options']);
$this
->assertEquals('medium', $form['style']['#default_value']);
}