Skip to content
Snippets Groups Projects
Commit ac6cca64 authored by Vadym Abramchuk's avatar Vadym Abramchuk
Browse files

Issue #3400982: Add address field type tests

parent a363a236
No related branches found
No related tags found
1 merge request!80Resolve #3400982 "Field processor plugins"
......@@ -64,8 +64,13 @@ abstract class FieldProcessorTestBase extends KernelTestBase {
public function testExportFieldValue(
array $fieldStorageDefinition,
mixed $fieldValue,
array $expectedExportOutput
array $expectedExportOutput,
array $extraModules = []
): void {
if ($extraModules) {
$this->enableModules($extraModules);
}
$this->prepareNodeTypeWithField($fieldStorageDefinition);
$node = Node::create([
......@@ -108,11 +113,17 @@ abstract class FieldProcessorTestBase extends KernelTestBase {
public function testImportFieldValue(
array $fieldStorageDefinition,
mixed $dataToImport,
mixed $expectedFieldValue = NULL
mixed $expectedFieldValue = NULL,
array $extraModules = []
): void {
if ($expectedFieldValue === NULL) {
$expectedFieldValue = $dataToImport;
}
if ($extraModules) {
$this->enableModules($extraModules);
}
$this->prepareNodeTypeWithField($fieldStorageDefinition);
$node = Node::create([
......
......@@ -11,11 +11,56 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
*/
class SimpleFieldProcessorTest extends FieldProcessorTestBase {
// The address field data used for testing.
const ADDRESS_FIELD_TEST_DATA = [
'country_code' => 'US',
'administrative_area' => 'CA',
'locality' => 'Mountain View',
'postal_code' => '94043',
'address_line1' => '1098 Alta Ave',
'organization' => 'Google Inc.',
'given_name' => 'John',
'family_name' => 'Smith',
];
// Full address field data, including all possible values; that's what
// get stored in the field.
const FULL_ADDRESS_FIELD_TEST_DATA = [
'country_code' => 'US',
'administrative_area' => 'CA',
'locality' => 'Mountain View',
'postal_code' => '94043',
'address_line1' => '1098 Alta Ave',
'organization' => 'Google Inc.',
'given_name' => 'John',
'family_name' => 'Smith',
'langcode' => NULL,
'dependent_locality' => NULL,
'sorting_code' => NULL,
'address_line2' => NULL,
'additional_name' => NULL,
];
/**
* {@inheritdoc}
*/
protected function importFieldValueDataProvider(): array {
return [
'address' => [
[
'type' => 'address',
'settings' => [
'available_countries' => [],
],
],
[
0 => self::ADDRESS_FIELD_TEST_DATA,
],
[
0 => self::FULL_ADDRESS_FIELD_TEST_DATA,
],
['address'],
],
'string' => [
[
'type' => 'string',
......@@ -52,6 +97,19 @@ class SimpleFieldProcessorTest extends FieldProcessorTestBase {
*/
protected function exportFieldValueDataProvider(): array {
return [
'address' => [
[
'type' => 'address',
'settings' => [
'available_countries' => [],
],
],
self::ADDRESS_FIELD_TEST_DATA,
[
0 => self::FULL_ADDRESS_FIELD_TEST_DATA,
],
['address'],
],
'string' => [
[
'type' => 'string',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment