/** * {@inheritdoc} */ public function finishView(BlockView $view, BlockInterface $block, array $options) { $context = $block->getContext(); $data = $block->getData(); if (true !== $context->getOr('expressions_evaluate_deferred')) { return; } $evaluate = $context->getOr('expressions_evaluate'); $encoding = $context->getOr('expressions_encoding'); $this->processor->processExpressions($view->vars, $context, $data, $evaluate, $encoding); }
public function testProcessExpressionsEncodesAllExpressions() { $context = new LayoutContext(); $context->set('expressions_evaluate_deferred', true); $data = $this->getMock('Oro\\Component\\Layout\\DataAccessorInterface'); $expr = $this->getMock('Oro\\Component\\ConfigExpression\\ExpressionInterface'); $expr->expects($this->once())->method('toArray')->will($this->returnValue(['@true' => null])); $classExpr = new Func\GetValue(); $classExpr->initialize([new PropertyPath('context.css_class')]); $classAttr = new OptionValueBag(); $classAttr->add(['@value' => ['$context.css_class']]); $expectedClassAttr = new OptionValueBag(); $expectedClassAttr->add('{"@value":{"parameters":["$context.css_class"]}}'); $values['expr_object'] = $expr; $values['expr_array'] = ['@true' => null]; $values['not_expr_array'] = ['\\@true' => null]; $values['scalar'] = 123; $values['attr']['enabled'] = ['@true' => null]; $values['attr']['class'] = $classAttr; $values['label_attr']['enabled'] = ['@true' => null]; $this->expressionAssembler->expects($this->exactly(4))->method('assemble')->will($this->returnValueMap([[['@true' => null], new Condition\True()], [['@value' => ['$context.css_class']], $classExpr]])); $this->processor->processExpressions($values, $context, $data, false, 'json'); $this->assertSame('{"@true":null}', $values['expr_object'], 'Failed asserting that an expression is encoded'); $this->assertSame('{"@true":null}', $values['expr_array'], 'Failed asserting that an expression is assembled and encoded'); $this->assertSame(['@true' => null], $values['not_expr_array'], 'Failed asserting that a backslash at the begin of the array key is removed'); $this->assertSame(123, $values['scalar'], 'Failed asserting that a scalar value is not changed'); $this->assertSame('{"@true":null}', $values['attr']['enabled'], 'Failed asserting that an expression in "attr" is assembled and encoded'); $this->assertEquals($expectedClassAttr, $values['attr']['class'], 'Failed asserting that "attr.class" is assembled and encoded'); $this->assertSame('{"@true":null}', $values['label_attr']['enabled'], 'Failed asserting that an expression in "label_attr" is assembled and encoded'); }