예제 #1
0
 public function testEvaluate()
 {
     $input = ['interpreter' => 'one', 'value' => 'test'];
     $expected = ['value' => 'test (updated)'];
     $this->_interpreterOne->expects($this->once())->method('evaluate')->with(['value' => 'test'])->will($this->returnValue($expected));
     $this->assertSame($expected, $this->_model->evaluate($input));
 }
예제 #2
0
 /**
  * @param array $input
  * @param array $expected
  *
  * @dataProvider evaluateDataProvider
  */
 public function testEvaluate(array $input, array $expected)
 {
     $this->_itemInterpreter->expects($this->any())->method('evaluate')->will($this->returnCallback(function ($input) {
         return '-' . $input['value'] . '-';
     }));
     $actual = $this->_model->evaluate($input);
     $this->assertSame($expected, $actual);
 }
예제 #3
0
 public function testEvaluateNoUpdaters()
 {
     $input = ['value' => 'some text'];
     $expected = ['value' => 'new text'];
     $this->_interpreter->expects($this->once())->method('evaluate')->with($input)->will($this->returnValue($expected));
     $this->_objectManager->expects($this->never())->method('get');
     $actual = $this->_model->evaluate($input);
     $this->assertSame($expected, $actual);
 }
예제 #4
0
 public function testEvaluate()
 {
     $input = array('param' => array('param1' => array('value' => 'value 1'), 'param2' => array('value' => 'value 2')));
     $this->_interpreter->expects($this->at(0))->method('evaluate')->with(array('value' => 'value 1'))->will($this->returnValue('value 1 (evaluated)'));
     $this->_interpreter->expects($this->at(1))->method('evaluate')->with(array('value' => 'value 2'))->will($this->returnValue('value 2 (evaluated)'));
     $expected = array('param1' => 'value 1 (evaluated)', 'param2' => 'value 2 (evaluated)');
     $actual = $this->_model->evaluate($input);
     $this->assertSame($expected, $actual);
 }
