diff --git a/dev/tests/functional/tests/app/Magento/Cms/Test/Block/Adminhtml/Page/Edit/Tab/Content.php b/dev/tests/functional/tests/app/Magento/Cms/Test/Block/Adminhtml/Page/Edit/Tab/Content.php index a07445f3eee83cf3d6d3b542c04921c4880f8f8e..24b1999344084474cf3954fb4aeed7b712283f44 100644 --- a/dev/tests/functional/tests/app/Magento/Cms/Test/Block/Adminhtml/Page/Edit/Tab/Content.php +++ b/dev/tests/functional/tests/app/Magento/Cms/Test/Block/Adminhtml/Page/Edit/Tab/Content.php @@ -62,11 +62,13 @@ class Content extends Tab /** * Clicking in content tab 'Insert Variable' button. * + * @param SimpleElement $element [optional] * @return void */ - public function clickInsertVariable() + public function clickInsertVariable(SimpleElement $element = null) { - $addVariableButton = $this->_rootElement->find($this->addVariableButton); + $context = $element === null ? $this->_rootElement : $element; + $addVariableButton = $context->find($this->addVariableButton); if ($addVariableButton->isVisible()) { $addVariableButton->click(); } @@ -75,11 +77,13 @@ class Content extends Tab /** * Clicking in content tab 'Insert Widget' button. * + * @param SimpleElement $element [optional] * @return void */ - public function clickInsertWidget() + public function clickInsertWidget(SimpleElement $element = null) { - $addWidgetButton = $this->_rootElement->find($this->addWidgetButton); + $context = $element === null ? $this->_rootElement : $element; + $addWidgetButton = $context->find($this->addWidgetButton); if ($addWidgetButton->isVisible()) { $addWidgetButton->click(); } diff --git a/dev/tests/functional/tests/app/Magento/Cms/Test/Fixture/CmsPage/Content.php b/dev/tests/functional/tests/app/Magento/Cms/Test/Fixture/CmsPage/Content.php index 0ce3f511d5732c8cae18a3f24fc59f156a751587..31a9d22a1530389c41b257a990ae67e8e57c228e 100644 --- a/dev/tests/functional/tests/app/Magento/Cms/Test/Fixture/CmsPage/Content.php +++ b/dev/tests/functional/tests/app/Magento/Cms/Test/Fixture/CmsPage/Content.php @@ -25,14 +25,19 @@ class Content extends DataSource */ protected $fixtureFactory; + /** + * Repository factory. + * + * @var RepositoryFactory + */ + protected $repositoryFactory; + /** * @constructor * @param RepositoryFactory $repositoryFactory * @param FixtureFactory $fixtureFactory * @param array $params * @param array $data - * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function __construct( RepositoryFactory $repositoryFactory, @@ -41,37 +46,62 @@ class Content extends DataSource array $data = [] ) { $this->fixtureFactory = $fixtureFactory; + $this->repositoryFactory = $repositoryFactory; $this->params = $params; $this->data = $data; - if (isset($data['widget']['dataset']) && isset($this->params['repository'])) { - $this->data['widget']['dataset'] = $repositoryFactory->get($this->params['repository'])->get( - $data['widget']['dataset'] + $this->prepareSourceData(); + } + + /** + * Prepare source data. + * + * @return void + */ + protected function prepareSourceData() + { + if (isset($this->data['widget']['dataset']) && isset($this->params['repository'])) { + $this->data['widget']['dataset'] = $this->repositoryFactory->get($this->params['repository'])->get( + $this->data['widget']['dataset'] ); - foreach ($this->data['widget']['dataset'] as $key => $widget) { - if (isset($widget['chosen_option']['category_path']) - && !isset($widget['chosen_option']['filter_sku']) - ) { - $category = $this->createCategory($widget); - $categoryName = $category->getData('name'); - $this->data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName; - } - if (isset($widget['chosen_option']['category_path']) && isset($widget['chosen_option']['filter_sku'])) { - $product = $this->createProduct($widget); - $categoryName = $product->getCategoryIds()[0]['name']; - $productSku = $product->getData('sku'); - $this->data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName; - $this->data['widget']['dataset'][$key]['chosen_option']['filter_sku'] = $productSku; - } - if ($widget['widget_type'] == 'Catalog New Products List') { - $this->createProduct(); - } - if ($widget['widget_type'] == 'CMS Static Block') { - $block = $this->createBlock($widget); - $blockIdentifier = $block->getIdentifier(); - $this->data['widget']['dataset'][$key]['chosen_option']['filter_identifier'] = $blockIdentifier; - } + $this->data = array_merge($this->data, $this->prepareWidgetData($this->data['widget'])); + } + } + + /** + * Prepare widget data for the source. + * + * @param array $widgets + * @return array + */ + protected function prepareWidgetData(array $widgets) + { + $data = []; + foreach ($widgets['dataset'] as $key => $widget) { + if (isset($widget['chosen_option']['category_path']) + && !isset($widget['chosen_option']['filter_sku']) + ) { + $category = $this->createCategory($widget); + $categoryName = $category->getData('name'); + $data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName; + } + if (isset($widget['chosen_option']['category_path']) && isset($widget['chosen_option']['filter_sku'])) { + $product = $this->createProduct($widget); + $categoryName = $product->getCategoryIds()[0]['name']; + $productSku = $product->getData('sku'); + $data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName; + $data['widget']['dataset'][$key]['chosen_option']['filter_sku'] = $productSku; + } + if ($widget['widget_type'] == 'Catalog New Products List') { + $this->createProduct(); + } + if ($widget['widget_type'] == 'CMS Static Block') { + $block = $this->createBlock($widget); + $blockIdentifier = $block->getIdentifier(); + $data['widget']['dataset'][$key]['chosen_option']['filter_identifier'] = $blockIdentifier; } } + + return $data; } /**