init
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\Block\Dashboard\Chart;
|
||||
|
||||
use Magento\Backend\ViewModel\ChartsPeriod;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Checks chart periods on Magento dashboard
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class PeriodTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Template */
|
||||
private $block;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->block = $this->layout->createBlock(Template::class);
|
||||
$this->block->setTemplate("Magento_Backend::dashboard/chart/period.phtml");
|
||||
$this->block->setData('view_model', $this->objectManager->get(ChartsPeriod::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testChartPeriodOptions(): void
|
||||
{
|
||||
$html = $this->block->toHtml();
|
||||
$dropDownList = [
|
||||
__('Today'),
|
||||
__('Last 24 Hours'),
|
||||
__('Last 7 Days'),
|
||||
__('Current Month'),
|
||||
__('YTD'),
|
||||
__('2YTD')
|
||||
];
|
||||
foreach ($dropDownList as $item) {
|
||||
$xPath = "//select[@id='dashboard_chart_period']/option[normalize-space(text())='{$item}']";
|
||||
$this->assertEquals(1, Xpath::getElementsCountForXpath($xPath, $html));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Block\Dashboard\Orders;
|
||||
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
|
||||
class GridTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Grid
|
||||
*/
|
||||
private $block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$block = $this->createMock(\Magento\Backend\Block\Dashboard\Orders\Grid::class);
|
||||
$layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
|
||||
$layout->expects($this->atLeastOnce())->method('getChildName')->willReturn('test');
|
||||
$layout->expects($this->atLeastOnce())->method('getBlock')->willReturn($block);
|
||||
$context = $objectManager->create(Context::class, ['layout' => $layout]);
|
||||
|
||||
$this->block = $objectManager->create(Grid::class, ['context' => $context]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
public function testGetPreparedCollection()
|
||||
{
|
||||
$collection = $this->block->getPreparedCollection();
|
||||
foreach ($collection->getItems() as $item) {
|
||||
if ($item->getIncrementId() == '100000001') {
|
||||
$this->assertEquals('firstname lastname', $item->getCustomer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Dashboard\Tab\Products;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap as BootstrapHelper;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Backend\Block\Dashboard\Tab\Products\Viewed as ViewedProductsTabBlock;
|
||||
use Magento\Catalog\Model\ProductRepository;
|
||||
use Magento\Framework\Event\ManagerInterface as EventManager;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class ViewedTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var ProductRepository
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var EventManager
|
||||
*/
|
||||
private $eventManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = BootstrapHelper::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepository::class);
|
||||
$this->eventManager = $this->objectManager->get(EventManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoConfigFixture default/reports/options/enabled 1
|
||||
*/
|
||||
public function testGetPreparedCollectionProductPrice()
|
||||
{
|
||||
/** @var ViewedProductsTabBlock $viewedProductsTabBlock */
|
||||
$viewedProductsTabBlock = $this->layout->createBlock(ViewedProductsTabBlock::class);
|
||||
$product = $this->productRepository->getById(1);
|
||||
$this->eventManager->dispatch('catalog_controller_product_view', ['product' => $product]);
|
||||
|
||||
$collection = $viewedProductsTabBlock->getPreparedCollection();
|
||||
|
||||
$this->assertEquals(
|
||||
10,
|
||||
$collection->getFirstItem()->getDataByKey('price')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block;
|
||||
|
||||
use Magento\Framework\App\State;
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Block\Menu
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class MenuTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Block\Menu $blockMenu
|
||||
*/
|
||||
protected $blockMenu;
|
||||
|
||||
/** @var \Magento\Framework\App\Cache\Type\Config $configCacheType */
|
||||
protected $configCacheType;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $backupRegistrar;
|
||||
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Menu\Config
|
||||
*/
|
||||
private $menuConfig;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->configCacheType = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Cache\Type\Config::class
|
||||
);
|
||||
$this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT);
|
||||
|
||||
$reflection = new \ReflectionClass(\Magento\Framework\Component\ComponentRegistrar::class);
|
||||
$paths = $reflection->getProperty('paths');
|
||||
$paths->setAccessible(true);
|
||||
$this->backupRegistrar = $paths->getValue();
|
||||
$paths->setAccessible(false);
|
||||
|
||||
$this->menuConfig = $this->prepareMenuConfig();
|
||||
|
||||
$this->blockMenu = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Backend\Block\Menu::class,
|
||||
['menuConfig' => $this->menuConfig]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that Admin Navigation Menu elements have correct titles & are located on correct levels
|
||||
*/
|
||||
public function testRenderNavigation()
|
||||
{
|
||||
$menuHtml = $this->blockMenu->renderNavigation($this->menuConfig->getMenu(), 0, 12);
|
||||
$menu = new \SimpleXMLElement($menuHtml);
|
||||
|
||||
$item = $menu->xpath('/ul/li/a/span')[0];
|
||||
$this->assertEquals('System', (string)$item, '"System" item is absent or located on wrong menu level.');
|
||||
|
||||
$item = $menu->xpath('/ul//ul/li/strong/span')[0];
|
||||
$this->assertEquals('Report', (string)$item, '"Report" item is absent or located on wrong menu level.');
|
||||
|
||||
$liTitles = [
|
||||
'Private Sales',
|
||||
'Invite',
|
||||
'Invited Customers',
|
||||
];
|
||||
foreach ($menu->xpath('/ul//ul//ul/li/a/span') as $sortOrder => $item) {
|
||||
if ($sortOrder>2) {
|
||||
break;
|
||||
}
|
||||
$this->assertEquals(
|
||||
$liTitles[$sortOrder],
|
||||
(string)$item,
|
||||
'"' . $liTitles[$sortOrder] . '" item is absent or located on wrong menu level.'
|
||||
);
|
||||
}
|
||||
// test column break if submenu contain more than 12 node
|
||||
$this->assertStringContainsString('<li class="column">', $menuHtml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Backend\Model\Menu\Config
|
||||
*/
|
||||
protected function prepareMenuConfig()
|
||||
{
|
||||
$this->loginAdminUser();
|
||||
|
||||
$componentRegistrar = new \Magento\Framework\Component\ComponentRegistrar();
|
||||
$libraryPath = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework');
|
||||
|
||||
$reflection = new \ReflectionClass(\Magento\Framework\Component\ComponentRegistrar::class);
|
||||
$paths = $reflection->getProperty('paths');
|
||||
$paths->setAccessible(true);
|
||||
|
||||
$paths->setValue(
|
||||
null,
|
||||
[
|
||||
ComponentRegistrar::MODULE => [],
|
||||
ComponentRegistrar::THEME => [],
|
||||
ComponentRegistrar::LANGUAGE => [],
|
||||
ComponentRegistrar::LIBRARY => []
|
||||
]
|
||||
);
|
||||
$paths->setAccessible(false);
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LIBRARY, 'magento/framework', $libraryPath);
|
||||
|
||||
ComponentRegistrar::register(
|
||||
ComponentRegistrar::MODULE,
|
||||
'Magento_Backend',
|
||||
__DIR__ . '/_files/menu/Magento/Backend'
|
||||
);
|
||||
|
||||
/* @var $validationState \Magento\Framework\App\Arguments\ValidationState */
|
||||
$validationState = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Arguments\ValidationState::class,
|
||||
['appMode' => State::MODE_DEFAULT]
|
||||
);
|
||||
|
||||
/* @var $configReader \Magento\Backend\Model\Menu\Config\Reader */
|
||||
$configReader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Backend\Model\Menu\Config\Reader::class,
|
||||
['validationState' => $validationState]
|
||||
);
|
||||
|
||||
return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Backend\Model\Menu\Config::class,
|
||||
[
|
||||
'configReader' => $configReader,
|
||||
'configCacheType' => $this->configCacheType
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function loginAdminUser()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Backend\Model\UrlInterface::class)
|
||||
->turnOffSecretKey();
|
||||
|
||||
$auth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Auth::class);
|
||||
$auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT);
|
||||
$reflection = new \ReflectionClass(\Magento\Framework\Component\ComponentRegistrar::class);
|
||||
$paths = $reflection->getProperty('paths');
|
||||
$paths->setAccessible(true);
|
||||
$paths->setValue(null, $this->backupRegistrar);
|
||||
$paths->setAccessible(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Block\Page;
|
||||
|
||||
/**
|
||||
* Test \Magento\Backend\Block\Page\Footer
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FooterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test Product Version Value
|
||||
*/
|
||||
const TEST_PRODUCT_VERSION = '222.333.444';
|
||||
|
||||
/**
|
||||
* @var \Magento\Backend\Block\Page\Footer
|
||||
*/
|
||||
protected $block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$productMetadataMock = $this->getMockBuilder(\Magento\Framework\App\ProductMetadata::class)
|
||||
->setMethods(['getVersion'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$productMetadataMock->expects($this->once())
|
||||
->method('getVersion')
|
||||
->willReturn($this::TEST_PRODUCT_VERSION);
|
||||
$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Backend\Block\Page\Footer::class,
|
||||
'',
|
||||
['productMetadata' => $productMetadataMock]
|
||||
);
|
||||
}
|
||||
|
||||
public function testToHtml()
|
||||
{
|
||||
$footerContent = $this->block->toHtml();
|
||||
$this->assertStringContainsString(
|
||||
'ver. ' . $this::TEST_PRODUCT_VERSION,
|
||||
$footerContent,
|
||||
'No or wrong product version.'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Page;
|
||||
|
||||
/**
|
||||
* Test \Magento\Backend\Block\Page\Header
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class HeaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Block\Page\Header
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Backend\Block\Page\Header::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetHomeLink()
|
||||
{
|
||||
$expected = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Helper\Data::class
|
||||
)->getHomePageUrl();
|
||||
$this->assertEquals($expected, $this->_block->getHomeLink());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\System\Account\Edit;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FormTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPrepareForm()
|
||||
{
|
||||
$user = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\User\Model\User::class
|
||||
)->loadByUsername(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_NAME
|
||||
);
|
||||
|
||||
/** @var $session \Magento\Backend\Model\Auth\Session */
|
||||
$session = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\Auth\Session::class
|
||||
);
|
||||
$session->setUser($user);
|
||||
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
|
||||
/** @var \Magento\Backend\Block\System\Account\Edit\Form */
|
||||
$block = $layout->createBlock(\Magento\Backend\Block\System\Account\Edit\Form::class);
|
||||
$block->toHtml();
|
||||
|
||||
$form = $block->getForm();
|
||||
|
||||
$this->assertInstanceOf(\Magento\Framework\Data\Form::class, $form);
|
||||
$this->assertEquals('post', $form->getData('method'));
|
||||
$this->assertEquals($block->getUrl('adminhtml/system_account/save'), $form->getData('action'));
|
||||
$this->assertEquals('edit_form', $form->getId());
|
||||
$this->assertTrue($form->getUseContainer());
|
||||
|
||||
$expectedFieldset = [
|
||||
'username' => [
|
||||
'name' => 'username',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'value' => $user->getData('username'),
|
||||
],
|
||||
'firstname' => [
|
||||
'name' => 'firstname',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'value' => $user->getData('firstname'),
|
||||
],
|
||||
'lastname' => [
|
||||
'name' => 'lastname',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'value' => $user->getData('lastname'),
|
||||
],
|
||||
'email' => [
|
||||
'name' => 'email',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'value' => $user->getData('email'),
|
||||
],
|
||||
'password' => ['name' => 'password', 'type' => 'password', 'required' => false],
|
||||
'confirmation' => ['name' => 'password_confirmation', 'type' => 'password', 'required' => false],
|
||||
'interface_locale' => ['name' => 'interface_locale', 'type' => 'select', 'required' => false],
|
||||
];
|
||||
|
||||
foreach ($expectedFieldset as $fieldId => $field) {
|
||||
$element = $form->getElement($fieldId);
|
||||
$this->assertInstanceOf(\Magento\Framework\Data\Form\Element\AbstractElement::class, $element);
|
||||
$this->assertEquals($field['name'], $element->getName(), 'Wrong \'' . $fieldId . '\' field name');
|
||||
$this->assertEquals($field['type'], $element->getType(), 'Wrong \'' . $fieldId . ' field type');
|
||||
$this->assertEquals(
|
||||
$field['required'],
|
||||
$element->getData('required'),
|
||||
'Wrong \'' . $fieldId . '\' requirement state'
|
||||
);
|
||||
if (array_key_exists('value', $field)) {
|
||||
$this->assertEquals($field['value'], $element->getData('value'), 'Wrong \'' . $fieldId . '\' value');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\System\Design\Edit\Tab;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Block\System\Design\Edit\Tab\General
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class GeneralTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testPrepareForm()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->setArea(
|
||||
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
|
||||
)->setDefaultDesignTheme();
|
||||
$objectManager->get(
|
||||
\Magento\Framework\Registry::class
|
||||
)->register(
|
||||
'design',
|
||||
$objectManager->create(\Magento\Framework\App\DesignInterface::class)
|
||||
);
|
||||
$layout = $objectManager->create(\Magento\Framework\View\Layout::class);
|
||||
$block = $layout->addBlock(\Magento\Backend\Block\System\Design\Edit\Tab\General::class);
|
||||
$prepareFormMethod = new \ReflectionMethod(
|
||||
\Magento\Backend\Block\System\Design\Edit\Tab\General::class,
|
||||
'_prepareForm'
|
||||
);
|
||||
$prepareFormMethod->setAccessible(true);
|
||||
$prepareFormMethod->invoke($block);
|
||||
|
||||
$form = $block->getForm();
|
||||
foreach (['date_from', 'date_to'] as $id) {
|
||||
$element = $form->getElement($id);
|
||||
$this->assertNotNull($element);
|
||||
$this->assertNotEmpty($element->getDateFormat());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\System\Store;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DeleteTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetHeaderText()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Backend\Block\System\Store\Delete */
|
||||
$block = $layout->createBlock(\Magento\Backend\Block\System\Store\Delete::class, 'block');
|
||||
|
||||
$dataObject = new \Magento\Framework\DataObject();
|
||||
$form = $block->getChildBlock('form');
|
||||
$form->setDataObject($dataObject);
|
||||
|
||||
$expectedValue = 'header_text_test';
|
||||
$this->assertStringNotContainsString($expectedValue, (string)$block->getHeaderText());
|
||||
|
||||
$dataObject->setName($expectedValue);
|
||||
$this->assertStringContainsString($expectedValue, (string)$block->getHeaderText());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\System\Store\Edit\Form;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class GroupTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Block\System\Store\Edit\Form\Group
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$registryData = [
|
||||
'store_type' => 'group',
|
||||
'store_data' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Store\Model\Store::class
|
||||
),
|
||||
'store_action' => 'add',
|
||||
];
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
foreach ($registryData as $key => $value) {
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register($key, $value);
|
||||
}
|
||||
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = $objectManager->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
|
||||
$this->_block = $layout->createBlock(\Magento\Backend\Block\System\Store\Edit\Form\Group::class);
|
||||
|
||||
$this->_block->toHtml();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_type');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_data');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_action');
|
||||
}
|
||||
|
||||
public function testPrepareForm()
|
||||
{
|
||||
$form = $this->_block->getForm();
|
||||
$this->assertEquals('group_fieldset', $form->getElement('group_fieldset')->getId());
|
||||
$this->assertEquals('group_name', $form->getElement('group_name')->getId());
|
||||
$this->assertEquals('group', $form->getElement('store_type')->getValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\System\Store\Edit\Form;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class StoreTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Block\System\Store\Edit\Form\Store
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$registryData = [
|
||||
'store_type' => 'store',
|
||||
'store_data' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Store\Model\Store::class
|
||||
),
|
||||
'store_action' => 'add',
|
||||
];
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
foreach ($registryData as $key => $value) {
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register($key, $value);
|
||||
}
|
||||
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = $objectManager->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
|
||||
$this->_block = $layout->createBlock(\Magento\Backend\Block\System\Store\Edit\Form\Store::class);
|
||||
|
||||
$this->_block->toHtml();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_type');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_data');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_action');
|
||||
}
|
||||
|
||||
public function testPrepareForm()
|
||||
{
|
||||
$form = $this->_block->getForm();
|
||||
$this->assertEquals('store_fieldset', $form->getElement('store_fieldset')->getId());
|
||||
$this->assertEquals('store_name', $form->getElement('store_name')->getId());
|
||||
$this->assertEquals('store', $form->getElement('store_type')->getValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\System\Store\Edit\Form;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class WebsiteTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Block\System\Store\Edit\Form\Website
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$registryData = [
|
||||
'store_type' => 'website',
|
||||
'store_data' => $objectManager->create(\Magento\Store\Model\Website::class),
|
||||
'store_action' => 'add',
|
||||
];
|
||||
foreach ($registryData as $key => $value) {
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register($key, $value);
|
||||
}
|
||||
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = $objectManager->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
|
||||
$this->_block = $layout->createBlock(\Magento\Backend\Block\System\Store\Edit\Form\Website::class);
|
||||
|
||||
$this->_block->toHtml();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_type');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_data');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_action');
|
||||
}
|
||||
|
||||
public function testPrepareForm()
|
||||
{
|
||||
$form = $this->_block->getForm();
|
||||
$this->assertEquals('website_fieldset', $form->getElement('website_fieldset')->getId());
|
||||
$this->assertEquals('website_name', $form->getElement('website_name')->getId());
|
||||
$this->assertEquals('website', $form->getElement('store_type')->getValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\System\Store;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class EditTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_type');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_data');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('store_action');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $registryData
|
||||
*/
|
||||
protected function _initStoreTypesInRegistry($registryData)
|
||||
{
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
foreach ($registryData as $key => $value) {
|
||||
if ($key == 'store_data') {
|
||||
$value = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create($value);
|
||||
}
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @param $registryData
|
||||
* @param $expected
|
||||
* @dataProvider getStoreTypesForLayout
|
||||
*/
|
||||
public function testStoreTypeFormCreated($registryData, $expected)
|
||||
{
|
||||
$this->_initStoreTypesInRegistry($registryData);
|
||||
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Backend\Block\System\Store\Edit */
|
||||
$block = $layout->createBlock(\Magento\Backend\Block\System\Store\Edit::class, 'block');
|
||||
$block->setArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
|
||||
$this->assertInstanceOf($expected, $block->getChildBlock('form'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStoreTypesForLayout()
|
||||
{
|
||||
return [
|
||||
[
|
||||
['store_type' => 'website', 'store_data' => \Magento\Store\Model\Website::class],
|
||||
\Magento\Backend\Block\System\Store\Edit\Form\Website::class,
|
||||
],
|
||||
[
|
||||
['store_type' => 'group', 'store_data' => \Magento\Store\Model\Store::class],
|
||||
\Magento\Backend\Block\System\Store\Edit\Form\Group::class
|
||||
],
|
||||
[
|
||||
['store_type' => 'store', 'store_data' => \Magento\Store\Model\Store::class],
|
||||
\Magento\Backend\Block\System\Store\Edit\Form\Store::class
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @param $registryData
|
||||
* @param $expected
|
||||
* @dataProvider getStoreDataForBlock
|
||||
*/
|
||||
public function testGetHeaderText($registryData, $expected)
|
||||
{
|
||||
$this->_initStoreTypesInRegistry($registryData);
|
||||
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Backend\Block\System\Store\Edit */
|
||||
$block = $layout->createBlock(\Magento\Backend\Block\System\Store\Edit::class, 'block');
|
||||
$block->setArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
|
||||
$this->assertEquals($expected, $block->getHeaderText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStoreDataForBlock()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'store_type' => 'website',
|
||||
'store_data' => \Magento\Store\Model\Website::class,
|
||||
'store_action' => 'add',
|
||||
],
|
||||
'New Web Site',
|
||||
],
|
||||
[
|
||||
[
|
||||
'store_type' => 'website',
|
||||
'store_data' => \Magento\Store\Model\Website::class,
|
||||
'store_action' => 'edit',
|
||||
],
|
||||
'Edit Web Site'
|
||||
],
|
||||
[
|
||||
['store_type' => 'group', 'store_data' => \Magento\Store\Model\Store::class, 'store_action' => 'add'],
|
||||
'New Store'
|
||||
],
|
||||
[
|
||||
['store_type' => 'group', 'store_data' => \Magento\Store\Model\Store::class, 'store_action' => 'edit'],
|
||||
'Edit Store'
|
||||
],
|
||||
[
|
||||
['store_type' => 'store', 'store_data' => \Magento\Store\Model\Store::class, 'store_action' => 'add'],
|
||||
'New Store View'
|
||||
],
|
||||
[
|
||||
['store_type' => 'store', 'store_data' => \Magento\Store\Model\Store::class, 'store_action' => 'edit'],
|
||||
'Edit Store View'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Block\Template.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class TemplateTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Block\Template
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Backend\Block\Template::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Block\Template::getFormKey
|
||||
*/
|
||||
public function testGetFormKey()
|
||||
{
|
||||
$this->assertGreaterThan(15, strlen($this->_block->getFormKey()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @covers \Magento\Backend\Block\Template::isOutputEnabled
|
||||
* @magentoConfigFixture current_store advanced/modules_disable_output/dummy 1
|
||||
*/
|
||||
public function testIsOutputEnabledTrue()
|
||||
{
|
||||
$this->_block->setData('module_name', 'dummy');
|
||||
$this->assertFalse($this->_block->isOutputEnabled('dummy'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @covers \Magento\Backend\Block\Template::isOutputEnabled
|
||||
* @magentoConfigFixture current_store advanced/modules_disable_output/dummy 0
|
||||
*/
|
||||
public function testIsOutputEnabledFalse()
|
||||
{
|
||||
$this->_block->setData('module_name', 'dummy');
|
||||
$this->assertTrue($this->_block->isOutputEnabled('dummy'));
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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")'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Block\Widget
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class WidgetTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Magento\Backend\Block\Widget::getButtonHtml
|
||||
*/
|
||||
public function testGetButtonHtml()
|
||||
{
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Layout::class,
|
||||
['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE]
|
||||
);
|
||||
$layout->getUpdate()->load();
|
||||
$layout->generateXml()->generateElements();
|
||||
|
||||
$widget = $layout->createBlock(\Magento\Backend\Block\Widget::class);
|
||||
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/\<button.*\>[\s\S]*Button Label[\s\S]*<\/button>'
|
||||
. '.*?\<script.*?\>.*?this\.form\.submit\(\).*?\<\/script\>/is',
|
||||
$widget->getButtonHtml('Button Label', 'this.form.submit()')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Case when two buttons will be created in same parent block
|
||||
*
|
||||
* @covers \Magento\Backend\Block\Widget::getButtonHtml
|
||||
*/
|
||||
public function testGetButtonHtmlForTwoButtonsInOneBlock()
|
||||
{
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Layout::class,
|
||||
['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE]
|
||||
);
|
||||
$layout->getUpdate()->load();
|
||||
$layout->generateXml()->generateElements();
|
||||
|
||||
$widget = $layout->createBlock(\Magento\Backend\Block\Widget::class);
|
||||
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<button.*\>[\s\S]*Button Label[\s\S]*<\/button>'
|
||||
. '.*?\<script.*?\>.*?this\.form\.submit\(\).*?\<\/script\>/ius',
|
||||
$widget->getButtonHtml('Button Label', 'this.form.submit()')
|
||||
);
|
||||
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<button.*\>[\s\S]*Button Label2[\s\S]*<\/button>'
|
||||
. '.*?\<script.*?\>.*?this\.form\.submit\(\).*?\<\/script\>/ius',
|
||||
$widget->getButtonHtml('Button Label2', 'this.form.submit()')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetSuffixId()
|
||||
{
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Backend\Block\Widget::class);
|
||||
$this->assertStringEndsNotWith('_test', $block->getSuffixId('suffix'));
|
||||
$this->assertStringEndsWith('_test', $block->getSuffixId('test'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<block class="Magento\Backend\Block\Widget\Grid" name="admin.test.grid">
|
||||
<arguments>
|
||||
<argument name="dataSource" xsi:type="object">Magento\Framework\Data\Collection</argument>
|
||||
</arguments>
|
||||
<block class="Magento\Backend\Block\Widget\Grid\ColumnSet" as="grid.columnSet" name="admin.test.grid.columnSet">
|
||||
<block class="Magento\Backend\Block\Widget\Grid\Column" as="product_name">
|
||||
<arguments>
|
||||
<argument name="header" xsi:type="string" translate="true">Product name 1</argument>
|
||||
<argument name="id" xsi:type="string">product_name</argument>
|
||||
<argument name="index" xsi:type="string">product_name</argument>
|
||||
<argument name="type" xsi:type="string">text</argument>
|
||||
</arguments>
|
||||
</block>
|
||||
<block class="Magento\Backend\Block\Widget\Grid\Column" as="description">
|
||||
<arguments>
|
||||
<argument name="header" xsi:type="string" translate="true">User Description</argument>
|
||||
<argument name="id" xsi:type="string">description</argument>
|
||||
<argument name="index" xsi:type="string">description</argument>
|
||||
<argument name="type" xsi:type="string">text</argument>
|
||||
</arguments>
|
||||
</block>
|
||||
<block class="Magento\Backend\Block\Widget\Grid\Column" as="qty">
|
||||
<arguments>
|
||||
<argument name="header" xsi:type="string" translate="true">Qty</argument>
|
||||
<argument name="id" xsi:type="string">qty</argument>
|
||||
<argument name="index" xsi:type="string">qty</argument>
|
||||
<argument name="type" xsi:type="string">number</argument>
|
||||
<argument name="width" xsi:type="string">60</argument>
|
||||
</arguments>
|
||||
</block>
|
||||
<block class="Magento\Backend\Block\Widget\Grid\Column" as="added_at">
|
||||
<arguments>
|
||||
<argument name="header" xsi:type="string" translate="true">Date Added</argument>
|
||||
<argument name="id" xsi:type="string">added_at</argument>
|
||||
<argument name="index" xsi:type="string">added_at</argument>
|
||||
<argument name="type" xsi:type="string">date</argument>
|
||||
<argument name="gmtoffset" xsi:type="string">1</argument>
|
||||
</arguments>
|
||||
</block>
|
||||
</block>
|
||||
<block class="Magento\Backend\Block\Widget\Grid\Massaction" as="grid.massaction" name='admin.test.grid.massaction'>
|
||||
<arguments>
|
||||
<argument name="massaction_id_field" xsi:type="string">test_id</argument>
|
||||
<argument name="form_field_name" xsi:type="string">test_id</argument>
|
||||
<argument name="use_select_all" xsi:type="string">1</argument>
|
||||
<argument name="options" xsi:type="array">
|
||||
<item name="option_id1" xsi:type="array">
|
||||
<item name="label" xsi:type="string" translate="true">Option One</item>
|
||||
<item name="url" xsi:type="string">*/*/option1</item>
|
||||
<item name="complete" xsi:type="string" translate="true">Test</item>
|
||||
</item>
|
||||
<item name="option_id2" xsi:type="array">
|
||||
<item name="label" xsi:type="string" translate="true">Option Two</item>
|
||||
<item name="url" xsi:type="string">*/*/option2</item>
|
||||
<item name="confirm" xsi:type="string" translate="true">Are you sure?</item>
|
||||
</item>
|
||||
<item name="option_id3" xsi:type="array">
|
||||
<item name="label" xsi:type="string" translate="true">Option Three</item>
|
||||
<item name="url" xsi:type="string">*/*/option3</item>
|
||||
<item name="visible" xsi:type="object">Magento\Backend\Block\Cache\Grid\Massaction\ProductionModeVisibilityChecker</item>
|
||||
</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
</block>
|
||||
</block>
|
||||
</layout>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::THEME, 'adminhtml/BackendTest/test_default', __DIR__);
|
||||
@@ -0,0 +1,9 @@
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
|
||||
<title>Magento Test backend</title>
|
||||
</theme>
|
||||
|
After Width: | Height: | Size: 105 B |
|
After Width: | Height: | Size: 106 B |
|
After Width: | Height: | Size: 41 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 326 B |
|
After Width: | Height: | Size: 210 B |
|
After Width: | Height: | Size: 324 B |
|
After Width: | Height: | Size: 211 B |
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOffSecretKey();
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOnSecretKey();
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config>
|
||||
<menu>
|
||||
<add id="Magento_Backend::system" title="System" module="Magento_Backend" sortOrder="30" resource="Magento_Backend::system"/>
|
||||
<add id="Magento_Backend::system_report" title="Report" module="Magento_Backend" sortOrder="10" parent="Magento_Backend::system" resource="Magento_Backend::report"/>
|
||||
|
||||
<add id="Magento_Backend::system_report_magento_invite_general" title="Invite" module="Magento_Backend" sortOrder="20" parent="Magento_Backend::system_report" resource="Magento_Backend::report_magento_invite_general"/>
|
||||
<add id="Magento_Backend::system_report_private_sales" title="Private Sales" module="Magento_Backend" sortOrder="10" parent="Magento_Backend::system_report" resource="Magento_Backend::report_private_sales" />
|
||||
<add id="Magento_Backend::system_report_magento_invite_customer" title="Invited Customers" module="Magento_Backend" sortOrder="30" parent="Magento_Backend::system_report" resource="Magento_Backend::report_magento_invite_customer"/>
|
||||
<add id="Magento_Cms::test1" title="Test 1"
|
||||
translate="title" module="Magento_Cms" sortOrder="100"
|
||||
action="test/test/test"
|
||||
parent="Magento_Backend::system" resource="Magento_Cms::page"/>
|
||||
<add id="Magento_Cms::test2" title="Test 2"
|
||||
translate="title" module="Magento_Cms" sortOrder="100"
|
||||
action="test/test/test"
|
||||
parent="Magento_Backend::system" resource="Magento_Cms::page"/>
|
||||
<add id="Magento_Cms::test3" title="Test 3"
|
||||
translate="title" module="Magento_Cms" sortOrder="100"
|
||||
action="test/test/test"
|
||||
parent="Magento_Backend::system" resource="Magento_Cms::page"/>
|
||||
<add id="Magento_Cms::test4" title="Test 4"
|
||||
translate="title" module="Magento_Cms" sortOrder="100"
|
||||
action="test/test/test"
|
||||
parent="Magento_Backend::system" resource="Magento_Cms::page"/>
|
||||
<add id="Magento_Cms::test5" title="Test 5"
|
||||
translate="title" module="Magento_Cms" sortOrder="100"
|
||||
action="test/test/test"
|
||||
parent="Magento_Backend::system" resource="Magento_Cms::page"/>
|
||||
<add id="Magento_Cms::test6" title="Test 6"
|
||||
translate="title" module="Magento_Cms" sortOrder="100"
|
||||
action="test/test/test"
|
||||
parent="Magento_Backend::system" resource="Magento_Cms::page"/>
|
||||
<add id="Magento_Cms::test7" title="Test 7"
|
||||
translate="title" module="Magento_Cms" sortOrder="100"
|
||||
action="test/test/test"
|
||||
parent="Magento_Backend::system" resource="Magento_Cms::page"/>
|
||||
<add id="Magento_Cms::test8" title="Test 8"
|
||||
translate="title" module="Magento_Cms" sortOrder="100"
|
||||
action="test/test/test"
|
||||
parent="Magento_Backend::system" resource="Magento_Cms::page"/>
|
||||
<add id="Magento_Cms::test9" title="Test 9"
|
||||
translate="title" module="Magento_Cms" sortOrder="100"
|
||||
action="test/test/test"
|
||||
parent="Magento_Backend::system" resource="Magento_Cms::page"/>
|
||||
</menu>
|
||||
</config>
|
||||