Mercurial > hg > isophonics-drupal-site
diff core/modules/options/tests/src/Kernel/OptionsFieldUnitTestBase.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/options/tests/src/Kernel/OptionsFieldUnitTestBase.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,81 @@ +<?php + +namespace Drupal\Tests\options\Kernel; + +use Drupal\field\Entity\FieldConfig; +use Drupal\Tests\field\Kernel\FieldKernelTestBase; +use Drupal\field\Entity\FieldStorageConfig; + +/** + * Base class for Options module integration tests. + */ +abstract class OptionsFieldUnitTestBase extends FieldKernelTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = ['options']; + + /** + * The field name used in the test. + * + * @var string + */ + protected $fieldName = 'test_options'; + + /** + * The field storage definition used to created the field storage. + * + * @var array + */ + protected $fieldStorageDefinition; + + /** + * The list field storage used in the test. + * + * @var \Drupal\field\Entity\FieldStorageConfig + */ + protected $fieldStorage; + + /** + * The list field used in the test. + * + * @var \Drupal\field\Entity\FieldConfig + */ + protected $field; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->container->get('router.builder')->rebuild(); + + $this->fieldStorageDefinition = [ + 'field_name' => $this->fieldName, + 'entity_type' => 'entity_test', + 'type' => 'list_integer', + 'cardinality' => 1, + 'settings' => [ + 'allowed_values' => [1 => 'One', 2 => 'Two', 3 => 'Three'], + ], + ]; + $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition); + $this->fieldStorage->save(); + + $this->field = FieldConfig::create([ + 'field_storage' => $this->fieldStorage, + 'bundle' => 'entity_test', + ]); + $this->field->save(); + + entity_get_form_display('entity_test', 'entity_test', 'default') + ->setComponent($this->fieldName, [ + 'type' => 'options_buttons', + ]) + ->save(); + } + +}