ltsecurityinc安防产品在线商城代码
This commit is contained in:
+142
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\Backend\Block\Widget\Grid\Column;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Phrase;
|
||||
use Magento\Framework\Phrase\RendererInterface;
|
||||
|
||||
class TextTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var RendererInterface
|
||||
*/
|
||||
private $origRenderer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->origRenderer = Phrase::getRenderer();
|
||||
/** @var RendererInterface|PHPUnit\Framework\MockObject_MockObject $rendererMock */
|
||||
$rendererMock = $this->getMockForAbstractClass(RendererInterface::class);
|
||||
$rendererMock->expects($this->any())
|
||||
->method('render')
|
||||
->willReturnCallback(
|
||||
function ($input) {
|
||||
return end($input) . ' translated';
|
||||
}
|
||||
);
|
||||
Phrase::setRenderer($rendererMock);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Phrase::setRenderer($this->origRenderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columnData
|
||||
* @param array $rowData
|
||||
* @param string $expected
|
||||
* @dataProvider renderDataProvider
|
||||
*/
|
||||
public function testRender($columnData, $rowData, $expected)
|
||||
{
|
||||
/** @var Text $renderer */
|
||||
$renderer = $this->objectManager->create(Text::class);
|
||||
/** @var Column $column */
|
||||
$column = $this->objectManager->create(
|
||||
Column::class,
|
||||
[
|
||||
'data' => $columnData
|
||||
]
|
||||
);
|
||||
/** @var DataObject $row */
|
||||
$row = $this->objectManager->create(
|
||||
DataObject::class,
|
||||
[
|
||||
'data' => $rowData
|
||||
]
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$renderer->setColumn($column)->render($row)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function renderDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'index' => 'title',
|
||||
'translate' => true
|
||||
],
|
||||
[
|
||||
'title' => 'String'
|
||||
],
|
||||
'String translated'
|
||||
],
|
||||
[
|
||||
[
|
||||
'index' => 'title'
|
||||
],
|
||||
[
|
||||
'title' => 'Doesn\'t need to be translated'
|
||||
],
|
||||
'Doesn't need to be translated'
|
||||
],
|
||||
[
|
||||
[
|
||||
'format' => '#$subscriber_id $customer_name ($subscriber_email)'
|
||||
],
|
||||
[
|
||||
'subscriber_id' => '10',
|
||||
'customer_name' => 'John Doe',
|
||||
'subscriber_email' => 'john@doe.com'
|
||||
],
|
||||
'#10 John Doe (john@doe.com)'
|
||||
],
|
||||
[
|
||||
[
|
||||
'format' => '$customer_name, email: $subscriber_email',
|
||||
'translate' => true
|
||||
],
|
||||
[
|
||||
'customer_name' => 'John Doe',
|
||||
'subscriber_email' => 'john@doe.com'
|
||||
],
|
||||
'John Doe, email: john@doe.com translated'
|
||||
],
|
||||
[
|
||||
[
|
||||
'format' => 'String',
|
||||
'translate' => true
|
||||
],
|
||||
[],
|
||||
'String translated'
|
||||
],
|
||||
[
|
||||
[
|
||||
'format' => 'Doesn\'t need to be translated'
|
||||
],
|
||||
[],
|
||||
'Doesn't need to be translated'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ColumnSetTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Block\Widget\Grid\ColumnSet
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_layoutMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_columnMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_columnMock = $this->createPartialMock(
|
||||
\Magento\Backend\Block\Widget\Grid\Column::class,
|
||||
['setSortable', 'setRendererType', 'setFilterType', 'addHeaderCssClass', 'setGrid']
|
||||
);
|
||||
$this->_layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
|
||||
$this->_layoutMock->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'getChildBlocks'
|
||||
)->willReturn(
|
||||
[$this->_columnMock]
|
||||
);
|
||||
|
||||
$context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Element\Template\Context::class,
|
||||
['layout' => $this->_layoutMock]
|
||||
);
|
||||
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Backend\Block\Widget\Grid\ColumnSet::class,
|
||||
'',
|
||||
['context' => $context]
|
||||
);
|
||||
$this->_block->setTemplate(null);
|
||||
}
|
||||
|
||||
public function testBeforeToHtmlAddsClassToLastColumn()
|
||||
{
|
||||
$this->_columnMock->expects($this->any())->method('addHeaderCssClass')->with($this->equalTo('last'));
|
||||
$this->_block->toHtml();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ContainerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPseudoConstruct()
|
||||
{
|
||||
/** @var $block \Magento\Backend\Block\Widget\Grid\Container */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Backend\Block\Widget\Grid\Container::class,
|
||||
'',
|
||||
[
|
||||
'data' => [
|
||||
\Magento\Backend\Block\Widget\Container::PARAM_CONTROLLER => 'widget',
|
||||
\Magento\Backend\Block\Widget\Container::PARAM_HEADER_TEXT => 'two',
|
||||
\Magento\Backend\Block\Widget\Grid\Container::PARAM_BLOCK_GROUP => 'Magento_Backend',
|
||||
\Magento\Backend\Block\Widget\Grid\Container::PARAM_BUTTON_NEW => 'four',
|
||||
\Magento\Backend\Block\Widget\Grid\Container::PARAM_BUTTON_BACK => 'five',
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->assertStringEndsWith('widget', $block->getHeaderCssClass());
|
||||
$this->assertStringContainsString('two', $block->getHeaderText());
|
||||
$this->assertInstanceOf(\Magento\Backend\Block\Widget\Grid::class, $block->getChildBlock('grid'));
|
||||
$this->assertEquals('four', $block->getAddButtonLabel());
|
||||
$this->assertEquals('five', $block->getBackButtonLabel());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid;
|
||||
|
||||
use Laminas\Stdlib\Parameters;
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
use Magento\Framework\Data\Collection;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ExtendedTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Extended
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
protected $_layoutMock;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_layoutMock = Bootstrap::getObjectManager()->get(
|
||||
LayoutInterface::class
|
||||
);
|
||||
$context = Bootstrap::getObjectManager()->create(
|
||||
Context::class,
|
||||
['layout' => $this->_layoutMock]
|
||||
);
|
||||
$this->_block = $this->_layoutMock->createBlock(
|
||||
Extended::class,
|
||||
'grid',
|
||||
['context' => $context]
|
||||
);
|
||||
|
||||
$this->_block->addColumn('column1', ['id' => 'columnId1']);
|
||||
$this->_block->addColumn('column2', ['id' => 'columnId2']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testAddColumnAddsChildToColumnSet()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Column::class,
|
||||
$this->_block->getColumnSet()->getChildBlock('column1')
|
||||
);
|
||||
$this->assertCount(2, $this->_block->getColumnSet()->getChildNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testRemoveColumn()
|
||||
{
|
||||
$this->assertCount(2, $this->_block->getColumnSet()->getChildNames());
|
||||
$this->_block->removeColumn('column1');
|
||||
$this->assertCount(1, $this->_block->getColumnSet()->getChildNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testSortColumnsByOrder()
|
||||
{
|
||||
$columnNames = $this->_block->getLayout()->getChildNames($this->_block->getColumnSet()->getNameInLayout());
|
||||
$this->assertEquals($this->_block->getColumn('column1')->getNameInLayout(), $columnNames[0]);
|
||||
$this->_block->addColumnsOrder('column1', 'column2');
|
||||
$this->_block->sortColumnsByOrder();
|
||||
$columnNames = $this->_block->getLayout()->getChildNames($this->_block->getColumnSet()->getNameInLayout());
|
||||
$this->assertEquals($this->_block->getColumn('column2')->getNameInLayout(), $columnNames[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetMainButtonsHtmlReturnsEmptyStringIfFiltersArentVisible()
|
||||
{
|
||||
$this->_block->setFilterVisibility(false);
|
||||
$this->assertEquals('', $this->_block->getMainButtonsHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that template does not have redundant div close tag
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExtendedTemplateMarkup(): void
|
||||
{
|
||||
$mockCollection = $this->getMockBuilder(Collection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->_block->setCollection($mockCollection);
|
||||
$this->_block->getRequest()
|
||||
->setQuery(
|
||||
Bootstrap::getObjectManager()
|
||||
->create(
|
||||
Parameters::class,
|
||||
[
|
||||
'values' => [
|
||||
'ajax' => true
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
$html = $this->_block->getHtml();
|
||||
$html = str_replace(["\n", " "], '', $html);
|
||||
$this->assertStringEndsWith("</table></div>", $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ItemTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetAdditionalActionBlock()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Backend\Block\Widget\Grid\Massaction\Item */
|
||||
$block = $layout->createBlock(\Magento\Backend\Block\Widget\Grid\Massaction\Item::class, 'block');
|
||||
$expected = $layout->addBlock(\Magento\Framework\View\Element\Template::class, 'additional_action', 'block');
|
||||
$this->assertSame($expected, $block->getAdditionalActionBlock());
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid\Massaction;
|
||||
|
||||
class AdditionalTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
$interpreter = $this->createMock(\Magento\Framework\View\Layout\Argument\Interpreter\Options::class);
|
||||
/**
|
||||
* @var Additional $block
|
||||
*/
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Backend\Block\Widget\Grid\Massaction\Additional::class,
|
||||
['optionsInterpreter' => $interpreter]
|
||||
);
|
||||
$modelClass = \Magento\Backend\Block\Widget\Grid\Massaction::class;
|
||||
$data = [
|
||||
'fields' => [
|
||||
'field1' => ['type' => 'select', 'values' => $modelClass, 'class' => 'custom_class'],
|
||||
],
|
||||
];
|
||||
$block->setData($data);
|
||||
$evaluatedValues = [
|
||||
['value' => 'value1', 'label' => 'label 1'],
|
||||
['value' => 'value2', 'label' => 'label 2'],
|
||||
];
|
||||
$interpreter->expects(
|
||||
$this->once()
|
||||
)->method(
|
||||
'evaluate'
|
||||
)->with(
|
||||
['model' => $modelClass]
|
||||
)->willReturn(
|
||||
$evaluatedValues
|
||||
);
|
||||
|
||||
$block->setNameInLayout('test_block_name');
|
||||
$html = $block->toHtml();
|
||||
$this->assertStringMatchesFormat(
|
||||
'%acustom_class absolute-advice%avalue="value1"%slabel 1%avalue="value2"%slabel 2%a',
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid;
|
||||
|
||||
use Magento\TestFramework\App\State;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoComponentsDir Magento/Backend/Block/_files/design
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class MassactionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Block\Widget\Grid\Massaction
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\View\LayoutInterface
|
||||
*/
|
||||
protected $_layout;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mageMode;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->mageMode = $this->objectManager->get(State::class)->getMode();
|
||||
|
||||
/** @var \Magento\Theme\Model\Theme\Registration $registration */
|
||||
$registration = $this->objectManager->get(\Magento\Theme\Model\Theme\Registration::class);
|
||||
$registration->register();
|
||||
$this->objectManager->get(\Magento\Framework\View\DesignInterface::class)
|
||||
->setDesignTheme('BackendTest/test_default');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->objectManager->get(State::class)->setMode($this->mageMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mageMode
|
||||
*/
|
||||
private function loadLayout($mageMode = State::MODE_DEVELOPER)
|
||||
{
|
||||
$this->objectManager->get(State::class)->setMode($mageMode);
|
||||
$this->_layout = $this->objectManager->create(
|
||||
\Magento\Framework\View\LayoutInterface::class,
|
||||
['area' => 'adminhtml']
|
||||
);
|
||||
$this->_layout->getUpdate()->load('layout_test_grid_handle');
|
||||
$this->_layout->generateXml();
|
||||
$this->_layout->generateElements();
|
||||
|
||||
$this->_block = $this->_layout->getBlock('admin.test.grid.massaction');
|
||||
$this->assertNotFalse($this->_block, 'Could not load the block for testing');
|
||||
}
|
||||
|
||||
public function testMassactionDefaultValues()
|
||||
{
|
||||
$this->loadLayout();
|
||||
|
||||
/** @var $blockEmpty \Magento\Backend\Block\Widget\Grid\Massaction */
|
||||
$blockEmpty = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\View\LayoutInterface::class)
|
||||
->createBlock(\Magento\Backend\Block\Widget\Grid\Massaction::class);
|
||||
$this->assertEmpty($blockEmpty->getItems());
|
||||
$this->assertEquals(0, $blockEmpty->getCount());
|
||||
$this->assertSame('[]', $blockEmpty->getItemsJson());
|
||||
|
||||
$this->assertFalse($blockEmpty->isAvailable());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mageMode
|
||||
* @param int $expectedCount
|
||||
* @dataProvider getCountDataProvider
|
||||
*/
|
||||
public function testGetCount($mageMode, $expectedCount)
|
||||
{
|
||||
$this->loadLayout($mageMode);
|
||||
$this->assertEquals($expectedCount, $this->_block->getCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCountDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'mageMode' => State::MODE_DEVELOPER,
|
||||
'expectedCount' => 3,
|
||||
],
|
||||
[
|
||||
'mageMode' => State::MODE_DEFAULT,
|
||||
'expectedCount' => 3,
|
||||
],
|
||||
[
|
||||
'mageMode' => State::MODE_PRODUCTION,
|
||||
'expectedCount' => 2,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $itemId
|
||||
* @param array $expectedItem
|
||||
* @dataProvider getItemsDataProvider
|
||||
*/
|
||||
public function testGetItems($itemId, $expectedItem)
|
||||
{
|
||||
$this->loadLayout();
|
||||
|
||||
$items = $this->_block->getItems();
|
||||
$this->assertCount(3, $items);
|
||||
$this->assertArrayHasKey($itemId, $items);
|
||||
|
||||
$actualItem = $items[$itemId];
|
||||
$this->assertEquals($expectedItem['id'], $actualItem->getId());
|
||||
$this->assertEquals($expectedItem['label'], $actualItem->getLabel());
|
||||
$this->assertMatchesRegularExpression($expectedItem['url'], $actualItem->getUrl());
|
||||
$this->assertEquals($expectedItem['selected'], $actualItem->getSelected());
|
||||
$this->assertEquals($expectedItem['blockname'], $actualItem->getBlockName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getItemsDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'option_id1',
|
||||
[
|
||||
'id' => 'option_id1',
|
||||
'label' => 'Option One',
|
||||
'url' => '#http:\/\/localhost\/index\.php\/(?:key\/([\w\d]+)\/)?#',
|
||||
'selected' => false,
|
||||
'blockname' => ''
|
||||
],
|
||||
],
|
||||
[
|
||||
'option_id2',
|
||||
[
|
||||
'id' => 'option_id2',
|
||||
'label' => 'Option Two',
|
||||
'url' => '#http:\/\/localhost\/index\.php\/(?:key\/([\w\d]+)\/)?#',
|
||||
'selected' => false,
|
||||
'blockname' => ''
|
||||
]
|
||||
],
|
||||
[
|
||||
'option_id3',
|
||||
[
|
||||
'id' => 'option_id3',
|
||||
'label' => 'Option Three',
|
||||
'url' => '#http:\/\/localhost\/index\.php\/(?:key\/([\w\d]+)\/)?#',
|
||||
'selected' => false,
|
||||
'blockname' => ''
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user