EdgeEntityDisplaySettingsFormTest.php in Apigee Edge 8
File
tests/src/Kernel/Form/EdgeEntityDisplaySettingsFormTest.php
View source
<?php
namespace Drupal\Tests\apigee_edge\Kernel\Form;
use Drupal\apigee_edge\Form\EdgeEntityDisplaySettingsForm;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\Core\Form\FormState;
use Drupal\KernelTests\KernelTestBase;
class EdgeEntityDisplaySettingsFormTest extends KernelTestBase {
const ENTITY_TYPE = 'developer_app';
protected static $modules = [
'system',
'apigee_edge',
'key',
];
public function testForm() {
$builder = $this->container
->get('form_builder');
$form = $builder
->getForm(EdgeEntityDisplaySettingsForm::class, static::ENTITY_TYPE);
$display_type_options = $form['display_settings']['display_type']['#options'];
static::assertCount(3, $display_type_options);
static::assertSame('Default', (string) $display_type_options['default']);
static::assertSame('Display mode', (string) $display_type_options['view_mode']);
$view_mode_options = $form['display_settings']['display_mode_container']['view_mode']['#options'];
static::assertCount(1, $view_mode_options);
static::assertSame('Default', (string) $view_mode_options['default']);
EntityViewMode::create([
'id' => static::ENTITY_TYPE . '.foo',
'targetEntityType' => static::ENTITY_TYPE,
'label' => 'Foo',
'status' => TRUE,
])
->save();
$builder = $this->container
->get('form_builder');
$form = $builder
->getForm(EdgeEntityDisplaySettingsForm::class, static::ENTITY_TYPE);
$view_mode_options = $form['display_settings']['display_mode_container']['view_mode']['#options'];
static::assertCount(2, $view_mode_options);
static::assertSame('Default', (string) $view_mode_options['default']);
static::assertSame('Foo', (string) $view_mode_options['foo']);
$form_state = new FormState();
$form_state
->setValue('display_type', 'view_mode');
$form_state
->setValue('view_mode', 'foo');
$this->container
->get('form_builder')
->submitForm(EdgeEntityDisplaySettingsForm::class, $form_state, static::ENTITY_TYPE);
$config = $this
->config('apigee_edge.display_settings.' . static::ENTITY_TYPE);
static::assertSame('view_mode', $config
->get('display_type'));
static::assertSame('foo', $config
->get('view_mode'));
}
}