コード例 #1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testFinishViewEvaluatesAllExpressions()
 {
     $context = new LayoutContext();
     $context->set('css_class', 'test_class');
     $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('evaluate')->with(['context' => $context, 'data' => $data])->will($this->returnValue(true));
     $classExpr = new Func\GetValue();
     $classExpr->initialize([new PropertyPath('context.css_class')]);
     $classExpr->setContextAccessor(new ContextAccessor());
     $classAttr = new OptionValueBag();
     $classAttr->add(['@value' => ['$context.css_class']]);
     $expectedClassAttr = new OptionValueBag();
     $expectedClassAttr->add('test_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']['data-scalar'] = 'foo';
     $view->vars['attr']['data-expr'] = ['@true' => null];
     $view->vars['attr']['class'] = $classAttr;
     $view->vars['label_attr']['enabled'] = ['@true' => null];
     $view->vars['array_with_expr'] = ['item1' => 'val1', 'item2' => ['@true' => null]];
     $this->expressionAssembler->expects($this->exactly(6))->method('assemble')->will($this->returnValueMap([[['@true' => null], new Condition\True()], [['@value' => ['$context.css_class']], $classExpr]]));
     $context['expressions_evaluate'] = true;
     $this->extension->finishView($view, $block, []);
     $this->assertSame(true, $view->vars['expr_object'], 'Failed asserting that an expression is evaluated');
     $this->assertSame(true, $view->vars['expr_array'], 'Failed asserting that an expression is assembled and evaluated');
     $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, $view->vars['attr']['enabled'], 'Failed asserting that an expression in "attr" is assembled and evaluated');
     $this->assertSame('foo', $view->vars['attr']['data-scalar'], 'Failed asserting that "attr.data-scalar" exists');
     $this->assertSame(true, $view->vars['attr']['data-expr'], 'Failed asserting that "attr.data-expr" is assembled and evaluated');
     $this->assertEquals($expectedClassAttr, $view->vars['attr']['class'], 'Failed asserting that "attr.class" is assembled and evaluated');
     $this->assertSame(true, $view->vars['label_attr']['enabled'], 'Failed asserting that an expression in "label_attr" is assembled and evaluated');
     $this->assertSame(['item1' => 'val1', 'item2' => true], $view->vars['array_with_expr'], 'Failed asserting that an expression is assembled and evaluated in nested array');
 }
コード例 #2
0
ファイル: GetValueTest.php プロジェクト: ramunasd/platform
 protected function setUp()
 {
     $this->function = new Func\GetValue();
     $this->function->setContextAccessor(new ContextAccessor());
 }