Skip to content

Commit f262b21

Browse files
author
Dmytro Aponasenko
committed
MTA-2494: Update widget adding to the CMS page content
1 parent cfb2937 commit f262b21

File tree

2 files changed

+66
-32
lines changed
  • dev/tests/functional/tests/app/Magento/Cms/Test

2 files changed

+66
-32
lines changed

dev/tests/functional/tests/app/Magento/Cms/Test/Block/Adminhtml/Page/Edit/Tab/Content.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ class Content extends Tab
6262
/**
6363
* Clicking in content tab 'Insert Variable' button.
6464
*
65+
* @param SimpleElement $element [optional]
6566
* @return void
6667
*/
67-
public function clickInsertVariable()
68+
public function clickInsertVariable(SimpleElement $element = null)
6869
{
69-
$addVariableButton = $this->_rootElement->find($this->addVariableButton);
70+
$context = $element === null ? $this->_rootElement : $element;
71+
$addVariableButton = $context->find($this->addVariableButton);
7072
if ($addVariableButton->isVisible()) {
7173
$addVariableButton->click();
7274
}
@@ -75,11 +77,13 @@ public function clickInsertVariable()
7577
/**
7678
* Clicking in content tab 'Insert Frontend App' button.
7779
*
80+
* @param SimpleElement $element [optional]
7881
* @return void
7982
*/
80-
public function clickInsertWidget()
83+
public function clickInsertWidget(SimpleElement $element = null)
8184
{
82-
$addWidgetButton = $this->_rootElement->find($this->addWidgetButton);
85+
$context = $element === null ? $this->_rootElement : $element;
86+
$addWidgetButton = $context->find($this->addWidgetButton);
8387
if ($addWidgetButton->isVisible()) {
8488
$addWidgetButton->click();
8589
}

dev/tests/functional/tests/app/Magento/Cms/Test/Fixture/CmsPage/Content.php

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ class Content extends DataSource
2525
*/
2626
protected $fixtureFactory;
2727

28+
/**
29+
* Repository factory.
30+
*
31+
* @var RepositoryFactory
32+
*/
33+
protected $repositoryFactory;
34+
2835
/**
2936
* @constructor
3037
* @param RepositoryFactory $repositoryFactory
3138
* @param FixtureFactory $fixtureFactory
3239
* @param array $params
3340
* @param array $data
34-
*
35-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
3641
*/
3742
public function __construct(
3843
RepositoryFactory $repositoryFactory,
@@ -41,37 +46,62 @@ public function __construct(
4146
array $data = []
4247
) {
4348
$this->fixtureFactory = $fixtureFactory;
49+
$this->repositoryFactory = $repositoryFactory;
4450
$this->params = $params;
4551
$this->data = $data;
46-
if (isset($data['widget']['dataset']) && isset($this->params['repository'])) {
47-
$this->data['widget']['dataset'] = $repositoryFactory->get($this->params['repository'])->get(
48-
$data['widget']['dataset']
52+
$this->prepareSourceData();
53+
}
54+
55+
/**
56+
* Prepare source data.
57+
*
58+
* @return void
59+
*/
60+
protected function prepareSourceData()
61+
{
62+
if (isset($this->data['widget']['dataset']) && isset($this->params['repository'])) {
63+
$this->data['widget']['dataset'] = $this->repositoryFactory->get($this->params['repository'])->get(
64+
$this->data['widget']['dataset']
4965
);
50-
foreach ($this->data['widget']['dataset'] as $key => $widget) {
51-
if (isset($widget['chosen_option']['category_path'])
52-
&& !isset($widget['chosen_option']['filter_sku'])
53-
) {
54-
$category = $this->createCategory($widget);
55-
$categoryName = $category->getData('name');
56-
$this->data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName;
57-
}
58-
if (isset($widget['chosen_option']['category_path']) && isset($widget['chosen_option']['filter_sku'])) {
59-
$product = $this->createProduct($widget);
60-
$categoryName = $product->getCategoryIds()[0]['name'];
61-
$productSku = $product->getData('sku');
62-
$this->data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName;
63-
$this->data['widget']['dataset'][$key]['chosen_option']['filter_sku'] = $productSku;
64-
}
65-
if ($widget['widget_type'] == 'Catalog New Products List') {
66-
$this->createProduct();
67-
}
68-
if ($widget['widget_type'] == 'CMS Static Block') {
69-
$block = $this->createBlock($widget);
70-
$blockIdentifier = $block->getIdentifier();
71-
$this->data['widget']['dataset'][$key]['chosen_option']['filter_identifier'] = $blockIdentifier;
72-
}
66+
$this->data = array_merge($this->data, $this->prepareWidgetData($this->data['widget']));
67+
}
68+
}
69+
70+
/**
71+
* Prepare widget data for the source.
72+
*
73+
* @param array $widgets
74+
* @return array
75+
*/
76+
protected function prepareWidgetData(array $widgets)
77+
{
78+
$data = [];
79+
foreach ($widgets['dataset'] as $key => $widget) {
80+
if (isset($widget['chosen_option']['category_path'])
81+
&& !isset($widget['chosen_option']['filter_sku'])
82+
) {
83+
$category = $this->createCategory($widget);
84+
$categoryName = $category->getData('name');
85+
$data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName;
86+
}
87+
if (isset($widget['chosen_option']['category_path']) && isset($widget['chosen_option']['filter_sku'])) {
88+
$product = $this->createProduct($widget);
89+
$categoryName = $product->getCategoryIds()[0]['name'];
90+
$productSku = $product->getData('sku');
91+
$data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName;
92+
$data['widget']['dataset'][$key]['chosen_option']['filter_sku'] = $productSku;
93+
}
94+
if ($widget['widget_type'] == 'Catalog New Products List') {
95+
$this->createProduct();
96+
}
97+
if ($widget['widget_type'] == 'CMS Static Block') {
98+
$block = $this->createBlock($widget);
99+
$blockIdentifier = $block->getIdentifier();
100+
$data['widget']['dataset'][$key]['chosen_option']['filter_identifier'] = $blockIdentifier;
73101
}
74102
}
103+
104+
return $data;
75105
}
76106

77107
/**

0 commit comments

Comments
 (0)