Skip to content

Commit adf3be6

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-61020' into 2.1-develop-pr46
2 parents 8725966 + 2fb8843 commit adf3be6

File tree

13 files changed

+345
-5
lines changed

13 files changed

+345
-5
lines changed

app/code/Magento/Widget/Model/ResourceModel/Widget/Instance/Options/ThemeId.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
*/
1111
namespace Magento\Widget\Model\ResourceModel\Widget\Instance\Options;
1212

13+
/**
14+
* @deprecated created new class that correctly loads theme options and whose name follows naming convention
15+
* @see \Magento\Widget\Model\ResourceModel\Widget\Instance\Options\Themes
16+
*/
1317
class ThemeId implements \Magento\Framework\Option\ArrayInterface
1418
{
1519
/**
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Widget\Model\ResourceModel\Widget\Instance\Options;
7+
8+
use Magento\Framework\Data\OptionSourceInterface;
9+
use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory as ThemeCollectionFactory;
10+
11+
/**
12+
* Option source of the widget theme property.
13+
*
14+
* Can be used as a data provider for UI components that shows possible themes as a list.
15+
*/
16+
class Themes implements OptionSourceInterface
17+
{
18+
/**
19+
* @var ThemeCollectionFactory
20+
*/
21+
private $themeCollectionFactory;
22+
23+
/**
24+
* @param ThemeCollectionFactory $themeCollectionFactory
25+
*/
26+
public function __construct(ThemeCollectionFactory $themeCollectionFactory)
27+
{
28+
$this->themeCollectionFactory = $themeCollectionFactory;
29+
}
30+
31+
/**
32+
* Return array of options as value-label pairs
33+
*
34+
* @return array Format: array('<theme ID>' => '<theme label>', ...)
35+
*/
36+
public function toOptionArray()
37+
{
38+
// Load only visible themes that are used in frontend area
39+
return $this->themeCollectionFactory->create()->loadRegisteredThemes()->toOptionHash();
40+
}
41+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Widget\Test\Unit\Model\ResourceModel\Widget\Instance\Options;
7+
8+
use Magento\Widget\Model\ResourceModel\Widget\Instance\Options\Themes;
9+
use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection;
10+
use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory as ThemeCollectionFactory;
11+
12+
/**
13+
* Test class for \Magento\Widget\Model\ResourceModel\Widget\Instance\Options\Themes
14+
*/
15+
class ThemesTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var Themes
19+
*/
20+
private $model;
21+
22+
/**
23+
* @var \PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $themeCollectionFactoryMock;
26+
27+
/**
28+
* @var \PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $themeCollectionMock;
31+
32+
protected function setUp()
33+
{
34+
$this->themeCollectionMock = $this->getMock(ThemeCollection::class, [], [], '', false);
35+
$this->themeCollectionFactoryMock = $this->getMock(ThemeCollectionFactory::class, ['create'], [], '', false);
36+
$this->model = new Themes(
37+
$this->themeCollectionFactoryMock
38+
);
39+
}
40+
41+
public function testToOptionArray()
42+
{
43+
$expectedResult = [
44+
1 => 'Theme Label',
45+
];
46+
$this->themeCollectionFactoryMock->expects($this->once())
47+
->method('create')
48+
->willReturn($this->themeCollectionMock);
49+
50+
$this->themeCollectionMock->expects($this->once())->method('loadRegisteredThemes')->willReturnSelf();
51+
$this->themeCollectionMock->expects($this->once())->method('toOptionHash')->willReturn($expectedResult);
52+
53+
$this->assertEquals($expectedResult, $this->model->toOptionArray());
54+
}
55+
}

app/code/Magento/Widget/view/adminhtml/layout/adminhtml_widget_instance_block.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<argument name="header" xsi:type="string" translate="true">Design Theme</argument>
5353
<argument name="index" xsi:type="string">theme_id</argument>
5454
<argument name="type" xsi:type="string">options</argument>
55-
<argument name="options" xsi:type="options" model="Magento\Widget\Model\ResourceModel\Widget\Instance\Options\ThemeId"/>
55+
<argument name="options" xsi:type="options" model="Magento\Widget\Model\ResourceModel\Widget\Instance\Options\Themes"/>
5656
<argument name="with_empty" xsi:type="string">1</argument>
5757
</arguments>
5858
</block>

dev/tests/functional/tests/app/Magento/Widget/Test/Block/Adminhtml/Widget/WidgetGrid.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77
namespace Magento\Widget\Test\Block\Adminhtml\Widget;
88

99
use Magento\Backend\Test\Block\Widget\Grid as AbstractGrid;
10+
use Magento\Mtf\Client\Locator;
1011

1112
/**
1213
* Widget grid on the Widget Instance Index page.
1314
*/
1415
class WidgetGrid extends AbstractGrid
1516
{
17+
/**
18+
* Selector for not empty options at select element.
19+
*
20+
* @var string
21+
*/
22+
private $notEmptyOptionsSelector = 'option:not([value=""])';
23+
1624
/**
1725
* Locator value for link in action column.
1826
*
@@ -36,5 +44,28 @@ class WidgetGrid extends AbstractGrid
3644
'title' => [
3745
'selector' => 'input[name="title"]',
3846
],
47+
'theme_id' => [
48+
'selector' => 'select[name="theme_id"]',
49+
'input' => 'select',
50+
],
3951
];
52+
53+
/**
54+
* Returns values of theme_id filter.
55+
*
56+
* @return array
57+
*/
58+
public function getThemeIdValues()
59+
{
60+
$values = [];
61+
$themeFilter = $this->filters['theme_id'];
62+
$strategy = empty($themeFilter['strategy']) ? Locator::SELECTOR_CSS : $themeFilter['strategy'];
63+
$element = $this->_rootElement->find($themeFilter['selector'], $strategy, $themeFilter['input']);
64+
$options = $element->getElements($this->notEmptyOptionsSelector);
65+
foreach ($options as $option) {
66+
$values[] = $option->getText();
67+
}
68+
69+
return $values;
70+
}
4071
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Widget\Test\Constraint;
8+
9+
use Magento\Mtf\Constraint\AbstractConstraint;
10+
use Magento\Widget\Test\Fixture\Widget;
11+
use Magento\Widget\Test\Page\Adminhtml\WidgetInstanceIndex;
12+
13+
/**
14+
* Assert theme filter contains all possible values from created widgets.
15+
*/
16+
class AssertThemeFilterValuesOnWidgetGrid extends AbstractConstraint
17+
{
18+
/**
19+
* Assert theme filter contains all possible values from created widgets.
20+
*
21+
* @param Widget[] $widgets
22+
* @param WidgetInstanceIndex $widgetInstanceIndex
23+
* @return void
24+
*/
25+
public function processAssert(array $widgets, WidgetInstanceIndex $widgetInstanceIndex)
26+
{
27+
$expectedValues = [];
28+
foreach ($widgets as $widget) {
29+
$expectedValues[] = $widget->getThemeId();
30+
}
31+
$widgetInstanceIndex->open();
32+
$actualValues = $widgetInstanceIndex->getWidgetGrid()->getThemeIdValues();
33+
\PHPUnit_Framework_Assert::assertEmpty(
34+
array_diff($expectedValues, $actualValues),
35+
"Widget grid theme filter doesn't contain all possible values from created widgets."
36+
);
37+
}
38+
39+
/**
40+
* Returns a string representation of the object.
41+
*
42+
* @return string
43+
*/
44+
public function toString()
45+
{
46+
return 'Widget grid theme filter contains all possible values from created widgets.';
47+
}
48+
}

dev/tests/functional/tests/app/Magento/Widget/Test/Constraint/AssertWidgetInGrid.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Mtf\Constraint\AbstractConstraint;
1212

1313
/**
14-
* Class AssertWidgetInGrid
14+
* Assert widget is present in widget grid.
1515
*/
1616
class AssertWidgetInGrid extends AbstractConstraint
1717
{
@@ -20,15 +20,18 @@ class AssertWidgetInGrid extends AbstractConstraint
2020
/* end tags */
2121

2222
/**
23-
* Assert widget availability in widget grid
23+
* Assert widget availability in widget grid.
24+
* Verifying such fields as:
25+
* - title
26+
* - theme_id
2427
*
2528
* @param Widget $widget
2629
* @param WidgetInstanceIndex $widgetInstanceIndex
2730
* @return void
2831
*/
2932
public function processAssert(Widget $widget, WidgetInstanceIndex $widgetInstanceIndex)
3033
{
31-
$filter = ['title' => $widget->getTitle()];
34+
$filter = ['title' => $widget->getTitle(), 'theme_id' => $widget->getThemeId()];
3235
$widgetInstanceIndex->open();
3336
\PHPUnit_Framework_Assert::assertTrue(
3437
$widgetInstanceIndex->getWidgetGrid()->isRowVisible($filter),
@@ -37,7 +40,7 @@ public function processAssert(Widget $widget, WidgetInstanceIndex $widgetInstanc
3740
}
3841

3942
/**
40-
* Returns a string representation of the object
43+
* Returns a string representation of the object.
4144
*
4245
* @return string
4346
*/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Widget\Test\Constraint;
8+
9+
use Magento\Mtf\Constraint\AbstractConstraint;
10+
use Magento\Widget\Test\Fixture\Widget;
11+
use Magento\Widget\Test\Page\Adminhtml\WidgetInstanceIndex;
12+
13+
/**
14+
* Assert widgets are present in widget grid.
15+
*/
16+
class AssertWidgetsInGrid extends AbstractConstraint
17+
{
18+
/**
19+
* Assert widgets are present in widget grid.
20+
* Verifying such fields as:
21+
* - title
22+
* - theme_id
23+
*
24+
* @param Widget[] $widgets
25+
* @param WidgetInstanceIndex $widgetInstanceIndex
26+
* @param AssertWidgetInGrid $assertWidgetInGrid
27+
* @return void
28+
*/
29+
public function processAssert(
30+
array $widgets,
31+
WidgetInstanceIndex $widgetInstanceIndex,
32+
AssertWidgetInGrid $assertWidgetInGrid
33+
) {
34+
foreach ($widgets as $widget) {
35+
$assertWidgetInGrid->processAssert($widget, $widgetInstanceIndex);
36+
}
37+
}
38+
39+
/**
40+
* Returns a string representation of the object.
41+
*
42+
* @return string
43+
*/
44+
public function toString()
45+
{
46+
return 'Widgets are present in widget grid.';
47+
}
48+
}

dev/tests/functional/tests/app/Magento/Widget/Test/Handler/Widget/Curl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Curl extends AbstractCurl
2828
'code' => [
2929
'CMS Page Link' => 'cms_page_link',
3030
'Catalog New Products List' => 'new_products',
31+
'Recently Viewed Products' => 'recently_viewed',
3132
],
3233
'block' => [
3334
'Main Content Area' => 'content',

dev/tests/functional/tests/app/Magento/Widget/Test/Repository/Widget.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,20 @@
4040
<item name="dataset" xsi:type="string">catalogNewProductsListNewOnly</item>
4141
</field>
4242
</dataset>
43+
44+
<dataset name="recently_viewed_products_on_blank_theme">
45+
<field name="code" xsi:type="string">Recently Viewed Products</field>
46+
<field name="title" xsi:type="string">Title_%isolation%</field>
47+
<field name="theme_id" xsi:type="string">Magento Blank</field>
48+
<field name="store_ids" xsi:type="array">
49+
<item name="dataset" xsi:type="string">all_store_views</item>
50+
</field>
51+
<field name="widget_instance" xsi:type="array">
52+
<item name="dataset" xsi:type="string">for_viewed_products</item>
53+
</field>
54+
<field name="parameters" xsi:type="array">
55+
<item name="dataset" xsi:type="string">recentlyViewedProducts</item>
56+
</field>
57+
</dataset>
4358
</repository>
4459
</config>

0 commit comments

Comments
 (0)