예제 #5
0
 /**
  * {@inheritdoc}
  * @return array
  * @throws \InvalidArgumentException
  */
 public function evaluate(array $data)
 {
     if (!isset($data['item']) || !is_array($data['item'])) {
         throw new \InvalidArgumentException('Array items are expected.');
     }
     $result = array();
     $items = $data['item'];
     foreach ($items as $itemKey => $itemData) {
         $result[$itemKey] = $this->itemInterpreter->evaluate($itemData);
     }
     return $result;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  * @throws \InvalidArgumentException
  */
 public function evaluate(array $data)
 {
     $updaters = !empty($data['updater']) ? $data['updater'] : array();
     unset($data['updater']);
     if (!is_array($updaters)) {
         throw new \InvalidArgumentException('Layout argument updaters are expected to be an array of classes.');
     }
     $result = $this->subject->evaluate($data);
     foreach ($updaters as $updaterClass) {
         $result = $this->applyUpdater($result, $updaterClass);
     }
     return $result;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  * @return array
  * @throws \InvalidArgumentException
  */
 public function evaluate(array $data)
 {
     $params = isset($data['param']) ? $data['param'] : [];
     if (!is_array($params)) {
         throw new \InvalidArgumentException('Layout argument parameters are expected to be an array.');
     }
     $result = [];
     foreach ($params as $paramKey => $paramData) {
         if (!is_array($paramData)) {
             throw new \InvalidArgumentException('Parameter data of layout argument is expected to be an array.');
         }
         $result[$paramKey] = $this->paramInterpreter->evaluate($paramData);
     }
     return $result;
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function evaluate(array $data)
 {
     if (!isset($data['argument'])) {
         throw new \InvalidArgumentException('Node "argument" required for this type.');
     }
     foreach ($data['argument'] as $name => $argument) {
         $arguments[$name] = $this->argumentInterpreter->evaluate($argument);
     }
     if (!isset($arguments['class'])) {
         throw new \InvalidArgumentException('Node "argument" with name "class" is required for this type.');
     }
     $className = $arguments['class'];
     unset($arguments['class']);
     return $this->objectManager->create($className, $arguments);
 }
예제 #9
0
 /**
  * Compute and return argument values
  *
  * @param array $arguments
  * @return array
  */
 protected function evaluateArguments(array $arguments)
 {
     $result = [];
     foreach ($arguments as $argumentName => $argumentData) {
         $result[$argumentName] = $this->argumentInterpreter->evaluate($argumentData);
     }
     return $result;
 }
예제 #10
0
 public function testProcess()
 {
     $this->prepareScheduledStructure();
     $this->readerContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock();
     $this->readerContextMock->expects($this->any())->method('getScheduledStructure')->willReturn($this->scheduledStructureMock);
     $generatorContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\Context')->disableOriginalConstructor()->getMock();
     $structureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Data\\Structure')->disableOriginalConstructor()->getMock();
     $structureMock->expects($this->once())->method('addToParentGroup')->with(UiComponent::TYPE, 'new_group')->willReturnSelf();
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->getMockForAbstractClass();
     $generatorContextMock->expects($this->any())->method('getStructure')->willReturn($structureMock);
     $generatorContextMock->expects($this->any())->method('getLayout')->willReturn($layoutMock);
     $this->uiComponentFactoryMock->expects($this->any())->method('setLayout')->with($layoutMock)->willReturnSelf();
     $blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMock();
     $this->uiComponentFactoryMock->expects($this->any())->method('createUiComponent')->with('component_name', UiComponent::TYPE, ['attribute_1' => 'value_1', 'attribute_2' => 'value_2'])->willReturn($blockMock);
     $this->argumentInterpreterMock->expects($this->any())->method('evaluate')->will($this->returnValueMap([[['key_1' => 'value_1'], 'value_1'], [['key_2' => 'value_2'], 'value_2']]));
     $layoutMock->expects($this->any())->method('setBlock')->with(UiComponent::TYPE, $blockMock)->willReturnSelf();
     $this->uiComponent->process($this->readerContextMock, $generatorContextMock);
 }
예제 #11
0
 /**
  * @param string $area
  * @param string $layoutFile
  * @dataProvider layoutArgumentsDataProvider
  */
 public function testLayoutArguments($area, $layoutFile)
 {
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea($area);
     $dom = new \DOMDocument();
     $dom->load($layoutFile);
     $xpath = new \DOMXPath($dom);
     $argumentNodes = $xpath->query('/layout//arguments/argument | /layout//action/argument');
     /** @var \DOMNode $argumentNode */
     foreach ($argumentNodes as $argumentNode) {
         try {
             $argumentData = $this->_argParser->parse($argumentNode);
             if ($this->isSkippedArgument($argumentData)) {
                 continue;
             }
             $this->_argInterpreter->evaluate($argumentData);
         } catch (\Exception $e) {
             $this->fail($e->getMessage());
         }
     }
 }
예제 #12
0
 /**
  * @dataProvider getComponentDataProvider()
  */
 public function testCreateRawComponentData($componentName, $configData, $componentData, $needEvaluate)
 {
     $this->componentConfigProvider->expects($this->any())->method('getComponentData')->willReturn($configData);
     if ($needEvaluate === true) {
         $this->argumentInterpreter->expects($this->once())->method('evaluate')->willReturnCallback(function ($argument) {
             return ['argument' => $argument['value']];
         });
     } else {
         $this->argumentInterpreter->expects($this->never())->method('evaluate');
     }
     $this->assertEquals($componentData, $this->manager->createRawComponentData($componentName, $needEvaluate));
 }
예제 #13
0
 /**
  * Compute and return argument values
  *
  * @param array $arguments
  * @return array
  */
 protected function evaluateArguments(array $arguments)
 {
     $result = [];
     foreach ($arguments as $argumentName => $argumentData) {
         if (!isset($argumentData[Dom::TYPE_ATTRIBUTE])) {
             $result[$argumentName] = $argumentData;
             continue;
         }
         $result[$argumentName] = $this->argumentInterpreter->evaluate($argumentData);
     }
     return $result;
 }
예제 #14
0
 /**
  * To create the raw  data components
  *
  * @param string $component
  * @param bool $evaluated
  * @return array
  */
 public function createRawComponentData($component, $evaluated = true)
 {
     $componentData = $this->componentConfigProvider->getComponentData($component);
     $componentData[Converter::DATA_ATTRIBUTES_KEY] = isset($componentData[Converter::DATA_ATTRIBUTES_KEY]) ? $componentData[Converter::DATA_ATTRIBUTES_KEY] : [];
     $componentData[Converter::DATA_ARGUMENTS_KEY] = isset($componentData[Converter::DATA_ARGUMENTS_KEY]) ? $componentData[Converter::DATA_ARGUMENTS_KEY] : [];
     if ($evaluated) {
         foreach ($componentData[Converter::DATA_ARGUMENTS_KEY] as $argumentName => $argument) {
             $componentData[Converter::DATA_ARGUMENTS_KEY][$argumentName] = $this->argumentInterpreter->evaluate($argument);
         }
     }
     return [ManagerInterface::COMPONENT_ATTRIBUTES_KEY => $componentData[Converter::DATA_ATTRIBUTES_KEY], ManagerInterface::COMPONENT_ARGUMENTS_KEY => $componentData[Converter::DATA_ARGUMENTS_KEY]];
 }
예제 #15
0
 /**
  * Compute argument values
  *
  * @param Layout\Element $blockElement
  * @param array $data
  */
 protected function evaluateArguments(Layout\Element $blockElement, array &$data)
 {
     $arguments = $this->getArguments($blockElement);
     foreach ($arguments as $argumentName => $argumentData) {
         if (isset($argumentData['updater'])) {
             continue;
         }
         $result = $this->argumentInterpreter->evaluate($argumentData);
         if (is_array($result)) {
             $data['arguments'][$argumentName] = isset($data['arguments'][$argumentName]) ? array_replace_recursive($data['arguments'][$argumentName], $result) : $result;
         } else {
             $data['arguments'][$argumentName] = $result;
         }
     }
 }
예제 #16
0
 /**
  * Resolve arguments
  *
  * @param string $identifier
  * @param array $componentData
  * @return array
  */
 protected function argumentsResolver($identifier, array $componentData)
 {
     $attributes = $componentData[ManagerInterface::COMPONENT_ATTRIBUTES_KEY];
     $className = $attributes['class'];
     unset($attributes['class']);
     $arguments = [];
     foreach ($componentData[ManagerInterface::COMPONENT_ARGUMENTS_KEY] as $name => $argument) {
         $arguments[$name] = $this->argumentInterpreter->evaluate($argument);
     }
     if (!isset($arguments['data'])) {
         $arguments['data'] = [];
     }
     $arguments['data'] = array_merge($arguments['data'], ['name' => $identifier], $attributes);
     return [$className, $arguments];
 }
예제 #17
0
파일: Dom.php 프로젝트: Mohitsahu123/mtf
 /**
  * Convert configuration in DOM format to assoc array that can be used by object manager
  *
  * @param \DOMDocument $config
  * @return array
  * @throws \Exception
  * @todo this method has high cyclomatic complexity in order to avoid performance issues
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function convert($config)
 {
     $output = array();
     /** @var \DOMNode $node */
     foreach ($config->documentElement->childNodes as $node) {
         if ($node->nodeType != XML_ELEMENT_NODE) {
             continue;
         }
         switch ($node->nodeName) {
             case 'preference':
                 $output['preferences'][$node->attributes->getNamedItem('for')->nodeValue] = $node->attributes->getNamedItem('type')->nodeValue;
                 break;
             case 'type':
             case 'virtualType':
                 $typeData = array();
                 $typeNodeAttributes = $node->attributes;
                 $typeNodeShared = $typeNodeAttributes->getNamedItem('shared');
                 if ($typeNodeShared) {
                     $typeData['shared'] = $this->booleanUtils->toBoolean($typeNodeShared->nodeValue);
                 }
                 if ($node->nodeName == 'virtualType') {
                     $attributeType = $typeNodeAttributes->getNamedItem('type');
                     // attribute type is required for virtual type only in merged configuration
                     if ($attributeType) {
                         $typeData['type'] = $attributeType->nodeValue;
                     }
                 }
                 $typeArguments = array();
                 $typePlugins = array();
                 /** @var \DOMNode $typeChildNode */
                 foreach ($node->childNodes as $typeChildNode) {
                     if ($typeChildNode->nodeType != XML_ELEMENT_NODE) {
                         continue;
                     }
                     switch ($typeChildNode->nodeName) {
                         case 'arguments':
                             /** @var \DOMNode $argumentNode */
                             foreach ($typeChildNode->childNodes as $argumentNode) {
                                 if ($argumentNode->nodeType != XML_ELEMENT_NODE) {
                                     continue;
                                 }
                                 $argumentName = $argumentNode->attributes->getNamedItem('name')->nodeValue;
                                 $argumentData = $this->argumentParser->parse($argumentNode);
                                 $typeArguments[$argumentName] = $this->argumentInterpreter->evaluate($argumentData);
                             }
                             break;
                         case 'plugin':
                             $pluginAttributes = $typeChildNode->attributes;
                             $pluginDisabledNode = $pluginAttributes->getNamedItem('disabled');
                             $pluginSortOrderNode = $pluginAttributes->getNamedItem('sortOrder');
                             $pluginTypeNode = $pluginAttributes->getNamedItem('type');
                             $pluginData = array('sortOrder' => $pluginSortOrderNode ? (int) $pluginSortOrderNode->nodeValue : 0);
                             if ($pluginDisabledNode) {
                                 $pluginData['disabled'] = $this->booleanUtils->toBoolean($pluginDisabledNode->nodeValue);
                             }
                             if ($pluginTypeNode) {
                                 $pluginData['instance'] = $pluginTypeNode->nodeValue;
                             }
                             $typePlugins[$pluginAttributes->getNamedItem('name')->nodeValue] = $pluginData;
                             break;
                         default:
                             throw new \Exception("Invalid application config. Unknown node: {$typeChildNode->nodeName}.");
                     }
                 }
                 $typeData['arguments'] = $typeArguments;
                 if (!empty($typePlugins)) {
                     $typeData['plugins'] = $typePlugins;
                 }
                 $output[$typeNodeAttributes->getNamedItem('name')->nodeValue] = $typeData;
                 break;
             default:
                 throw new \Exception("Invalid application config. Unknown node: {$node->nodeName}.");
         }
     }
     return $output;
 }