public function testFinishViewEncodesClassAttrExpression()
 {
     $context = new LayoutContext();
     $context->set('css_class', 'test_class');
     $block = $this->getMock('Oro\\Component\\Layout\\BlockInterface');
     $block->expects($this->once())->method('getContext')->will($this->returnValue($context));
     $view = new BlockView();
     $classAttr = new OptionValueBag();
     $classAttr->add('test_class');
     $view->vars['attr']['class'] = $classAttr;
     $context['expressions_evaluate'] = false;
     $context['expressions_encoding'] = 'json';
     $this->extension->finishView($view, $block, []);
     $this->assertEquals('{"@actions":[{"name":"add","args":["test_class"]}]}', $view->vars['attr']['class']);
 }
 /**
  * @param mixed $initialValue
  *
  * @return OptionValueBag
  */
 protected function createOptionValueBag($initialValue)
 {
     $result = new OptionValueBag();
     if (null !== $initialValue) {
         $result->add($initialValue);
     }
     return $result;
 }
 public function testFinishViewEncodesAllExpressions()
 {
     $context = new LayoutContext();
     $data = $this->getMock('Oro\\Component\\Layout\\DataAccessorInterface');
     $block = $this->getMock('Oro\\Component\\Layout\\BlockInterface');
     $block->expects($this->once())->method('getContext')->will($this->returnValue($context));
     $block->expects($this->once())->method('getData')->will($this->returnValue($data));
     $view = new BlockView();
     $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"]}}');
     $view->vars['expr_object'] = $expr;
     $view->vars['expr_array'] = ['@true' => null];
     $view->vars['not_expr_array'] = ['\\@true' => null];
     $view->vars['scalar'] = 123;
     $view->vars['attr']['enabled'] = ['@true' => null];
     $view->vars['attr']['class'] = $classAttr;
     $view->vars['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]]));
     $context['expressions_evaluate'] = false;
     $context['expressions_encoding'] = 'json';
     $this->extension->finishView($view, $block, []);
     $this->assertSame('{"@true":null}', $view->vars['expr_object'], 'Failed asserting that an expression is encoded');
     $this->assertSame('{"@true":null}', $view->vars['expr_array'], 'Failed asserting that an expression is assembled and encoded');
     $this->assertSame(['@true' => null], $view->vars['not_expr_array'], 'Failed asserting that a backslash at the begin of the array key is removed');
     $this->assertSame(123, $view->vars['scalar'], 'Failed asserting that a scalar value is not changed');
     $this->assertSame('{"@true":null}', $view->vars['attr']['enabled'], 'Failed asserting that an expression in "attr" is assembled and encoded');
     $this->assertEquals($expectedClassAttr, $view->vars['attr']['class'], 'Failed asserting that "attr.class" is assembled and encoded');
     $this->assertSame('{"@true":null}', $view->vars['label_attr']['enabled'], 'Failed asserting that an expression in "label_attr" is assembled and encoded');
 }