X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FTests%2FCore%2FField%2FFieldInputValueNormalizerTraitTest.php;fp=web%2Fcore%2Ftests%2FDrupal%2FTests%2FCore%2FField%2FFieldInputValueNormalizerTraitTest.php;h=2d85b3aac73b7bd8d53068eae403cf6a26e51ebd;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/tests/Drupal/Tests/Core/Field/FieldInputValueNormalizerTraitTest.php b/web/core/tests/Drupal/Tests/Core/Field/FieldInputValueNormalizerTraitTest.php new file mode 100644 index 000000000..2d85b3aac --- /dev/null +++ b/web/core/tests/Drupal/Tests/Core/Field/FieldInputValueNormalizerTraitTest.php @@ -0,0 +1,100 @@ +assertEquals($expected_value, $this->normalizeValue($input_value, $main_property_name)); + } + + /** + * Test cases for ::testKeyValueByDelta. + */ + public function keyValueByDeltaTestCases() { + return [ + 'Integer' => [ + 1, + [['value' => 1]], + ], + 'Falsey integer' => [ + 0, + [['value' => 0]], + ], + 'String' => [ + 'foo', + [['value' => 'foo']], + ], + 'Empty string' => [ + '', + [['value' => '']], + ], + 'Null' => [ + NULL, + [], + ], + 'Empty field value' => [ + [], + [], + ], + 'Single delta' => [ + ['value' => 'foo'], + [['value' => 'foo']], + ], + 'Keyed delta' => [ + [['value' => 'foo']], + [['value' => 'foo']], + ], + 'Multiple keyed deltas' => [ + [['value' => 'foo'], ['value' => 'bar']], + [['value' => 'foo'], ['value' => 'bar']], + ], + 'No main property with keyed delta' => [ + [['foo' => 'bar']], + [['foo' => 'bar']], + NULL, + ], + 'No main property with single delta' => [ + ['foo' => 'bar'], + [['foo' => 'bar']], + NULL, + ], + 'No main property with empty array' => [ + [], + [], + NULL, + ], + ]; + } + + /** + * @covers ::normalizeValue + */ + public function testScalarWithNoMainProperty() { + $this->setExpectedException(\InvalidArgumentException::class, 'A main property is required when normalizing scalar field values.'); + $value = 'foo'; + $this->normalizeValue($value, NULL); + } + + /** + * @covers ::normalizeValue + */ + public function testKeyValueByDeltaUndefinedVariables() { + $this->assertEquals([], $this->normalizeValue($undefined_variable, 'value')); + $this->assertEquals([], $this->normalizeValue($undefined_variable['undefined_key'], 'value')); + } + +}