init
This commit is contained in:
+95
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\Block\Widget\Button;
|
||||
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Testing SplitButton widget
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class SplitButtonTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $objectManager->get(LayoutInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the block.
|
||||
*
|
||||
* @return SplitButton
|
||||
*/
|
||||
private function createBlock(): SplitButton
|
||||
{
|
||||
/** @var SplitButton $block */
|
||||
$block = $this->layout->createBlock(SplitButton::class, 'button_block');
|
||||
$block->setLayout($this->layout);
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test resulting button HTML.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testToHtml(): void
|
||||
{
|
||||
$block = $this->createBlock();
|
||||
$block->addData(
|
||||
[
|
||||
'title' => 'A button',
|
||||
'label' => 'A button',
|
||||
'has_split' => true,
|
||||
'button_class' => 'aclass',
|
||||
'id' => 'split-button',
|
||||
'disabled' => false,
|
||||
'class' => 'aclass',
|
||||
'data_attribute' => ['bind' => ['var' => 'val']],
|
||||
'options' => [
|
||||
[
|
||||
'disabled' => false,
|
||||
'title' => 'An option',
|
||||
'label' => 'An option',
|
||||
'onclick' => $onclick = 'console.log("option")',
|
||||
'style' => 'width: 100px'
|
||||
]
|
||||
],
|
||||
'dropdown_button_aria_label' => 'Split button options',
|
||||
]
|
||||
);
|
||||
|
||||
$html = $block->toHtml();
|
||||
$this->assertStringContainsString('<button ', $html);
|
||||
$this->assertStringContainsString('<span>A button</span>', $html);
|
||||
$this->assertStringNotContainsString('onclick=', $html);
|
||||
$this->assertStringNotContainsString('style=', $html);
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/\<script.*?\>.*?' . preg_quote($onclick) . '.*?\<\/script\>/ims',
|
||||
$html
|
||||
);
|
||||
$this->assertStringContainsString('width', $html);
|
||||
$this->assertStringContainsString('100px', $html);
|
||||
$this->assertStringContainsString('aria-label="Split button options"', $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\Block\Widget;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
|
||||
/**
|
||||
* Test for the button widget.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ButtonTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $objectManager->get(LayoutInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the block.
|
||||
*
|
||||
* @return Button
|
||||
*/
|
||||
private function createBlock(): Button
|
||||
{
|
||||
/** @var Button $block */
|
||||
$block = $this->layout->createBlock(Button::class, 'button_block');
|
||||
$block->setLayout($this->layout);
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test resulting button HTML.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testToHtml(): void
|
||||
{
|
||||
$block = $this->createBlock();
|
||||
$block->addData(
|
||||
[
|
||||
'type' => 'button',
|
||||
'onclick' => 'console.log("Button pressed!")',
|
||||
'disabled' => false,
|
||||
'title' => 'A button',
|
||||
'label' => 'A button',
|
||||
'class' => 'button',
|
||||
'id' => 'button',
|
||||
'element_name' => 'some-name',
|
||||
'value' => 'Press a button',
|
||||
'data-style' => 'width: 100px',
|
||||
'style' => 'height: 200px'
|
||||
]
|
||||
);
|
||||
|
||||
$html = $block->toHtml();
|
||||
$this->assertStringContainsString('<button ', $html);
|
||||
$this->assertStringContainsString('<span>A button</span>', $html);
|
||||
$this->assertStringNotContainsString('onclick=', $html);
|
||||
$this->assertStringNotContainsString('style=', $html);
|
||||
$this->assertMatchesRegularExpression('/\<script.*?\>.*?' .preg_quote($block->getOnClick()) .'.*?\<\/script\>/ims', $html);
|
||||
$this->assertStringContainsString('height', $html);
|
||||
$this->assertStringContainsString('200px', $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ContainerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testPseudoConstruct()
|
||||
{
|
||||
/** @var $block \Magento\Backend\Block\Widget\Container */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Backend\Block\Widget\Container::class,
|
||||
'',
|
||||
[
|
||||
'data' => [
|
||||
\Magento\Backend\Block\Widget\Container::PARAM_CONTROLLER => 'one',
|
||||
\Magento\Backend\Block\Widget\Container::PARAM_HEADER_TEXT => 'two',
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->assertStringEndsWith('one', $block->getHeaderCssClass());
|
||||
$this->assertStringContainsString('two', $block->getHeaderText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetButtonsHtml()
|
||||
{
|
||||
$titles = [1 => 'Title 1', 'Title 2', 'Title 3'];
|
||||
$block = $this->_buildBlock($titles);
|
||||
$html = $block->getButtonsHtml('header');
|
||||
|
||||
$this->assertStringContainsString('<button', $html);
|
||||
foreach ($titles as $title) {
|
||||
$this->assertStringContainsString($title, $html);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testUpdateButton()
|
||||
{
|
||||
$originalTitles = [1 => 'Title 1', 'Title 2', 'Title 3'];
|
||||
$newTitles = [1 => 'Button A', 'Button B', 'Button C'];
|
||||
|
||||
$block = $this->_buildBlock($originalTitles);
|
||||
foreach ($newTitles as $id => $newTitle) {
|
||||
$block->updateButton($id, 'title', $newTitle);
|
||||
}
|
||||
$html = $block->getButtonsHtml('header');
|
||||
foreach ($newTitles as $newTitle) {
|
||||
$this->assertStringContainsString($newTitle, $html);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes a container with several buttons in it
|
||||
*
|
||||
* @param array $titles
|
||||
* @param string $blockName
|
||||
* @return \Magento\Backend\Block\Widget\Container
|
||||
*/
|
||||
protected function _buildBlock($titles, $blockName = 'block')
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\LayoutInterface */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Backend\Block\Widget\Container */
|
||||
$block = $layout->createBlock(\Magento\Backend\Block\Widget\Container::class, $blockName);
|
||||
foreach ($titles as $id => $title) {
|
||||
$block->addButton($id, ['title' => $title], 0, 0, 'header');
|
||||
}
|
||||
$block->setLayout($layout);
|
||||
return $block;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Form;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ContainerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetFormHtml()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
// Create block with blocking _prepateLayout(), which is used by block to instantly add 'form' child
|
||||
/** @var $block \Magento\Backend\Block\Widget\Form\Container */
|
||||
$block = $this->getMockBuilder(\Magento\Backend\Block\Widget\Form\Container::class)
|
||||
->setMethods(['_prepareLayout'])
|
||||
->setConstructorArgs([$objectManager->create(\Magento\Backend\Block\Widget\Context::class)])
|
||||
->getMock();
|
||||
|
||||
$layout->addBlock($block, 'block');
|
||||
$form = $layout->addBlock(\Magento\Framework\View\Element\Text::class, 'form', 'block');
|
||||
|
||||
$expectedHtml = '<b>html</b>';
|
||||
$this->assertNotEquals($expectedHtml, $block->getFormHtml());
|
||||
$form->setText($expectedHtml);
|
||||
$this->assertEquals($expectedHtml, $block->getFormHtml());
|
||||
}
|
||||
|
||||
public function testPseudoConstruct()
|
||||
{
|
||||
/** @var $block \Magento\Backend\Block\Widget\Form\Container */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Backend\Block\Widget\Form\Container::class,
|
||||
'',
|
||||
[
|
||||
'data' => [
|
||||
\Magento\Backend\Block\Widget\Container::PARAM_CONTROLLER => 'user',
|
||||
\Magento\Backend\Block\Widget\Form\Container::PARAM_MODE => 'edit',
|
||||
\Magento\Backend\Block\Widget\Form\Container::PARAM_BLOCK_GROUP => 'Magento_User'
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->assertInstanceOf(\Magento\User\Block\User\Edit\Form::class, $block->getChildBlock('form'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Block\Widget\Form
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FormTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testSetFieldset()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->setArea(
|
||||
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
|
||||
)->setDefaultDesignTheme();
|
||||
$layout = $objectManager->create(\Magento\Framework\View\Layout::class);
|
||||
$formBlock = $layout->addBlock(\Magento\Backend\Block\Widget\Form::class);
|
||||
$fieldSet = $objectManager->create(\Magento\Framework\Data\Form\Element\Fieldset::class);
|
||||
$arguments = [
|
||||
'data' => [
|
||||
'attribute_code' => 'date',
|
||||
'backend_type' => 'datetime',
|
||||
'frontend_input' => 'date',
|
||||
'frontend_label' => 'Date',
|
||||
],
|
||||
];
|
||||
$attributes = [$objectManager->create(\Magento\Eav\Model\Entity\Attribute::class, $arguments)];
|
||||
$method = new \ReflectionMethod(\Magento\Backend\Block\Widget\Form::class, '_setFieldset');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($formBlock, $attributes, $fieldSet);
|
||||
$fields = $fieldSet->getElements();
|
||||
|
||||
$this->assertCount(1, $fields);
|
||||
$this->assertInstanceOf(\Magento\Framework\Data\Form\Element\Date::class, $fields[0]);
|
||||
$this->assertNotEmpty($fields[0]->getDateFormat());
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
|
||||
|
||||
use Magento\Backend\Block\Widget\Grid\Column;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Phrase;
|
||||
use Magento\Framework\Phrase\RendererInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
class ActionTest 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(Action::class);
|
||||
/** @var Column $column */
|
||||
$column = $this->objectManager->create(
|
||||
Column::class,
|
||||
[
|
||||
'data' => $columnData
|
||||
]
|
||||
);
|
||||
/** @var DataObject $row */
|
||||
$row = $this->objectManager->create(
|
||||
DataObject::class,
|
||||
[
|
||||
'data' => $rowData
|
||||
]
|
||||
);
|
||||
$this->assertStringContainsString(
|
||||
$expected,
|
||||
$renderer->setColumn($column)->render($row)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function renderDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'index' => 'type',
|
||||
'type' => 'action',
|
||||
'actions' => [
|
||||
'rollback_action'=> [
|
||||
'caption' => 'Rollback', 'href'=>'#', 'onclick' => 'alert("test")'
|
||||
]
|
||||
]
|
||||
],
|
||||
[],
|
||||
'alert("test")'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+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,144 @@
|
||||
<?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\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Data\Collection;
|
||||
use Magento\Framework\Filesystem;
|
||||
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()->create(
|
||||
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);
|
||||
}
|
||||
|
||||
public function testGetCsvFileStartsWithBOM(): void
|
||||
{
|
||||
$collection = Bootstrap::getObjectManager()->create(Collection::class);
|
||||
$this->_block->setCollection($collection);
|
||||
$data = $this->_block->getCsvFile();
|
||||
|
||||
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
|
||||
$directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
|
||||
self::assertTrue($directory->isFile($data['value']));
|
||||
self::assertStringStartsWith(
|
||||
pack('CCC', 0xef, 0xbb, 0xbf),
|
||||
$directory->readFile($data['value'])
|
||||
);
|
||||
|
||||
$directory->delete($data['value']);
|
||||
}
|
||||
}
|
||||
@@ -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' => ''
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\Block\Widget;
|
||||
|
||||
use Magento\Backend\Block\Widget\Grid\ColumnSet;
|
||||
use Magento\Backend\Block\Widget\Grid\Extended;
|
||||
use Magento\Backend\Model\Widget\Grid\Row\UrlGeneratorFactory;
|
||||
use Magento\Backend\Model\Widget\Grid\SubTotals;
|
||||
use Magento\Backend\Model\Widget\Grid\Totals;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\Json\Helper\Data;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Layout;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class GridTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ColumnSet
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @var LayoutInterface|MockObject
|
||||
*/
|
||||
private $layoutMock;
|
||||
|
||||
/**
|
||||
* @var ColumnSet|MockObject
|
||||
*/
|
||||
private $columnSetMock;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->layoutMock = $this->getMockBuilder(Layout::class)
|
||||
->disableOriginalConstructor()
|
||||
->disableOriginalClone()
|
||||
->disableArgumentCloning()
|
||||
->disallowMockingUnknownTypes()
|
||||
->onlyMethods(['getChildName', 'getBlock', 'createBlock', 'renameElement', 'unsetChild', 'setChild'])
|
||||
->addMethods(['helper'])
|
||||
->getMock();
|
||||
|
||||
$this->columnSetMock = $this->getColumnSetMock();
|
||||
|
||||
$returnValueMap = [
|
||||
['grid', 'grid.columnSet', 'grid.columnSet'],
|
||||
['grid', 'reset_filter_button', 'reset_filter_button'],
|
||||
['grid', 'search_button', 'search_button'],
|
||||
];
|
||||
$this->layoutMock->expects($this->any())
|
||||
->method('getChildName')
|
||||
->willReturnMap($returnValueMap);
|
||||
|
||||
$this->layoutMock->expects($this->any())
|
||||
->method('getBlock')
|
||||
->with('grid.columnSet')
|
||||
->willReturn($this->columnSetMock);
|
||||
$this->layoutMock->expects($this->any())
|
||||
->method('createBlock')
|
||||
->with(Button::class)
|
||||
->willReturn(Bootstrap::getObjectManager()->get(LayoutInterface::class)->createBlock(Button::class));
|
||||
$this->layoutMock->expects($this->any())
|
||||
->method('helper')->with(Data::class)
|
||||
->willReturn(Bootstrap::getObjectManager()->get(Data::class));
|
||||
|
||||
$this->block = Bootstrap::getObjectManager()
|
||||
->get(LayoutInterface::class)
|
||||
->createBlock(Grid::class);
|
||||
|
||||
$this->block->setLayout($this->layoutMock);
|
||||
$this->block->setNameInLayout('grid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the mocked column set block instance
|
||||
*
|
||||
* @return ColumnSet|MockObject
|
||||
*/
|
||||
private function getColumnSetMock()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$directoryList = $objectManager->create(
|
||||
DirectoryList::class,
|
||||
['root' => __DIR__]
|
||||
);
|
||||
return $this->getMockBuilder(ColumnSet::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
$objectManager->create(
|
||||
\Magento\Framework\View\Element\Template\Context::class,
|
||||
[
|
||||
'filesystem' => $objectManager->create(
|
||||
Filesystem::class,
|
||||
['directoryList' => $directoryList]
|
||||
)
|
||||
]
|
||||
),
|
||||
$objectManager->create(UrlGeneratorFactory::class),
|
||||
$objectManager->create(SubTotals::class),
|
||||
$objectManager->create(Totals::class)
|
||||
]
|
||||
)
|
||||
->getMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testToHtmlPreparesColumns(): void
|
||||
{
|
||||
$this->columnSetMock->expects($this->once())->method('setRendererType');
|
||||
$this->columnSetMock->expects($this->once())->method('setFilterType');
|
||||
$this->columnSetMock->expects($this->once())->method('setSortable');
|
||||
$this->block->setColumnRenderers(['filter' => 'Filter_Class']);
|
||||
$this->block->setColumnFilters(['filter' => 'Filter_Class']);
|
||||
$this->block->setSortable(false);
|
||||
$this->block->toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMainButtonsHtmlReturnsEmptyStringIfFiltersArentVisible(): void
|
||||
{
|
||||
$this->columnSetMock->expects($this->once())->method('isFilterVisible')->willReturn(false);
|
||||
$this->block->getMainButtonsHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMassactionBlock(): void
|
||||
{
|
||||
/** @var $layout Layout */
|
||||
$layout = Bootstrap::getObjectManager()->get(
|
||||
LayoutInterface::class
|
||||
);
|
||||
/** @var $block Grid */
|
||||
$block = $layout->createBlock(Extended::class, 'block');
|
||||
$child = $layout->addBlock(Template::class, 'massaction', 'block');
|
||||
$this->assertSame($child, $block->getMassactionBlock());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class TabsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testAddTab()
|
||||
{
|
||||
/** @var $widgetInstance \Magento\Widget\Model\Widget\Instance */
|
||||
$widgetInstance = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Widget\Model\Widget\Instance::class
|
||||
);
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register('current_widget_instance', $widgetInstance);
|
||||
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Backend\Block\Widget\Tabs */
|
||||
$block = $layout->createBlock(\Magento\Backend\Block\Widget\Tabs::class, 'block');
|
||||
$layout->addBlock(\Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Tab\Main::class, 'child_tab', 'block');
|
||||
$block->addTab('tab_id', 'child_tab');
|
||||
|
||||
$this->assertEquals(['tab_id'], $block->getTabsIds());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user