Skip to content

Commit

Permalink
Merge branch 'next-13521/fix-cms-text-element-with-null-value' into '…
Browse files Browse the repository at this point in the history
…master'

NEXT-13521 - Fix cms text element with null value

See merge request shopware/6/product/platform!4354
  • Loading branch information
taltholtmann committed Feb 1, 2021
2 parents c0afed1 + ad5cb2f commit 6e6c554
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Expand Up @@ -38,7 +38,7 @@ public function enrich(CmsSlotEntity $slot, ResolverContext $resolverContext, El

if ($config->isStatic()) {
if ($resolverContext instanceof EntityResolverContext) {
$content = $this->resolveEntityValues($resolverContext, $config->getValue());
$content = $this->resolveEntityValues($resolverContext, (string) $config->getValue());

$text->setContent((string) $content);
} else {
Expand Down
Expand Up @@ -214,4 +214,54 @@ public function testWithStaticContentAndMappedVariableNotFound(): void
static::assertInstanceOf(TextStruct::class, $textStruct);
static::assertSame('<h1>Title {{ product.unknownProperty }}</h1>', $textStruct->getContent());
}

public function testWithStaticContentAndNullValue(): void
{
$product = new ProductEntity();
$product->setName('TextProduct');

$resolverContext = new EntityResolverContext($this->createMock(SalesChannelContext::class), new Request(), $this->createMock(ProductDefinition::class), $product);
$result = new ElementDataCollection();

$fieldConfig = new FieldConfigCollection();
$fieldConfig->add(new FieldConfig('content', FieldConfig::SOURCE_STATIC, null));

$slot = new CmsSlotEntity();
$slot->setUniqueIdentifier('id');
$slot->setType('text');
$slot->setConfig([]);
$slot->setFieldConfig($fieldConfig);

$this->textResolver->enrich($slot, $resolverContext, $result);

/** @var TextStruct|null $textStruct */
$textStruct = $slot->getData();
static::assertInstanceOf(TextStruct::class, $textStruct);
static::assertSame('', $textStruct->getContent());
}

public function testWithStaticContentAndEmptyValue(): void
{
$product = new ProductEntity();
$product->setName('TextProduct');

$resolverContext = new EntityResolverContext($this->createMock(SalesChannelContext::class), new Request(), $this->createMock(ProductDefinition::class), $product);
$result = new ElementDataCollection();

$fieldConfig = new FieldConfigCollection();
$fieldConfig->add(new FieldConfig('content', FieldConfig::SOURCE_STATIC, ''));

$slot = new CmsSlotEntity();
$slot->setUniqueIdentifier('id');
$slot->setType('text');
$slot->setConfig([]);
$slot->setFieldConfig($fieldConfig);

$this->textResolver->enrich($slot, $resolverContext, $result);

/** @var TextStruct|null $textStruct */
$textStruct = $slot->getData();
static::assertInstanceOf(TextStruct::class, $textStruct);
static::assertSame('', $textStruct->getContent());
}
}

0 comments on commit 6e6c554

Please sign in to comment.