ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*
|
||||
*/
|
||||
namespace Magento\Widget\Model\Config;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DataTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoCache config disabled
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
$fileResolver = $this->getMockForAbstractClass(\Magento\Framework\Config\FileResolverInterface::class);
|
||||
$fileResolver->expects($this->exactly(3))->method('get')->willReturnMap([
|
||||
['widget.xml', 'global', [file_get_contents(__DIR__ . '/_files/orders_and_returns.xml')]],
|
||||
['widget.xml', 'adminhtml', []],
|
||||
['widget.xml', 'design', [file_get_contents(__DIR__ . '/_files/orders_and_returns_customized.xml')]],
|
||||
]);
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$reader = $objectManager->create(\Magento\Widget\Model\Config\Reader::class, ['fileResolver' => $fileResolver]);
|
||||
/** @var \Magento\Widget\Model\Config\Data $configData */
|
||||
$configData = $objectManager->create(\Magento\Widget\Model\Config\Data::class, ['reader' => $reader]);
|
||||
$result = $configData->get();
|
||||
$expected = include '_files/expectedGlobalDesignArray.php';
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Widget\Model\Config;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class ReaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Widget\Model\Config\Reader
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $fileResolver;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->fileResolver = $this->getMockForAbstractClass(\Magento\Framework\Config\FileResolverInterface::class);
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->model = $objectManager->create(
|
||||
\Magento\Widget\Model\Config\Reader::class,
|
||||
['fileResolver' => $this->fileResolver]
|
||||
);
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$this->fileResolver->expects($this->once())
|
||||
->method('get')
|
||||
->willReturn([file_get_contents(__DIR__ . '/_files/orders_and_returns.xml')]);
|
||||
$expected = include __DIR__ . '/_files/expectedGlobalArray.php';
|
||||
$this->assertEquals($expected, $this->model->read('global'));
|
||||
}
|
||||
|
||||
public function testReadFile()
|
||||
{
|
||||
$file = file_get_contents(__DIR__ . '/_files/orders_and_returns.xml');
|
||||
$expected = include __DIR__ . '/_files/expectedGlobalArray.php';
|
||||
$this->assertEquals($expected, $this->model->readFile($file));
|
||||
}
|
||||
|
||||
public function testMergeCompleteAndPartial()
|
||||
{
|
||||
$fileList = [
|
||||
file_get_contents(__DIR__ . '/_files/catalog_new_products_list.xml'),
|
||||
file_get_contents(__DIR__ . '/_files/orders_and_returns_customized.xml'),
|
||||
];
|
||||
$this->fileResolver->expects($this->once())
|
||||
->method('get')
|
||||
->with('widget.xml', 'global')
|
||||
->willReturn($fileList);
|
||||
$expected = include __DIR__ . '/_files/expectedMergedArray.php';
|
||||
$this->assertEquals($expected, $this->model->read('global'));
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
|
||||
<widget id="new_products" class="Magento\Catalog\Block\Product\Widget\NewWidget" is_email_compatible="true"
|
||||
placeholder_image="Magento_Catalog::images/product_widget_new.png">
|
||||
<label translate="true">Catalog New Products List</label>
|
||||
<description translate="true">List of Products that are set as New</description>
|
||||
<parameters>
|
||||
<parameter name="display_type" xsi:type="select" required="true" visible="true">
|
||||
<label translate="true">Display Type</label>
|
||||
<description translate="true">All products - recently added products, New products - products marked as new</description>
|
||||
<options>
|
||||
<option name="default" value="all_products" selected="true">
|
||||
<label translate="true">All products</label>
|
||||
</option>
|
||||
<option name="item" value="new_products">
|
||||
<label translate="true">New products</label>
|
||||
</option>
|
||||
</options>
|
||||
</parameter>
|
||||
<parameter name="show_pager" xsi:type="select" visible="true"
|
||||
source_model="Magento\Config\Model\Config\Source\Yesno">
|
||||
<label translate="true">Display Page Control</label>
|
||||
</parameter>
|
||||
<parameter name="products_per_page" xsi:type="text" required="true" visible="true">
|
||||
<label translate="true">Number of Products per Page</label>
|
||||
<depends>
|
||||
<parameter name="show_pager" value="1" />
|
||||
</depends>
|
||||
<value>5</value>
|
||||
</parameter>
|
||||
<parameter name="products_count" xsi:type="text" required="true" visible="true">
|
||||
<label translate="true">Number of Products to Display</label>
|
||||
<value>10</value>
|
||||
</parameter>
|
||||
<parameter name="template" xsi:type="select" required="true" visible="true">
|
||||
<label translate="true">Template</label>
|
||||
<options>
|
||||
<option name="default" value="product/widget/new/content/new_grid.phtml" selected="true">
|
||||
<label translate="true">New Products Grid Template</label>
|
||||
</option>
|
||||
<option name="list" value="product/widget/new/content/new_list.phtml">
|
||||
<label translate="true">New Products List Template</label>
|
||||
</option>
|
||||
<option name="list_default"
|
||||
value="product/widget/new/column/new_default_list.phtml">
|
||||
<label translate="true">New Products Images and Names Template</label>
|
||||
</option>
|
||||
<option name="list_names"
|
||||
value="product/widget/new/column/new_names_list.phtml">
|
||||
<label translate="true">New Products Names Only Template</label>
|
||||
</option>
|
||||
<option name="list_images"
|
||||
value="product/widget/new/column/new_images_list.phtml">
|
||||
<label translate="true">New Products Images Only Template</label>
|
||||
</option>
|
||||
</options>
|
||||
</parameter>
|
||||
<parameter name="cache_lifetime" xsi:type="text" visible="true">
|
||||
<label translate="true">Cache Lifetime (Seconds)</label>
|
||||
<description translate="true">86400 by default, if not set. To refresh instantly, clear the Blocks HTML
|
||||
Output cache.
|
||||
</description>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<containers>
|
||||
<container name="left">
|
||||
<template name="default" value="list_default" />
|
||||
<template name="names_only" value="list_names" />
|
||||
<template name="images_only" value="list_images" />
|
||||
</container>
|
||||
<container name="content">
|
||||
<template name="grid" value="default" />
|
||||
<template name="list" value="list" />
|
||||
</container>
|
||||
<container name="right">
|
||||
<template name="default" value="list_default" />
|
||||
<template name="names_only" value="list_names" />
|
||||
<template name="images_only" value="list_images" />
|
||||
</container>
|
||||
</containers>
|
||||
</widget>
|
||||
</widgets>
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
return [
|
||||
'sales_widget_guestform' => [
|
||||
'@' => ['type' => \Magento\Sales\Block\Widget\Guest\Form::class],
|
||||
'is_email_compatible' => '1',
|
||||
'name' => 'Orders and Returns',
|
||||
'description' => 'Orders and Returns Search Form',
|
||||
'parameters' => [
|
||||
'title' => ['type' => 'text', 'visible' => '0', 'label' => 'Anchor Custom Title'],
|
||||
'template' => [
|
||||
'type' => 'select',
|
||||
'value' => 'hierarchy/widget/link/link_block.phtml',
|
||||
'values' => [
|
||||
'default' => [
|
||||
'value' => 'hierarchy/widget/link/link_block.phtml',
|
||||
'label' => 'CMS Page Link Block Template',
|
||||
],
|
||||
'link_inline' => [
|
||||
'value' => 'hierarchy/widget/link/link_inline.phtml',
|
||||
'label' => 'CMS Page Link Inline Template',
|
||||
],
|
||||
],
|
||||
'visible' => '0',
|
||||
],
|
||||
'link_display' => [
|
||||
'source_model' => \Magento\Config\Model\Config\Source\Yesno::class,
|
||||
'type' => 'select',
|
||||
'visible' => '1',
|
||||
'sort_order' => '10',
|
||||
'label' => 'Display a Link to Loading a Spreadsheet',
|
||||
'description' => "Defines whether a link to My Account",
|
||||
],
|
||||
'link_text' => [
|
||||
'type' => 'text',
|
||||
'value' => 'Load a list of SKUs',
|
||||
'visible' => '1',
|
||||
'required' => '1',
|
||||
'sort_order' => '20',
|
||||
'label' => 'Link Text',
|
||||
'description' => 'The text of the link to the My Account > Order by SKU page',
|
||||
'depends' => ['link_display' => ['value' => '1']],
|
||||
],
|
||||
'id_path' => [
|
||||
'type' => 'label',
|
||||
'@' => ['type' => 'complex'],
|
||||
'helper_block' => [
|
||||
'type' => \Magento\Catalog\Block\Adminhtml\Product\Widget\Chooser::class,
|
||||
'data' => ['button' => ['open' => 'Select Product...']],
|
||||
],
|
||||
'visible' => '1',
|
||||
'required' => '1',
|
||||
'sort_order' => '10',
|
||||
'label' => 'Product',
|
||||
],
|
||||
],
|
||||
'supported_containers' => [
|
||||
'0' => ['container_name' => 'left', 'template' => ['default' => 'default_template']],
|
||||
'1' => ['container_name' => 'right', 'template' => ['default' => 'default_template']],
|
||||
],
|
||||
]
|
||||
];
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
return [
|
||||
'sales_widget_guestform' => [
|
||||
'@' => ['type' => \Magento\Sales\Block\Widget\Guest\Form::class],
|
||||
'is_email_compatible' => '1',
|
||||
'name' => 'Orders and Returns',
|
||||
'description' => 'Orders and Returns Search Form',
|
||||
'parameters' => [
|
||||
'title' => ['type' => 'text', 'visible' => '0', 'label' => 'Anchor Custom Title'],
|
||||
'template' => [
|
||||
'type' => 'select',
|
||||
'value' => 'hierarchy/widget/link/link_block.phtml',
|
||||
'values' => [
|
||||
'default' => [
|
||||
'value' => 'hierarchy/widget/link/link_block.phtml',
|
||||
'label' => 'CMS Page Link Block Template',
|
||||
],
|
||||
'link_inline' => [
|
||||
'value' => 'hierarchy/widget/link/link_inline.phtml',
|
||||
'label' => 'CMS Page Link Inline Template',
|
||||
],
|
||||
],
|
||||
'visible' => '0',
|
||||
],
|
||||
'link_display' => [
|
||||
'source_model' => \Magento\Config\Model\Config\Source\Yesno::class,
|
||||
'type' => 'select',
|
||||
'visible' => '1',
|
||||
'sort_order' => '10',
|
||||
'label' => 'Display a Link to Loading a Spreadsheet',
|
||||
'description' => "Defines whether a link to My Account",
|
||||
],
|
||||
'link_text' => [
|
||||
'type' => 'text',
|
||||
'value' => 'Load a list of SKUs',
|
||||
'visible' => '1',
|
||||
'required' => '1',
|
||||
'sort_order' => '20',
|
||||
'label' => 'Link Text',
|
||||
'description' => 'The text of the link to the My Account > Order by SKU page',
|
||||
'depends' => ['link_display' => ['value' => '1']],
|
||||
],
|
||||
'id_path' => [
|
||||
'type' => 'label',
|
||||
'@' => ['type' => 'complex'],
|
||||
'helper_block' => [
|
||||
'type' => \Magento\Catalog\Block\Adminhtml\Product\Widget\Chooser::class,
|
||||
'data' => ['button' => ['open' => 'Select Product...']],
|
||||
],
|
||||
'visible' => '1',
|
||||
'required' => '1',
|
||||
'sort_order' => '10',
|
||||
'label' => 'Product',
|
||||
],
|
||||
],
|
||||
'supported_containers' => [
|
||||
'0' => ['container_name' => 'left', 'template' => ['default' => 'default_template']],
|
||||
'1' => ['container_name' => 'right', 'template' => ['default' => 'default_template']],
|
||||
],
|
||||
],
|
||||
'new_products' => [
|
||||
'@' => ['type' => \Magento\Sales\Block\Widget\Guest\Form::class],
|
||||
'is_email_compatible' => '1',
|
||||
'name' => 'Orders and Returns',
|
||||
'description' => 'Orders and Returns Search Form',
|
||||
'parameters' => [
|
||||
'title' => ['type' => 'text', 'visible' => '0', 'label' => 'Anchor Custom Title'],
|
||||
'template' => [
|
||||
'type' => 'select',
|
||||
'values' => [
|
||||
'default_template' => ['value' => 'widget/guest/form.phtml', 'label' => 'Default Template'],
|
||||
],
|
||||
'visible' => '0',
|
||||
],
|
||||
],
|
||||
'supported_containers' => [
|
||||
['container_name' => 'left', 'template' => ['default' => 'default_template']],
|
||||
['container_name' => 'right', 'template' => ['default' => 'default_template']],
|
||||
],
|
||||
]
|
||||
];
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
return [
|
||||
'new_products' => [
|
||||
'@' => ['type' => \Magento\Sales\Block\Widget\Guest\Form::class],
|
||||
'is_email_compatible' => '1',
|
||||
'placeholder_image' => 'Magento_Catalog::images/product_widget_new.png',
|
||||
'name' => 'Orders and Returns',
|
||||
'description' => 'Orders and Returns Search Form',
|
||||
'parameters' => [
|
||||
'display_type' => [
|
||||
'type' => 'select',
|
||||
'value' => 'all_products',
|
||||
'values' => [
|
||||
'default' => ['value' => 'all_products', 'label' => 'All products'],
|
||||
'item' => ['value' => 'new_products', 'label' => 'New products'],
|
||||
],
|
||||
'visible' => '1',
|
||||
'required' => '1',
|
||||
'label' => 'Display Type',
|
||||
'description' => 'All products - recently added products, New products - products marked as new',
|
||||
],
|
||||
'show_pager' => [
|
||||
'source_model' => "Magento\Config\Model\Config\Source\Yesno",
|
||||
'type' => 'select',
|
||||
'visible' => '1',
|
||||
'label' => 'Display Page Control',
|
||||
],
|
||||
'products_per_page' => [
|
||||
'type' => 'text',
|
||||
'value' => '5',
|
||||
'visible' => '1',
|
||||
'required' => '1',
|
||||
'label' => 'Number of Products per Page',
|
||||
'depends' => ['show_pager' => ['value' => '1']],
|
||||
],
|
||||
'products_count' => [
|
||||
'type' => 'text',
|
||||
'value' => '10',
|
||||
'visible' => '1',
|
||||
'required' => '1',
|
||||
'label' => 'Number of Products to Display',
|
||||
],
|
||||
'template' => [
|
||||
'type' => 'select',
|
||||
'value' => 'product/widget/new/content/new_grid.phtml',
|
||||
'values' => [
|
||||
'default' => [
|
||||
'value' => 'product/widget/new/content/new_grid.phtml',
|
||||
'label' => 'New Products Grid Template',
|
||||
],
|
||||
'list' => [
|
||||
'value' => 'product/widget/new/content/new_list.phtml',
|
||||
'label' => 'New Products List Template',
|
||||
],
|
||||
'list_default' => [
|
||||
'value' => 'product/widget/new/column/new_default_list.phtml',
|
||||
'label' => 'New Products Images and Names Template',
|
||||
],
|
||||
'list_names' => [
|
||||
'value' => 'product/widget/new/column/new_names_list.phtml',
|
||||
'label' => 'New Products Names Only Template',
|
||||
],
|
||||
'list_images' => [
|
||||
'value' => 'product/widget/new/column/new_images_list.phtml',
|
||||
'label' => 'New Products Images Only Template',
|
||||
],
|
||||
'default_template' => ['value' => 'widget/guest/form.phtml', 'label' => 'Default Template'],
|
||||
],
|
||||
'visible' => '0',
|
||||
'required' => '1',
|
||||
'label' => 'Template',
|
||||
],
|
||||
'cache_lifetime' => [
|
||||
'type' => 'text',
|
||||
'visible' => '1',
|
||||
'label' => 'Cache Lifetime (Seconds)',
|
||||
'description' => "86400 by default, if not set. To refresh instantly, clear the Blocks HTML
|
||||
Output cache.
|
||||
",
|
||||
],
|
||||
'title' => ['type' => 'text', 'visible' => '0', 'label' => 'Anchor Custom Title'],
|
||||
],
|
||||
'supported_containers' => [
|
||||
[
|
||||
'container_name' => 'left',
|
||||
'template' => [
|
||||
'default' => 'default_template',
|
||||
'names_only' => 'list_names',
|
||||
'images_only' => 'list_images',
|
||||
],
|
||||
],
|
||||
['container_name' => 'content', 'template' => ['grid' => 'default', 'list' => 'list']],
|
||||
[
|
||||
'container_name' => 'right',
|
||||
'template' => [
|
||||
'default' => 'default_template',
|
||||
'names_only' => 'list_names',
|
||||
'images_only' => 'list_images',
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
|
||||
<widget id="sales_widget_guestform" class="Magento\Sales\Block\Widget\Guest\Form" is_email_compatible="true" >
|
||||
<label translate="true">Orders and Returns</label>
|
||||
<description translate="true">Orders and Returns Search Form</description>
|
||||
<parameters>
|
||||
<parameter name="title" xsi:type="text" visible="false">
|
||||
<label translate="true">Anchor Custom Title</label>
|
||||
</parameter>
|
||||
<parameter name="template" xsi:type="select" visible="false">
|
||||
<options>
|
||||
<option name="default" value="hierarchy/widget/link/link_block.phtml" selected="true">
|
||||
<label translate="true">CMS Page Link Block Template</label>
|
||||
</option>
|
||||
<option name="link_inline" value="hierarchy/widget/link/link_inline.phtml">
|
||||
<label translate="true">CMS Page Link Inline Template</label>
|
||||
</option>
|
||||
</options>
|
||||
</parameter>
|
||||
<parameter name="link_display" xsi:type="select" visible="true" sort_order="10"
|
||||
source_model="Magento\Config\Model\Config\Source\Yesno">
|
||||
<label translate="true">Display a Link to Loading a Spreadsheet</label>
|
||||
<description translate="true">Defines whether a link to My Account</description>
|
||||
</parameter>
|
||||
<parameter name="link_text" xsi:type="text" required="true" visible="true" sort_order="20">
|
||||
<label translate="true">Link Text</label>
|
||||
<description translate="true">The text of the link to the My Account &gt; Order by SKU page</description>
|
||||
<depends>
|
||||
<parameter name="link_display" value="1" />
|
||||
</depends>
|
||||
<value translate="true">Load a list of SKUs</value>
|
||||
</parameter>
|
||||
<parameter name="id_path" xsi:type="block" visible="true" required="true" sort_order="10">
|
||||
<label translate="true">Product</label>
|
||||
<block class="Magento\Catalog\Block\Adminhtml\Product\Widget\Chooser">
|
||||
<data>
|
||||
<item name="button" xsi:type="array">
|
||||
<item name="open" xsi:type="string">Select Product...</item>
|
||||
</item>
|
||||
</data>
|
||||
</block>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<containers>
|
||||
<container name="left">
|
||||
<template name="default" value="default_template" />
|
||||
</container>
|
||||
<container name="right">
|
||||
<template name="default" value="default_template" />
|
||||
</container>
|
||||
</containers>
|
||||
</widget>
|
||||
</widgets>
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
|
||||
<widget id="new_products" class="Magento\Sales\Block\Widget\Guest\Form" is_email_compatible="true" >
|
||||
<label translate="true">Orders and Returns</label>
|
||||
<description translate="true">Orders and Returns Search Form</description>
|
||||
<parameters>
|
||||
<parameter name="title" xsi:type="text" visible="false">
|
||||
<label translate="true">Anchor Custom Title</label>
|
||||
</parameter>
|
||||
<parameter name="template" xsi:type="select" visible="false">
|
||||
<options>
|
||||
<option name="default_template" value="widget/guest/form.phtml">
|
||||
<label translate="true">Default Template</label>
|
||||
</option>
|
||||
</options>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<containers>
|
||||
<container name="left">
|
||||
<template name="default" value="default_template" />
|
||||
</container>
|
||||
<container name="right">
|
||||
<template name="default" value="default_template" />
|
||||
</container>
|
||||
</containers>
|
||||
</widget>
|
||||
</widgets>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Widget\Model\Layout;
|
||||
|
||||
class UpdateTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Widget\Model\Layout\Update
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\Layout\Update::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\Layout\Update::class
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
\Magento\Widget\Model\ResourceModel\Layout\Update::class,
|
||||
$this->_model->getResource()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testCrud()
|
||||
{
|
||||
$this->_model->setData(['handle' => 'default', 'xml' => '<layout/>', 'sort_order' => 123]);
|
||||
$entityHelper = new \Magento\TestFramework\Entity(
|
||||
$this->_model,
|
||||
['handle' => 'custom', 'xml' => '<layout version="0.1.0"/>', 'sort_order' => 456]
|
||||
);
|
||||
$entityHelper->testCrud();
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Widget\Model\ResourceModel\Layout;
|
||||
|
||||
class UpdateTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Widget\Model\ResourceModel\Layout\Update
|
||||
*/
|
||||
protected $_resourceModel;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_resourceModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\ResourceModel\Layout\Update::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Widget/_files/layout_update.php
|
||||
*/
|
||||
public function testFetchUpdatesByHandle()
|
||||
{
|
||||
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
|
||||
$theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Design\ThemeInterface::class
|
||||
);
|
||||
$theme->load('Test Theme', 'theme_title');
|
||||
$result = $this->_resourceModel->fetchUpdatesByHandle(
|
||||
'test_handle',
|
||||
$theme,
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()
|
||||
);
|
||||
$this->assertEquals('not_temporary', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Backend/controllers/_files/cache/application_cache.php
|
||||
* @magentoDataFixture Magento/Widget/_files/layout_cache.php
|
||||
*/
|
||||
public function testSaveAfterClearCache()
|
||||
{
|
||||
/** @var $appCache \Magento\Framework\App\Cache */
|
||||
$appCache = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Cache::class
|
||||
);
|
||||
/** @var \Magento\Framework\App\Cache\Type\Layout $layoutCache */
|
||||
$layoutCache = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Cache\Type\Layout::class
|
||||
);
|
||||
|
||||
$this->assertNotEmpty($appCache->load('APPLICATION_FIXTURE'));
|
||||
$this->assertNotEmpty($layoutCache->load('LAYOUT_CACHE_FIXTURE'));
|
||||
|
||||
/** @var $layoutUpdate \Magento\Widget\Model\Layout\Update */
|
||||
$layoutUpdate = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\Layout\Update::class
|
||||
);
|
||||
$layoutUpdate->setHasDataChanges(true);
|
||||
$this->_resourceModel->save($layoutUpdate);
|
||||
|
||||
$this->assertNotEmpty($appCache->load('APPLICATION_FIXTURE'), 'Non-layout cache must be kept');
|
||||
$this->assertFalse($layoutCache->load('LAYOUT_CACHE_FIXTURE'), 'Layout cache must be erased');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Widget\Model\Template;
|
||||
|
||||
class FilterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testMediaDirective()
|
||||
{
|
||||
$image = 'wysiwyg/VB.png';
|
||||
$construction = ['{{media url="' . $image . '"}}', 'media', ' url="' . $image . '"'];
|
||||
$baseUrl = 'http://localhost/media/';
|
||||
|
||||
/** @var \Magento\Widget\Model\Template\Filter $filter */
|
||||
$filter = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\Template\Filter::class
|
||||
);
|
||||
$result = $filter->mediaDirective($construction);
|
||||
$this->assertEquals($baseUrl . $image, $result);
|
||||
}
|
||||
|
||||
public function testMediaDirectiveWithEncodedQuotes()
|
||||
{
|
||||
$image = 'wysiwyg/VB.png';
|
||||
$construction = ['{{media url="' . $image . '"}}', 'media', ' url="' . $image . '"'];
|
||||
$baseUrl = 'http://localhost/media/';
|
||||
|
||||
/** @var \Magento\Widget\Model\Template\Filter $filter */
|
||||
$filter = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\Template\Filter::class
|
||||
);
|
||||
$result = $filter->mediaDirective($construction);
|
||||
$this->assertEquals($baseUrl . $image, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Widget\Model\Widget;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Widget\Model\Widget\Config
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\Widget\Config::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* App isolation is enabled, because we change current area and design
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetPluginSettings()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->setDesignTheme(
|
||||
'Magento/backend'
|
||||
);
|
||||
|
||||
$config = new \Magento\Framework\DataObject();
|
||||
$settings = $this->_model->getPluginSettings($config);
|
||||
|
||||
$this->assertArrayHasKey('plugins', $settings);
|
||||
$plugins = array_shift($settings['plugins']);
|
||||
$this->assertArrayHasKey('options', $plugins);
|
||||
$this->assertArrayHasKey('window_url', $plugins['options']);
|
||||
$this->assertArrayHasKey('placeholders', $plugins['options']);
|
||||
|
||||
$jsFilename = $plugins['src'];
|
||||
$this->assertStringMatchesFormat(
|
||||
'http://localhost/static/%s/adminhtml/Magento/backend/en_US/%s/editor_plugin.js',
|
||||
$jsFilename
|
||||
);
|
||||
|
||||
$this->assertIsArray($plugins['options']['placeholders']);
|
||||
|
||||
$this->assertStringStartsWith(
|
||||
'http://localhost/index.php/backend/admin/widget/index/key',
|
||||
$plugins['options']['window_url']
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetWidgetWindowUrl()
|
||||
{
|
||||
$config = new \Magento\Framework\DataObject(['widget_filters' => ['is_email_compatible' => 1]]);
|
||||
|
||||
$url = $this->_model->getWidgetWindowUrl($config);
|
||||
|
||||
$this->assertStringStartsWith('http://localhost/index.php/backend/admin/widget/index/skip_widgets', $url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Widget\Model\Widget;
|
||||
|
||||
class InstanceTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Widget\Model\Widget\Instance
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\Widget\Instance::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetGetType()
|
||||
{
|
||||
$this->assertEmpty($this->_model->getType());
|
||||
$this->assertSame('test', $this->_model->setType('test')->getType());
|
||||
$this->assertSame('test', $this->_model->getInstanceType());
|
||||
}
|
||||
|
||||
public function testSetThemeId()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
|
||||
->setAreaCode('frontend');
|
||||
$theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->setDefaultDesignTheme()->getDesignTheme();
|
||||
$this->_model->setThemeId($theme->getId());
|
||||
|
||||
$this->assertEquals($theme->getId(), $this->_model->getThemeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Widget\Model\Widget\Instance
|
||||
*/
|
||||
public function testGetWidgetConfigAsArray()
|
||||
{
|
||||
$config = $this->_model->setType(\Magento\Catalog\Block\Product\Widget\NewWidget::class)
|
||||
->getWidgetConfigAsArray();
|
||||
$this->assertIsArray($config);
|
||||
$element = null;
|
||||
if (isset(
|
||||
$config['parameters']
|
||||
) && isset(
|
||||
$config['parameters']['template']
|
||||
) && isset(
|
||||
$config['parameters']['template']['values']
|
||||
) && isset(
|
||||
$config['parameters']['template']['values']['list']
|
||||
)
|
||||
) {
|
||||
$element = $config['parameters']['template']['values']['list'];
|
||||
}
|
||||
$expected = [
|
||||
'value' => 'product/widget/new/content/new_list.phtml',
|
||||
'label' => 'New Products List Template',
|
||||
];
|
||||
$this->assertNotNull($element);
|
||||
$this->assertEquals($expected, $element);
|
||||
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Widget\Model\Widget\Instance
|
||||
*/
|
||||
public function testGetWidgetSupportedContainers()
|
||||
{
|
||||
$this->_model->setType(\Magento\Catalog\Block\Product\Widget\NewWidget::class);
|
||||
$containers = $this->_model->getWidgetSupportedContainers();
|
||||
$this->assertIsArray($containers);
|
||||
$this->assertContains('sidebar.main', $containers);
|
||||
$this->assertContains('content', $containers);
|
||||
$this->assertContains('sidebar.additional', $containers);
|
||||
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Widget\Model\Widget\Instance $model
|
||||
* @depends testGetWidgetSupportedContainers
|
||||
*/
|
||||
public function testGetWidgetSupportedTemplatesByContainer($model)
|
||||
{
|
||||
$templates = $model->getWidgetSupportedTemplatesByContainer('content');
|
||||
$this->assertNotEmpty($templates);
|
||||
$this->assertIsArray($templates);
|
||||
foreach ($templates as $row) {
|
||||
$this->assertArrayHasKey('value', $row);
|
||||
$this->assertArrayHasKey('label', $row);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Widget\Model\Widget\Instance::generateLayoutUpdateXml()
|
||||
* @covers \Magento\Widget\Model\Widget\Instance::getWidgetParameters()
|
||||
* @param \Magento\Widget\Model\Widget\Instance $model
|
||||
* @depends testGetWidgetConfigAsArray
|
||||
*/
|
||||
public function testGenerateLayoutUpdateXml(\Magento\Widget\Model\Widget\Instance $model)
|
||||
{
|
||||
$params = [
|
||||
'display_mode' => 'fixed',
|
||||
'types' => ['type_1', 'type_2'],
|
||||
'conditions' => [
|
||||
'1' => [
|
||||
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
|
||||
'aggregator' => 'all',
|
||||
'value' => '1',
|
||||
'new_child' => '',
|
||||
],
|
||||
'1--1' => [
|
||||
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
|
||||
'attribute' => 'attribute_set_id',
|
||||
'value' => '4',
|
||||
'operator' => '==',
|
||||
],
|
||||
],
|
||||
];
|
||||
$model->setData('widget_parameters', $params);
|
||||
$this->assertEquals('', $model->generateLayoutUpdateXml('content'));
|
||||
$model->setId('test_id')->setPackageTheme('Magento/luma');
|
||||
$result = $model->generateLayoutUpdateXml('content');
|
||||
$this->assertStringContainsString('<body><referenceContainer name="content">', $result);
|
||||
$this->assertStringContainsString('<block class="' . $model->getType() . '"', $result);
|
||||
$this->assertEquals(count($params), substr_count($result, '<action method="setData">'));
|
||||
$this->assertStringContainsString('<argument name="name" xsi:type="string">display_mode</argument>', $result);
|
||||
$this->assertStringContainsString('<argument name="value" xsi:type="string">fixed</argument>', $result);
|
||||
$this->assertStringContainsString('<argument name="name" xsi:type="string">types</argument>', $result);
|
||||
$this->assertStringContainsString('<argument name="value" xsi:type="string">type_1,type_2</argument>', $result);
|
||||
$this->assertStringContainsString(
|
||||
'<argument name="name" xsi:type="string">conditions_encoded</argument>',
|
||||
$result
|
||||
);
|
||||
$this->assertStringContainsString('`Magento||CatalogWidget||Model||Rule||Condition||Combine`', $result);
|
||||
$this->assertStringContainsString('`Magento||CatalogWidget||Model||Rule||Condition||Product`', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Widget\Model\Widget\Instance::beforeSave()
|
||||
* @magentoDataFixture Magento/Widget/_files/new_widget.php
|
||||
* @dataProvider beforeSaveDataProvider
|
||||
* @param array $expected
|
||||
*/
|
||||
public function testBeforeSave(array $expected)
|
||||
{
|
||||
/** @var \Magento\Widget\Model\ResourceModel\Widget\Instance $resourceModel */
|
||||
$resourceModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Widget\Model\ResourceModel\Widget\Instance::class);
|
||||
$resourceModel->load($this->_model, 'Magento\Widget\NewSampleWidget', 'instance_type');
|
||||
|
||||
$this->assertSame($expected, $this->_model->getWidgetParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function beforeSaveDataProvider()
|
||||
{
|
||||
return [
|
||||
# Variation 1
|
||||
[
|
||||
['block_id' => '2']
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Instance $model
|
||||
* @depends testGetWidgetConfigAsArray
|
||||
*/
|
||||
public function testGenerateLayoutUpdateXmlWithInvalidParamName(\Magento\Widget\Model\Widget\Instance $model)
|
||||
{
|
||||
$params = [
|
||||
'block_id' => '2',
|
||||
'block_id</argument><argument name="value" xsi:type="string">2</argument></action></block><block'
|
||||
. ' class="Magento\Cms\Block\Widget\Block" name="dfgdfgdfg" template="widget/static_block/default.phtml">'
|
||||
. '<action method="setData"><argument name="name" xsi:type="string">' => 'some_value',
|
||||
];
|
||||
$this->expectException('\Magento\Framework\Exception\LocalizedException');
|
||||
$this->expectExceptionMessage('Layout update is invalid');
|
||||
$model->setData('widget_parameters', $params);
|
||||
$model->generateLayoutUpdateXml('content');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Widget\Model;
|
||||
|
||||
class WidgetTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Widget\Model\Widget
|
||||
*/
|
||||
protected $_model = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\Widget::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetWidgetsArray()
|
||||
{
|
||||
$declaredWidgets = $this->_model->getWidgetsArray();
|
||||
$this->assertNotEmpty($declaredWidgets);
|
||||
$this->assertIsArray($declaredWidgets);
|
||||
foreach ($declaredWidgets as $row) {
|
||||
$this->assertArrayHasKey('name', $row);
|
||||
$this->assertArrayHasKey('code', $row);
|
||||
$this->assertArrayHasKey('type', $row);
|
||||
$this->assertArrayHasKey('description', $row);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $expectedFile
|
||||
* @return string
|
||||
*
|
||||
* @dataProvider getPlaceholderImageUrlDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetPlaceholderImageUrl($type, $expectedFile)
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()
|
||||
->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
$objectManager->get(\Magento\Framework\View\DesignInterface::class)->setDesignTheme('Magento/backend');
|
||||
$expectedFilePath = "/adminhtml/Magento/backend/en_US/{$expectedFile}";
|
||||
|
||||
$url = $this->_model->getPlaceholderImageUrl($type);
|
||||
$this->assertStringEndsWith($expectedFilePath, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPlaceholderImageUrlDataProvider()
|
||||
{
|
||||
return [
|
||||
'custom image' => [\Magento\Catalog\Block\Product\Widget\NewWidget::class,
|
||||
'Magento_Catalog/images/product_widget_new.png',
|
||||
],
|
||||
'default image' => ['non_existing_widget_type', 'Magento_Widget/placeholder.png']
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user