Skip to content
Snippets Groups Projects
Commit d90bbeb2 authored by Patrick Waller's avatar Patrick Waller Committed by Stephen Lucero
Browse files

Issue #3514132 by slucero, firewaller, minsharm: TypeError:...

Issue #3514132 by slucero, firewaller, minsharm: TypeError: Drupal\Core\Utility\Token::replacePlain(): Argument #1 ($plain) must be of type string, null given
parent cbd62bdb
No related branches found
No related tags found
1 merge request!150Resolve #3514132 "TypeError: Drupal\Core\Utility\Token::replacePlain(): Argument #1 ($plain) must be of type string, null given"
Pipeline #484877 failed
......@@ -74,7 +74,8 @@ class TokenProcessor extends PatternFieldProcessorBase {
*/
public function applies(SchemaContract $propertySchema, $propertyValue = NULL): bool {
return property_exists($propertySchema, 'type')
&& $propertySchema->type == 'string';
&& $propertySchema->type == 'string'
&& is_string($propertyValue);
}
/**
......
......@@ -80,7 +80,8 @@ class WysiwygFieldProcessor extends PatternFieldProcessorBase {
*/
public function applies(SchemaContract $propertySchema, $propertyValue = NULL): bool {
$textProfile = $this->getTextProfile();
return is_string($textProfile) && $textProfile !== ''
return is_string($propertyValue)
&& is_string($textProfile) && $textProfile !== ''
&& property_exists($propertySchema, 'type') && $propertySchema->type == 'string'
&& property_exists($propertySchema, 'format') && $propertySchema->format == 'html'
&& isset($propertySchema->options) && property_exists($propertySchema->options, 'wysiwyg')
......
......@@ -77,14 +77,21 @@ class TokenProcessorTest extends UnitTestCase {
/**
* Tests applies method in various use cases.
*
* @param \Swaggest\JsonSchema\SchemaContract $propertySchema
* The schema object to be tested against.
* @param mixed $value
* An example value for testing.
* @param bool $expected
* The expected result.
*/
#[DataProvider('providerApplies')]
public function testApplies(SchemaContract $propertySchema, bool $expected) {
$this->assertEquals($expected, $this->plugin->applies($propertySchema));
public function testApplies(SchemaContract $propertySchema, mixed $value, bool $expected) {
$this->assertEquals($expected, $this->plugin->applies($propertySchema, $value));
}
/**
* Data provider for the applies test.
* Data provider for testApplies().
*/
public static function providerApplies() {
$schema_json = <<<JSON
......@@ -152,26 +159,53 @@ class TokenProcessorTest extends UnitTestCase {
$schema = Schema::import(json_decode($schema_json));
$properties = $schema->getProperties();
$cases = [];
$cases['full_object'] = [$schema, FALSE];
$cases['html_wysiwyg_field'] = [$properties->formatted_text, TRUE];
$cases['plain_text_field'] = [$properties->text, TRUE];
$cases['object_property'] = [$properties->image, FALSE];
$cases['nested_string_field'] = [
return [
'full_object' => [
$schema,
['text' => 'My text value'],
FALSE,
],
'html_wysiwyg_field' => [
$properties->formatted_text,
'My <strong>formatted</strong> text',
TRUE,
],
'plain_text_field' => [
$properties->text,
'A plain text value',
TRUE,
],
'object_property' => [
$properties->image,
['image_url' => 'my/example/image.jpg'],
FALSE,
],
'nested_string_field' => [
$properties->image->getProperties()->image_url,
'my/example/image.jpg',
TRUE,
],
'number_property' => [
$properties->amount,
12345,
FALSE,
],
'array_property' => [
$properties->breakpoints,
['xxs', 'md', 'lg'],
FALSE,
],
'string with mismatched value' => [
$properties->formatted_text,
['nested value' => 'My nested string value'],
FALSE,
],
'string with null value' => [
$properties->formatted_text,
NULL,
FALSE,
],
];
$cases['number_property'] = [$properties->amount, FALSE];
$cases['array_property'] = [$properties->breakpoints, FALSE];
return $cases;
}
public function testApplyReplace() {
......
......@@ -74,10 +74,17 @@ class WysiwygFieldProcessorTest extends UnitTestCase {
/**
* Tests applies method in various use cases.
*
* @param \Swaggest\JsonSchema\SchemaContract $propertySchema
* The schema object to be tested against.
* @param mixed $value
* An example value for testing.
* @param bool $expected
* The expected result.
*/
#[DataProvider('providerApplies')]
public function testApplies(SchemaContract $propertySchema, bool $expected) {
$this->assertEquals($expected, $this->plugin->applies($propertySchema));
public function testApplies(SchemaContract $propertySchema, mixed $value, bool $expected) {
$this->assertEquals($expected, $this->plugin->applies($propertySchema, $value));
}
/**
......@@ -149,26 +156,53 @@ class WysiwygFieldProcessorTest extends UnitTestCase {
$schema = Schema::import(json_decode($schema_json));
$properties = $schema->getProperties();
$cases = [];
$cases['full_object'] = [$schema, FALSE];
$cases['html_wysiwyg_field'] = [$properties->formatted_text, TRUE];
$cases['plain_text_field'] = [$properties->text, FALSE];
$cases['object_property'] = [$properties->image, FALSE];
$cases['nested_string_field'] = [
return [
'full_object' => [
$schema,
['text' => 'My text value'],
FALSE,
],
'html_wysiwyg_field' => [
$properties->formatted_text,
'My <strong>formatted</strong> text',
TRUE,
],
'plain_text_field' => [
$properties->text,
'A plain text value',
FALSE,
],
'object_property' => [
$properties->image,
['image_url' => 'my/example/image.jpg'],
FALSE,
],
'nested_string_field' => [
$properties->image->getProperties()->image_url,
'my/example/image.jpg',
FALSE,
],
'number_property' => [
$properties->amount,
12345,
FALSE,
],
'array_property' => [
$properties->breakpoints,
['xxs', 'md', 'lg'],
FALSE,
],
'string with mismatched value' => [
$properties->formatted_text,
['nested value' => 'My nested string value'],
FALSE,
],
'string with null value' => [
$properties->formatted_text,
NULL,
FALSE,
],
];
$cases['number_property'] = [$properties->amount, FALSE];
$cases['array_property'] = [$properties->breakpoints, FALSE];
return $cases;
}
public function testApply() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment