ltsecurityinc安防产品在线商城代码
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\App;
|
||||
|
||||
use Magento\TestFramework\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\App\AbstractAction.
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class AbstractActionTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Check redirection to startup page for logged user
|
||||
* @magentoConfigFixture current_store admin/security/use_form_key 1
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testPreDispatchWithEmptyUrlRedirectsToStartupPage()
|
||||
{
|
||||
$this->markTestSkipped('Session destruction doesn\'t work');
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Config\ScopeInterface::class
|
||||
)->setCurrentScope(
|
||||
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
|
||||
);
|
||||
$this->dispatch('backend');
|
||||
/** @var $backendUrlModel \Magento\Backend\Model\UrlInterface */
|
||||
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
);
|
||||
$url = $backendUrlModel->getStartupPageUrl();
|
||||
$expected = $backendUrlModel->getUrl($url);
|
||||
$this->assertRedirect($this->stringStartsWith($expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check login redirection
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testInitAuthentication()
|
||||
{
|
||||
/**
|
||||
* Logout current session
|
||||
*/
|
||||
$this->_auth->logout();
|
||||
|
||||
/** @var \Magento\Framework\Data\Form\FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
|
||||
$postLogin = [
|
||||
'login' => [
|
||||
'username' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
|
||||
],
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
];
|
||||
|
||||
$this->getRequest()->setPostValue($postLogin);
|
||||
$this->dispatch('backend/admin/system_account/index');
|
||||
|
||||
$expected = 'backend/admin/system_account/index';
|
||||
$this->assertRedirect($this->stringContains($expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check layout attribute "acl" for check access to
|
||||
*
|
||||
* @param string $blockName
|
||||
* @param string $resource
|
||||
* @param bool $isLimitedAccess
|
||||
* @dataProvider nodesWithAcl
|
||||
*/
|
||||
public function testAclInNodes($blockName, $resource, $isLimitedAccess)
|
||||
{
|
||||
/** @var $noticeInbox \Magento\AdminNotification\Model\Inbox */
|
||||
$noticeInbox = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\AdminNotification\Model\Inbox::class
|
||||
);
|
||||
if (!$noticeInbox->loadLatestNotice()->getId()) {
|
||||
$noticeInbox->addCritical('Test notice', 'Test description');
|
||||
}
|
||||
|
||||
$this->_auth->login(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
|
||||
/** @var $acl \Magento\Framework\Acl */
|
||||
$acl = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\Acl\Builder::class)
|
||||
->getAcl();
|
||||
if ($isLimitedAccess) {
|
||||
$acl->deny(Bootstrap::ADMIN_ROLE_ID, $resource);
|
||||
}
|
||||
|
||||
$this->dispatch('backend/admin/dashboard');
|
||||
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
$actualBlocks = $layout->getAllBlocks();
|
||||
|
||||
$this->assertNotEmpty($actualBlocks);
|
||||
if ($isLimitedAccess) {
|
||||
$this->assertNotContains($blockName, array_keys($actualBlocks));
|
||||
} else {
|
||||
$this->assertContains($blockName, array_keys($actualBlocks));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider with expected blocks with acl properties
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function nodesWithAcl()
|
||||
{
|
||||
return [
|
||||
['notification_window', 'Magento_AdminNotification::show_toolbar', true],
|
||||
['notification_window', 'Magento_AdminNotification::show_toolbar', false]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\App\Area;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FrontNameResolverTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var FrontNameResolver
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->model = $this->objectManager->create(
|
||||
FrontNameResolver::class
|
||||
);
|
||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoConfigFixture current_store web/unsecure/base_url http://example.com/
|
||||
*/
|
||||
public function testIsHostBackend()
|
||||
{
|
||||
$this->assertTrue($this->model->isHostBackend());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,435 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\App\Request;
|
||||
|
||||
use Magento\Backend\App\AbstractAction;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\Auth;
|
||||
use Magento\Framework\App\ActionInterface;
|
||||
use Magento\Framework\App\CsrfAwareActionInterface;
|
||||
use Magento\Framework\App\Request\InvalidRequestException;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Exception\NotFoundException;
|
||||
use Magento\Framework\Phrase;
|
||||
use Magento\TestFramework\Request;
|
||||
use Magento\TestFramework\Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Bootstrap as TestBootstrap;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\App\Response\Http as HttpResponse;
|
||||
use Laminas\Stdlib\Parameters;
|
||||
use Magento\Backend\Model\UrlInterface as BackendUrl;
|
||||
use Magento\Framework\App\Response\HttpFactory as HttpResponseFactory;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class BackendValidatorTest extends TestCase
|
||||
{
|
||||
private const AWARE_VALIDATION_PARAM = 'test_param';
|
||||
|
||||
private const AWARE_LOCATION_VALUE = 'test1';
|
||||
|
||||
private const CSRF_AWARE_MESSAGE = 'csrf_aware';
|
||||
|
||||
/**
|
||||
* @var ActionInterface
|
||||
*/
|
||||
private $mockUnawareAction;
|
||||
|
||||
/**
|
||||
* @var AbstractAction
|
||||
*/
|
||||
private $mockAwareAction;
|
||||
|
||||
/**
|
||||
* @var BackendValidator
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var FormKey
|
||||
*/
|
||||
private $formKey;
|
||||
|
||||
/**
|
||||
* @var BackendUrl
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var Auth
|
||||
*/
|
||||
private $auth;
|
||||
|
||||
/**
|
||||
* @var CsrfAwareActionInterface
|
||||
*/
|
||||
private $mockCsrfAwareAction;
|
||||
|
||||
/**
|
||||
* @var HttpResponseFactory
|
||||
*/
|
||||
private $httpResponseFactory;
|
||||
|
||||
/**
|
||||
* @return ActionInterface
|
||||
*/
|
||||
private function createUnawareAction(): ActionInterface
|
||||
{
|
||||
return new class implements ActionInterface {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
throw new NotFoundException(new Phrase('Not implemented'));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AbstractAction
|
||||
*/
|
||||
private function createAwareAction(): AbstractAction
|
||||
{
|
||||
$l = self::AWARE_LOCATION_VALUE;
|
||||
$p = self::AWARE_VALIDATION_PARAM;
|
||||
|
||||
return new class($l, $p) extends AbstractAction{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $locationValue;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $param;
|
||||
|
||||
/**
|
||||
* @param string $locationValue
|
||||
* @param string $param
|
||||
*/
|
||||
public function __construct(
|
||||
string $locationValue,
|
||||
string $param
|
||||
) {
|
||||
parent::__construct(
|
||||
Bootstrap::getObjectManager()->get(Context::class)
|
||||
);
|
||||
$this->locationValue= $locationValue;
|
||||
$this->param = $param;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
throw new NotFoundException(new Phrase('Not implemented'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _processUrlKeys()
|
||||
{
|
||||
if ($this->_request->getParam($this->param)) {
|
||||
return true;
|
||||
} else {
|
||||
/** @var Response $response */
|
||||
$response = $this->_response;
|
||||
$response->setHeader('Location', $this->locationValue);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CsrfAwareActionInterface
|
||||
*/
|
||||
private function createCsrfAwareAction(): CsrfAwareActionInterface
|
||||
{
|
||||
$r = Bootstrap::getObjectManager()
|
||||
->get(ResponseInterface::class);
|
||||
$m = self::CSRF_AWARE_MESSAGE;
|
||||
|
||||
return new class ($r, $m) implements CsrfAwareActionInterface {
|
||||
|
||||
/**
|
||||
* @var ResponseInterface
|
||||
*/
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* @param ResponseInterface $response
|
||||
* @param string $message
|
||||
*/
|
||||
public function __construct(
|
||||
ResponseInterface $response,
|
||||
string $message
|
||||
) {
|
||||
$this->response = $response;
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createCsrfValidationException(
|
||||
RequestInterface $request
|
||||
): ?InvalidRequestException {
|
||||
return new InvalidRequestException(
|
||||
$this->response,
|
||||
[new Phrase($this->message)]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function validateForCsrf(RequestInterface $request): ?bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->request = $objectManager->get(RequestInterface::class);
|
||||
$this->validator = $objectManager->get(BackendValidator::class);
|
||||
$this->mockUnawareAction = $this->createUnawareAction();
|
||||
$this->mockAwareAction = $this->createAwareAction();
|
||||
$this->formKey = $objectManager->get(FormKey::class);
|
||||
$this->url = $objectManager->get(BackendUrl::class);
|
||||
$this->auth = $objectManager->get(Auth::class);
|
||||
$this->mockCsrfAwareAction = $this->createCsrfAwareAction();
|
||||
$this->httpResponseFactory = $objectManager->get(
|
||||
HttpResponseFactory::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture admin/security/use_form_key 1
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testValidateWithValidKey()
|
||||
{
|
||||
$this->request->setMethod(HttpRequest::METHOD_GET);
|
||||
$this->auth->login(
|
||||
TestBootstrap::ADMIN_NAME,
|
||||
TestBootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
$this->request->setParams([
|
||||
BackendUrl::SECRET_KEY_PARAM_NAME => $this->url->getSecretKey(),
|
||||
]);
|
||||
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockUnawareAction
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @magentoConfigFixture admin/security/use_form_key 1
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testValidateWithInvalidKey()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\App\Request\InvalidRequestException::class);
|
||||
|
||||
$invalidKey = $this->url->getSecretKey() .'Invalid';
|
||||
$this->request->setParams([
|
||||
BackendUrl::SECRET_KEY_PARAM_NAME => $invalidKey,
|
||||
]);
|
||||
$this->request->setMethod(HttpRequest::METHOD_GET);
|
||||
$this->auth->login(
|
||||
TestBootstrap::ADMIN_NAME,
|
||||
TestBootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockUnawareAction
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @magentoConfigFixture admin/security/use_form_key 0
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testValidateWithInvalidFormKey()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\App\Request\InvalidRequestException::class);
|
||||
|
||||
$this->request->setPost(
|
||||
new Parameters(['form_key' => $this->formKey->getFormKey() .'1'])
|
||||
);
|
||||
$this->request->setMethod(HttpRequest::METHOD_POST);
|
||||
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockUnawareAction
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture admin/security/use_form_key 0
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testValidateInvalidWithAwareAction()
|
||||
{
|
||||
$this->request->setParams([self::AWARE_VALIDATION_PARAM => '']);
|
||||
|
||||
/** @var InvalidRequestException|null $caught */
|
||||
$caught = null;
|
||||
try {
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockAwareAction
|
||||
);
|
||||
} catch (InvalidRequestException $exception) {
|
||||
$caught = $exception;
|
||||
}
|
||||
|
||||
$this->assertNotNull($caught);
|
||||
/** @var Response $response */
|
||||
$response = $caught->getReplaceResult();
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
$this->assertEquals(
|
||||
self::AWARE_LOCATION_VALUE,
|
||||
$response->getHeader('Location')->getFieldValue()
|
||||
);
|
||||
$this->assertNull($caught->getMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testValidateValidWithAwareAction()
|
||||
{
|
||||
$this->request->setParams(
|
||||
[self::AWARE_VALIDATION_PARAM => '1']
|
||||
);
|
||||
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockAwareAction
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture admin/security/use_form_key 1
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testValidateWithCsrfAwareAction()
|
||||
{
|
||||
//Setting up request that would be valid for default validation.
|
||||
$this->request->setMethod(HttpRequest::METHOD_GET);
|
||||
$this->auth->login(
|
||||
TestBootstrap::ADMIN_NAME,
|
||||
TestBootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
$this->request->setParams([
|
||||
BackendUrl::SECRET_KEY_PARAM_NAME => $this->url->getSecretKey(),
|
||||
]);
|
||||
|
||||
/** @var InvalidRequestException|null $caught */
|
||||
$caught = null;
|
||||
try {
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockCsrfAwareAction
|
||||
);
|
||||
} catch (InvalidRequestException $exception) {
|
||||
$caught = $exception;
|
||||
}
|
||||
|
||||
//Checking that custom validation was called and invalidated
|
||||
//valid request.
|
||||
$this->assertNotNull($caught);
|
||||
$this->assertCount(1, $caught->getMessages());
|
||||
$this->assertEquals(
|
||||
self::CSRF_AWARE_MESSAGE,
|
||||
$caught->getMessages()[0]->getText()
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidAjaxRequest()
|
||||
{
|
||||
//Setting up AJAX request with invalid secret key.
|
||||
$this->request->setMethod(HttpRequest::METHOD_GET);
|
||||
$this->auth->login(
|
||||
TestBootstrap::ADMIN_NAME,
|
||||
TestBootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
$this->request->setParams([
|
||||
BackendUrl::SECRET_KEY_PARAM_NAME => 'invalid',
|
||||
'isAjax' => '1'
|
||||
]);
|
||||
|
||||
/** @var InvalidRequestException|null $caught */
|
||||
$caught = null;
|
||||
try {
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockUnawareAction
|
||||
);
|
||||
} catch (InvalidRequestException $exception) {
|
||||
$caught = $exception;
|
||||
}
|
||||
|
||||
$this->assertNotNull($caught);
|
||||
$this->assertInstanceOf(
|
||||
ResultInterface::class,
|
||||
$caught->getReplaceResult()
|
||||
);
|
||||
/** @var ResultInterface $result */
|
||||
$result = $caught->getReplaceResult();
|
||||
/** @var HttpResponse $response */
|
||||
$response = $this->httpResponseFactory->create();
|
||||
$result->renderResult($response);
|
||||
$this->assertEmpty($response->getBody());
|
||||
$this->assertEquals(401, $response->getHttpResponseCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\App;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class RouterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\App\Router
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->model = $this->objectManager->create(\Magento\Backend\App\Router::class);
|
||||
}
|
||||
|
||||
public function testRouterCanProcessRequestsWithProperPathInfo()
|
||||
{
|
||||
$request = $this->createMock(\Magento\Framework\App\Request\Http::class);
|
||||
$request->expects($this->once())->method('getPathInfo')->willReturn('backend/admin/dashboard');
|
||||
|
||||
$this->assertInstanceOf(\Magento\Backend\Controller\Adminhtml\Dashboard::class, $this->model->match($request));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $module
|
||||
* @param string $controller
|
||||
* @param string $className
|
||||
*
|
||||
* @dataProvider getControllerClassNameDataProvider
|
||||
*/
|
||||
public function testGetControllerClassName($module, $controller, $className)
|
||||
{
|
||||
$this->assertEquals($className, $this->model->getActionClassName($module, $controller));
|
||||
}
|
||||
|
||||
public function getControllerClassNameDataProvider()
|
||||
{
|
||||
return [
|
||||
['Magento_TestModule', 'controller', \Magento\TestModule\Controller\Adminhtml\Controller::class],
|
||||
];
|
||||
}
|
||||
|
||||
public function testMatchCustomNoRouteAction()
|
||||
{
|
||||
if (!\Magento\TestFramework\Helper\Bootstrap::canTestHeaders()) {
|
||||
$this->markTestSkipped('Can\'t test get match without sending headers');
|
||||
}
|
||||
|
||||
$routers = [
|
||||
'testmodule' => [
|
||||
'frontName' => 'testfixture',
|
||||
'id' => 'testfixture',
|
||||
'modules' => ['Magento_TestFixture'],
|
||||
],
|
||||
];
|
||||
|
||||
$routeConfig = $this->getMockBuilder(\Magento\Framework\App\Route\Config::class)
|
||||
->setMethods(['_getRoutes'])
|
||||
->setConstructorArgs(
|
||||
[
|
||||
'reader' => $this->objectManager->get(\Magento\Framework\App\Route\Config\Reader::class),
|
||||
'cache' => $this->objectManager->get(\Magento\Framework\Config\CacheInterface::class),
|
||||
'configScope' => $this->objectManager->get(\Magento\Framework\Config\ScopeInterface::class),
|
||||
'areaList' => $this->objectManager->get(\Magento\Framework\App\AreaList::class),
|
||||
'cacheId' => 'RoutesConfig'
|
||||
]
|
||||
)
|
||||
->getMock();
|
||||
|
||||
$routeConfig->expects($this->any())->method('_getRoutes')->willReturn($routers);
|
||||
|
||||
$defaultRouter = $this->objectManager->create(
|
||||
\Magento\Backend\App\Router::class,
|
||||
['routeConfig' => $routeConfig]
|
||||
);
|
||||
|
||||
/** @var $request \Magento\TestFramework\Request */
|
||||
$request = $this->objectManager->get(\Magento\TestFramework\Request::class);
|
||||
|
||||
$request->setPathInfo('backend/testfixture/test_controller');
|
||||
$controller = $defaultRouter->match($request);
|
||||
$this->assertInstanceOf(\Magento\TestFixture\Controller\Adminhtml\Noroute::class, $controller);
|
||||
$this->assertEquals('noroute', $request->getActionName());
|
||||
}
|
||||
}
|
||||
@@ -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,163 @@
|
||||
<?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());
|
||||
$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) {
|
||||
$this->assertEquals(
|
||||
$liTitles[$sortOrder],
|
||||
(string)$item,
|
||||
'"' . $liTitles[$sortOrder] . '" item is absent or located on wrong menu level.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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(
|
||||
[
|
||||
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($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,142 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\Backend\Block\Widget\Grid\Column;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Phrase;
|
||||
use Magento\Framework\Phrase\RendererInterface;
|
||||
|
||||
class TextTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var RendererInterface
|
||||
*/
|
||||
private $origRenderer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->origRenderer = Phrase::getRenderer();
|
||||
/** @var RendererInterface|PHPUnit\Framework\MockObject_MockObject $rendererMock */
|
||||
$rendererMock = $this->getMockForAbstractClass(RendererInterface::class);
|
||||
$rendererMock->expects($this->any())
|
||||
->method('render')
|
||||
->willReturnCallback(
|
||||
function ($input) {
|
||||
return end($input) . ' translated';
|
||||
}
|
||||
);
|
||||
Phrase::setRenderer($rendererMock);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Phrase::setRenderer($this->origRenderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columnData
|
||||
* @param array $rowData
|
||||
* @param string $expected
|
||||
* @dataProvider renderDataProvider
|
||||
*/
|
||||
public function testRender($columnData, $rowData, $expected)
|
||||
{
|
||||
/** @var Text $renderer */
|
||||
$renderer = $this->objectManager->create(Text::class);
|
||||
/** @var Column $column */
|
||||
$column = $this->objectManager->create(
|
||||
Column::class,
|
||||
[
|
||||
'data' => $columnData
|
||||
]
|
||||
);
|
||||
/** @var DataObject $row */
|
||||
$row = $this->objectManager->create(
|
||||
DataObject::class,
|
||||
[
|
||||
'data' => $rowData
|
||||
]
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$renderer->setColumn($column)->render($row)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function renderDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'index' => 'title',
|
||||
'translate' => true
|
||||
],
|
||||
[
|
||||
'title' => 'String'
|
||||
],
|
||||
'String translated'
|
||||
],
|
||||
[
|
||||
[
|
||||
'index' => 'title'
|
||||
],
|
||||
[
|
||||
'title' => 'Doesn\'t need to be translated'
|
||||
],
|
||||
'Doesn't need to be translated'
|
||||
],
|
||||
[
|
||||
[
|
||||
'format' => '#$subscriber_id $customer_name ($subscriber_email)'
|
||||
],
|
||||
[
|
||||
'subscriber_id' => '10',
|
||||
'customer_name' => 'John Doe',
|
||||
'subscriber_email' => 'john@doe.com'
|
||||
],
|
||||
'#10 John Doe (john@doe.com)'
|
||||
],
|
||||
[
|
||||
[
|
||||
'format' => '$customer_name, email: $subscriber_email',
|
||||
'translate' => true
|
||||
],
|
||||
[
|
||||
'customer_name' => 'John Doe',
|
||||
'subscriber_email' => 'john@doe.com'
|
||||
],
|
||||
'John Doe, email: john@doe.com translated'
|
||||
],
|
||||
[
|
||||
[
|
||||
'format' => 'String',
|
||||
'translate' => true
|
||||
],
|
||||
[],
|
||||
'String translated'
|
||||
],
|
||||
[
|
||||
[
|
||||
'format' => 'Doesn\'t need to be translated'
|
||||
],
|
||||
[],
|
||||
'Doesn't need to be translated'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ColumnSetTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Block\Widget\Grid\ColumnSet
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_layoutMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_columnMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_columnMock = $this->createPartialMock(
|
||||
\Magento\Backend\Block\Widget\Grid\Column::class,
|
||||
['setSortable', 'setRendererType', 'setFilterType', 'addHeaderCssClass', 'setGrid']
|
||||
);
|
||||
$this->_layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
|
||||
$this->_layoutMock->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'getChildBlocks'
|
||||
)->willReturn(
|
||||
[$this->_columnMock]
|
||||
);
|
||||
|
||||
$context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Element\Template\Context::class,
|
||||
['layout' => $this->_layoutMock]
|
||||
);
|
||||
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Backend\Block\Widget\Grid\ColumnSet::class,
|
||||
'',
|
||||
['context' => $context]
|
||||
);
|
||||
$this->_block->setTemplate(null);
|
||||
}
|
||||
|
||||
public function testBeforeToHtmlAddsClassToLastColumn()
|
||||
{
|
||||
$this->_columnMock->expects($this->any())->method('addHeaderCssClass')->with($this->equalTo('last'));
|
||||
$this->_block->toHtml();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ContainerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPseudoConstruct()
|
||||
{
|
||||
/** @var $block \Magento\Backend\Block\Widget\Grid\Container */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Backend\Block\Widget\Grid\Container::class,
|
||||
'',
|
||||
[
|
||||
'data' => [
|
||||
\Magento\Backend\Block\Widget\Container::PARAM_CONTROLLER => 'widget',
|
||||
\Magento\Backend\Block\Widget\Container::PARAM_HEADER_TEXT => 'two',
|
||||
\Magento\Backend\Block\Widget\Grid\Container::PARAM_BLOCK_GROUP => 'Magento_Backend',
|
||||
\Magento\Backend\Block\Widget\Grid\Container::PARAM_BUTTON_NEW => 'four',
|
||||
\Magento\Backend\Block\Widget\Grid\Container::PARAM_BUTTON_BACK => 'five',
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->assertStringEndsWith('widget', $block->getHeaderCssClass());
|
||||
$this->assertStringContainsString('two', $block->getHeaderText());
|
||||
$this->assertInstanceOf(\Magento\Backend\Block\Widget\Grid::class, $block->getChildBlock('grid'));
|
||||
$this->assertEquals('four', $block->getAddButtonLabel());
|
||||
$this->assertEquals('five', $block->getBackButtonLabel());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid;
|
||||
|
||||
use Laminas\Stdlib\Parameters;
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
use Magento\Framework\Data\Collection;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ExtendedTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Extended
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
protected $_layoutMock;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_layoutMock = Bootstrap::getObjectManager()->get(
|
||||
LayoutInterface::class
|
||||
);
|
||||
$context = Bootstrap::getObjectManager()->create(
|
||||
Context::class,
|
||||
['layout' => $this->_layoutMock]
|
||||
);
|
||||
$this->_block = $this->_layoutMock->createBlock(
|
||||
Extended::class,
|
||||
'grid',
|
||||
['context' => $context]
|
||||
);
|
||||
|
||||
$this->_block->addColumn('column1', ['id' => 'columnId1']);
|
||||
$this->_block->addColumn('column2', ['id' => 'columnId2']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testAddColumnAddsChildToColumnSet()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Column::class,
|
||||
$this->_block->getColumnSet()->getChildBlock('column1')
|
||||
);
|
||||
$this->assertCount(2, $this->_block->getColumnSet()->getChildNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testRemoveColumn()
|
||||
{
|
||||
$this->assertCount(2, $this->_block->getColumnSet()->getChildNames());
|
||||
$this->_block->removeColumn('column1');
|
||||
$this->assertCount(1, $this->_block->getColumnSet()->getChildNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testSortColumnsByOrder()
|
||||
{
|
||||
$columnNames = $this->_block->getLayout()->getChildNames($this->_block->getColumnSet()->getNameInLayout());
|
||||
$this->assertEquals($this->_block->getColumn('column1')->getNameInLayout(), $columnNames[0]);
|
||||
$this->_block->addColumnsOrder('column1', 'column2');
|
||||
$this->_block->sortColumnsByOrder();
|
||||
$columnNames = $this->_block->getLayout()->getChildNames($this->_block->getColumnSet()->getNameInLayout());
|
||||
$this->assertEquals($this->_block->getColumn('column2')->getNameInLayout(), $columnNames[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetMainButtonsHtmlReturnsEmptyStringIfFiltersArentVisible()
|
||||
{
|
||||
$this->_block->setFilterVisibility(false);
|
||||
$this->assertEquals('', $this->_block->getMainButtonsHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that template does not have redundant div close tag
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExtendedTemplateMarkup(): void
|
||||
{
|
||||
$mockCollection = $this->getMockBuilder(Collection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->_block->setCollection($mockCollection);
|
||||
$this->_block->getRequest()
|
||||
->setQuery(
|
||||
Bootstrap::getObjectManager()
|
||||
->create(
|
||||
Parameters::class,
|
||||
[
|
||||
'values' => [
|
||||
'ajax' => true
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
$html = $this->_block->getHtml();
|
||||
$html = str_replace(["\n", " "], '', $html);
|
||||
$this->assertStringEndsWith("</table></div>", $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Widget\Grid;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ItemTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetAdditionalActionBlock()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Backend\Block\Widget\Grid\Massaction\Item */
|
||||
$block = $layout->createBlock(\Magento\Backend\Block\Widget\Grid\Massaction\Item::class, 'block');
|
||||
$expected = $layout->addBlock(\Magento\Framework\View\Element\Template::class, 'additional_action', 'block');
|
||||
$this->assertSame($expected, $block->getAdditionalActionBlock());
|
||||
}
|
||||
}
|
||||
@@ -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,17 @@
|
||||
<?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"/>
|
||||
</menu>
|
||||
</config>
|
||||
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Controller\Adminhtml;
|
||||
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Controller\Adminhtml\Auth
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class AuthTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Auth\Session
|
||||
*/
|
||||
protected $_session;
|
||||
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Auth
|
||||
*/
|
||||
protected $_auth;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_session = null;
|
||||
$this->_auth = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs user login
|
||||
*/
|
||||
protected function _login()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOffSecretKey();
|
||||
|
||||
$this->_auth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\Auth::class
|
||||
);
|
||||
$this->_auth->login(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
$this->_session = $this->_auth->getAuthStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs user logout
|
||||
*/
|
||||
protected function _logout()
|
||||
{
|
||||
$this->_auth->logout();
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOnSecretKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check not logged state
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Auth\Login::execute
|
||||
*/
|
||||
public function testNotLoggedLoginAction()
|
||||
{
|
||||
$this->dispatch('backend/admin/auth/login');
|
||||
/** @var $backendUrlModel \Magento\Backend\Model\UrlInterface */
|
||||
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
);
|
||||
$backendUrlModel->turnOffSecretKey();
|
||||
$url = $backendUrlModel->getUrl('admin');
|
||||
$this->assertRedirect($this->stringStartsWith($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check logged state
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Auth\Login::execute
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testLoggedLoginAction()
|
||||
{
|
||||
$this->_login();
|
||||
|
||||
$this->dispatch('backend/admin/auth/login');
|
||||
/** @var $backendUrlModel \Magento\Backend\Model\UrlInterface */
|
||||
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
);
|
||||
$url = $backendUrlModel->getStartupPageUrl();
|
||||
$expected = $backendUrlModel->getUrl($url);
|
||||
$this->assertRedirect($this->stringStartsWith($expected));
|
||||
|
||||
$this->_logout();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testNotLoggedLoginActionWithRedirect()
|
||||
{
|
||||
/** @var \Magento\Framework\Data\Form\FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
|
||||
$this->getRequest()->setPostValue(
|
||||
[
|
||||
'login' => [
|
||||
'username' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
|
||||
],
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
]
|
||||
);
|
||||
|
||||
$this->dispatch('backend/admin/index/index');
|
||||
|
||||
$response = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\App\ResponseInterface::class);
|
||||
$code = $response->getHttpResponseCode();
|
||||
$this->assertTrue($code >= 300 && $code < 400, 'Incorrect response code');
|
||||
|
||||
$this->assertTrue(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\Auth::class
|
||||
)->isLoggedIn()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Auth\Logout::execute
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testLogoutAction()
|
||||
{
|
||||
$this->_login();
|
||||
$this->dispatch('backend/admin/auth/logout');
|
||||
$this->assertRedirect(
|
||||
$this->equalTo(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Helper\Data::class
|
||||
)->getHomePageUrl()
|
||||
)
|
||||
);
|
||||
$this->assertFalse($this->_session->isLoggedIn(), 'User is not logged out.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Auth\DeniedJson::execute
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Auth\DeniedJson::_getDeniedJson
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testDeniedJsonAction()
|
||||
{
|
||||
$this->_login();
|
||||
$this->dispatch('backend/admin/auth/deniedJson');
|
||||
$data = [
|
||||
'ajaxExpired' => 1,
|
||||
'ajaxRedirect' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Helper\Data::class
|
||||
)->getHomePageUrl(),
|
||||
];
|
||||
$expected = json_encode($data);
|
||||
$this->assertEquals($expected, $this->getResponse()->getBody());
|
||||
$this->_logout();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Auth\DeniedIframe::execute
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Auth\DeniedIframe::_getDeniedIframe
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testDeniedIframeAction()
|
||||
{
|
||||
$this->_login();
|
||||
$this->dispatch('backend/admin/auth/deniedIframe');
|
||||
$homeUrl = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Helper\Data::class
|
||||
)->getHomePageUrl();
|
||||
$expected = '<script>parent.window.location =';
|
||||
$this->assertStringStartsWith($expected, $this->getResponse()->getBody());
|
||||
$this->assertStringContainsString($homeUrl, $this->getResponse()->getBody());
|
||||
$this->_logout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user logging process when user not assigned to any role
|
||||
* @dataProvider incorrectLoginDataProvider
|
||||
* @magentoDbIsolation enabled
|
||||
*
|
||||
* @param $params
|
||||
*/
|
||||
public function testIncorrectLogin($params)
|
||||
{
|
||||
/** @var \Magento\Framework\Data\Form\FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
|
||||
$params['form_key'] = $formKey->getFormKey();
|
||||
$this->getRequest()->setPostValue($params);
|
||||
$this->dispatch('backend/admin/auth/login');
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(
|
||||
[
|
||||
'The account sign-in was incorrect or your account is disabled temporarily. '
|
||||
. 'Please wait and try again later.'
|
||||
]
|
||||
),
|
||||
MessageInterface::TYPE_ERROR
|
||||
);
|
||||
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
);
|
||||
$backendUrlModel->turnOffSecretKey();
|
||||
$url = $backendUrlModel->getUrl('admin');
|
||||
$this->assertRedirect($this->stringStartsWith($url));
|
||||
}
|
||||
|
||||
public function incorrectLoginDataProvider()
|
||||
{
|
||||
return [
|
||||
'login dummy user' => [
|
||||
[
|
||||
'login' => [
|
||||
'username' => 'test1',
|
||||
'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
|
||||
],
|
||||
],
|
||||
],
|
||||
'login without role' => [
|
||||
[
|
||||
'login' => [
|
||||
'username' => 'test2',
|
||||
'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
|
||||
],
|
||||
],
|
||||
],
|
||||
'login not active user' => [
|
||||
[
|
||||
'login' => [
|
||||
'username' => 'test3',
|
||||
'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Controller\Adminhtml\Cache;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
class CleanStaticFilesTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Backend::cache';
|
||||
$this->uri = 'backend/admin/cache/cleanStaticFiles';
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testAclHasAccess()
|
||||
{
|
||||
// setup
|
||||
/** @var \Magento\Framework\Filesystem $filesystem */
|
||||
$filesystem = Bootstrap::getObjectManager()->get(\Magento\Framework\Filesystem::class);
|
||||
$dirStatic = $filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
|
||||
$subStaticDir = 'subdir';
|
||||
$dirStatic->create($subStaticDir);
|
||||
$this->assertTrue($dirStatic->isExist($subStaticDir));
|
||||
|
||||
$dirVar= $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
|
||||
$subVarDir = DirectoryList::TMP_MATERIALIZATION_DIR . '/subdir';
|
||||
$dirVar->create($subVarDir);
|
||||
$this->assertTrue($dirVar->isExist($subVarDir));
|
||||
|
||||
// test
|
||||
parent::testAclHasAccess();
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual("The static files cache has been cleaned."),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS,
|
||||
\Magento\Framework\Message\ManagerInterface::class
|
||||
);
|
||||
$this->assertFalse($dirStatic->isExist($subStaticDir));
|
||||
$this->assertTrue($dirVar->isExist(DirectoryList::TMP_MATERIALIZATION_DIR));
|
||||
$this->assertFalse($dirVar->isExist($subVarDir));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Controller\Adminhtml\Cache;
|
||||
|
||||
use Magento\Framework\App\Cache\State;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\Config\File\ConfigFilePool;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\TestFramework\App\State as AppState;
|
||||
|
||||
class MassActionTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Configuration of cache types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $typesConfig;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mageState;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
/** @var \Magento\Framework\App\DeploymentConfig $config */
|
||||
$config = Bootstrap::getObjectManager()->get(\Magento\Framework\App\DeploymentConfig::class);
|
||||
self::$typesConfig = $config->get(State::CACHE_KEY);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->mageState = Bootstrap::getObjectManager()->get(AppState::class)->getMode();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Bootstrap::getObjectManager()->get(AppState::class)->setMode($this->mageState);
|
||||
/** @var $cacheState \Magento\Framework\App\Cache\StateInterface */
|
||||
$cacheState = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Cache\StateInterface::class);
|
||||
foreach (self::$typesConfig as $type => $value) {
|
||||
$cacheState->setEnabled($type, $value);
|
||||
}
|
||||
$cacheState->persist();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider massActionsDataProvider
|
||||
* @param array $typesToEnable
|
||||
*/
|
||||
public function testMassEnableActionDeveloperMode($typesToEnable = [])
|
||||
{
|
||||
$this->setAll(false);
|
||||
|
||||
$this->getRequest()->setParams(['types' => $typesToEnable]);
|
||||
$this->dispatch('backend/admin/cache/massEnable');
|
||||
|
||||
foreach ($this->getCacheStates() as $cacheType => $cacheState) {
|
||||
if (in_array($cacheType, $typesToEnable)) {
|
||||
$this->assertEquals(1, $cacheState, "Type '{$cacheType}' has not been enabled");
|
||||
} else {
|
||||
$this->assertEquals(0, $cacheState, "Type '{$cacheType}' must remain disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider massActionsDataProvider
|
||||
* @param array $typesToEnable
|
||||
*/
|
||||
public function testMassEnableActionProductionMode($typesToEnable = [])
|
||||
{
|
||||
Bootstrap::getObjectManager()->get(AppState::class)->setMode(AppState::MODE_PRODUCTION);
|
||||
$this->setAll(false);
|
||||
|
||||
$this->getRequest()->setParams(['types' => $typesToEnable]);
|
||||
$this->dispatch('backend/admin/cache/massEnable');
|
||||
|
||||
foreach ($this->getCacheStates() as $cacheType => $cacheState) {
|
||||
$this->assertEquals(0, $cacheState, "Type '{$cacheType}' must remain disabled");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider massActionsDataProvider
|
||||
* @param array $typesToDisable
|
||||
*/
|
||||
public function testMassDisableActionDeveloperMode($typesToDisable = [])
|
||||
{
|
||||
$this->setAll(true);
|
||||
|
||||
$this->getRequest()->setParams(['types' => $typesToDisable]);
|
||||
$this->dispatch('backend/admin/cache/massDisable');
|
||||
|
||||
foreach ($this->getCacheStates() as $cacheType => $cacheState) {
|
||||
if (in_array($cacheType, $typesToDisable)) {
|
||||
$this->assertEquals(0, $cacheState, "Type '{$cacheType}' has not been disabled");
|
||||
} else {
|
||||
$this->assertEquals(1, $cacheState, "Type '{$cacheType}' must remain enabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider massActionsDataProvider
|
||||
* @param array $typesToDisable
|
||||
*/
|
||||
public function testMassDisableActionProductionMode($typesToDisable = [])
|
||||
{
|
||||
Bootstrap::getObjectManager()->get(AppState::class)->setMode(AppState::MODE_PRODUCTION);
|
||||
$this->setAll(true);
|
||||
|
||||
$this->getRequest()->setParams(['types' => $typesToDisable]);
|
||||
$this->dispatch('backend/admin/cache/massDisable');
|
||||
|
||||
foreach ($this->getCacheStates() as $cacheType => $cacheState) {
|
||||
$this->assertEquals(1, $cacheState, "Type '{$cacheType}' must remain enabled");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve cache states (enabled/disabled) information
|
||||
*
|
||||
* Access configuration file directly as it is not possible to re-include modified file under HHVM
|
||||
* @link https://github.com/facebook/hhvm/issues/1447
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.EvalExpression)
|
||||
*/
|
||||
protected function getCacheStates()
|
||||
{
|
||||
$configFilePool = new ConfigFilePool();
|
||||
$configPath = Bootstrap::getInstance()->getAppTempDir() . '/'. DirectoryList::CONFIG .'/'
|
||||
. $configFilePool->getPath($configFilePool::APP_ENV);
|
||||
$configData = eval(str_replace('<?php', '', file_get_contents($configPath)));
|
||||
return $configData[State::CACHE_KEY];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all cache types to enabled or disabled state
|
||||
*
|
||||
* @param bool $isEnabled
|
||||
* @return void
|
||||
*/
|
||||
private function setAll($isEnabled)
|
||||
{
|
||||
/** @var $cacheState \Magento\Framework\App\Cache\StateInterface */
|
||||
$cacheState = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Cache\StateInterface::class);
|
||||
foreach (array_keys(self::$typesConfig) as $type) {
|
||||
$cacheState->setEnabled($type, $isEnabled);
|
||||
}
|
||||
$cacheState->persist();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Backend/controllers/_files/cache/all_types_invalidated.php
|
||||
* @dataProvider massActionsDataProvider
|
||||
* @param array $typesToRefresh
|
||||
*/
|
||||
public function testMassRefreshAction($typesToRefresh = [])
|
||||
{
|
||||
$this->getRequest()->setParams(['types' => $typesToRefresh]);
|
||||
$this->dispatch('backend/admin/cache/massRefresh');
|
||||
|
||||
/** @var $cacheTypeList \Magento\Framework\App\Cache\TypeListInterface */
|
||||
$cacheTypeList = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Cache\TypeListInterface::class);
|
||||
$invalidatedTypes = array_keys($cacheTypeList->getInvalidated());
|
||||
$failed = array_intersect($typesToRefresh, $invalidatedTypes);
|
||||
$this->assertEmpty($failed, 'Could not refresh following cache types: ' . implode(', ', $failed));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function massActionsDataProvider()
|
||||
{
|
||||
return [
|
||||
'no types' => [[]],
|
||||
'existing types' => [
|
||||
[
|
||||
\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER,
|
||||
\Magento\Framework\App\Cache\Type\Layout::TYPE_IDENTIFIER,
|
||||
\Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER,
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Controller\Adminhtml;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CacheTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Backend/controllers/_files/cache/application_cache.php
|
||||
* @magentoDataFixture Magento/Backend/controllers/_files/cache/non_application_cache.php
|
||||
*/
|
||||
public function testFlushAllAction()
|
||||
{
|
||||
/** @var $cache \Magento\Framework\App\Cache */
|
||||
$cache = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Cache::class
|
||||
);
|
||||
$this->assertNotEmpty($cache->load('APPLICATION_FIXTURE'));
|
||||
|
||||
$this->dispatch('backend/admin/cache/flushAll');
|
||||
|
||||
/** @var $cachePool \Magento\Framework\App\Cache\Frontend\Pool */
|
||||
$this->assertFalse($cache->load('APPLICATION_FIXTURE'));
|
||||
|
||||
$cachePool = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Cache\Frontend\Pool::class
|
||||
);
|
||||
/** @var $cacheFrontend \Magento\Framework\Cache\FrontendInterface */
|
||||
foreach ($cachePool as $cacheFrontend) {
|
||||
$this->assertFalse($cacheFrontend->getBackend()->load('NON_APPLICATION_FIXTURE'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Backend/controllers/_files/cache/application_cache.php
|
||||
* @magentoDataFixture Magento/Backend/controllers/_files/cache/non_application_cache.php
|
||||
*/
|
||||
public function testFlushSystemAction()
|
||||
{
|
||||
$this->dispatch('backend/admin/cache/flushSystem');
|
||||
|
||||
/** @var $cache \Magento\Framework\App\Cache */
|
||||
$cache = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Cache::class
|
||||
);
|
||||
/** @var $cachePool \Magento\Framework\App\Cache\Frontend\Pool */
|
||||
$this->assertFalse($cache->load('APPLICATION_FIXTURE'));
|
||||
|
||||
$cachePool = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Cache\Frontend\Pool::class
|
||||
);
|
||||
/** @var $cacheFrontend \Magento\Framework\Cache\FrontendInterface */
|
||||
foreach ($cachePool as $cacheFrontend) {
|
||||
$this->assertSame(
|
||||
'non-application cache data',
|
||||
$cacheFrontend->getBackend()->load('NON_APPLICATION_FIXTURE')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider massActionsInvalidTypesDataProvider
|
||||
* @param $action
|
||||
*/
|
||||
public function testMassActionsInvalidTypes($action)
|
||||
{
|
||||
$this->getRequest()->setParams(['types' => ['invalid_type_1', 'invalid_type_2', 'config']]);
|
||||
$this->dispatch('backend/admin/cache/' . $action);
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual("These cache type(s) don't exist: invalid_type_1, invalid_type_2"),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function massActionsInvalidTypesDataProvider()
|
||||
{
|
||||
return [
|
||||
'enable' => ['massEnable'],
|
||||
'disable' => ['massDisable'],
|
||||
'refresh' => ['massRefresh']
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\Controller\Adminhtml;
|
||||
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ConsecutiveCallTest extends AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Consecutive calls were failing due to `$request['dispatched']` not being reset before request
|
||||
*/
|
||||
public function testConsecutiveCallShouldNotFail()
|
||||
{
|
||||
$this->dispatch('backend/admin/auth/login');
|
||||
$this->dispatch('backend/admin/auth/login');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\Controller\Adminhtml\Dashboard;
|
||||
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class AjaxBlockTest extends AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Test execute to check render block
|
||||
*
|
||||
* @param string $block
|
||||
* @param string $expectedResult
|
||||
*
|
||||
* @dataProvider ajaxBlockDataProvider
|
||||
*/
|
||||
public function testExecute($block, $expectedResult)
|
||||
{
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setParam('block', $block);
|
||||
|
||||
$this->dispatch('backend/admin/dashboard/ajaxBlock/');
|
||||
|
||||
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode());
|
||||
|
||||
$actual = $this->getResponse()->getBody();
|
||||
|
||||
$this->assertStringContainsString($expectedResult, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides POST data and Expected Result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function ajaxBlockDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'totals',
|
||||
'dashboard_diagram_totals'
|
||||
],
|
||||
[
|
||||
'',
|
||||
''
|
||||
],
|
||||
[
|
||||
'test_block',
|
||||
''
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Controller\Adminhtml\Dashboard;
|
||||
|
||||
/**
|
||||
* Test product viewed backend controller.
|
||||
*/
|
||||
class ProductsViewedTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Reports/_files/viewed_products.php
|
||||
* @magentoConfigFixture default/reports/options/enabled 1
|
||||
*/
|
||||
public function testExecute()
|
||||
{
|
||||
$this->getRequest()->setMethod("POST");
|
||||
$this->dispatch('backend/admin/dashboard/productsViewed/');
|
||||
|
||||
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode());
|
||||
|
||||
$actual = $this->getResponse()->getBody();
|
||||
$this->assertStringContainsString('Simple Product', $actual);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Controller\Adminhtml;
|
||||
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Check not logged state
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Index\Index::execute
|
||||
*/
|
||||
public function testNotLoggedIndexAction()
|
||||
{
|
||||
$this->_auth->logout();
|
||||
$this->dispatch('backend/admin/index/index');
|
||||
/** @var $backendUrlModel \Magento\Backend\Model\UrlInterface */
|
||||
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
);
|
||||
$backendUrlModel->turnOffSecretKey();
|
||||
$url = $backendUrlModel->getUrl('admin');
|
||||
$this->assertRedirect($this->stringStartsWith($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check logged state
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Index\Index::execute
|
||||
*
|
||||
*/
|
||||
public function testLoggedIndexAction()
|
||||
{
|
||||
$this->dispatch('backend/admin/index/index');
|
||||
$this->assertRedirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Controller\Adminhtml\Index\GlobalSearch::execute
|
||||
*/
|
||||
public function testGlobalSearchAction()
|
||||
{
|
||||
$this->getRequest()->setParam('isAjax', 'true');
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue('query', 'dummy');
|
||||
$this->dispatch('backend/admin/index/globalSearch');
|
||||
|
||||
$actual = $this->getResponse()->getBody();
|
||||
$this->assertEquals([], json_decode($actual));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Controller\Adminhtml\System;
|
||||
|
||||
use Magento\TestFramework\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class AccountTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @dataProvider saveDataProvider
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testSaveAction($password, $passwordConfirmation, $isPasswordChanged)
|
||||
{
|
||||
$userId = $this->_session->getUser()->getId();
|
||||
/** @var $user \Magento\User\Model\User */
|
||||
$user = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\User\Model\User::class
|
||||
)->load(
|
||||
$userId
|
||||
);
|
||||
$oldPassword = $user->getPassword();
|
||||
|
||||
$request = $this->getRequest();
|
||||
$request->setParam(
|
||||
'username',
|
||||
$user->getUsername()
|
||||
)->setParam(
|
||||
'email',
|
||||
$user->getEmail()
|
||||
)->setParam(
|
||||
'firstname',
|
||||
$user->getFirstname()
|
||||
)->setParam(
|
||||
'lastname',
|
||||
$user->getLastname()
|
||||
)->setParam(
|
||||
'password',
|
||||
$password
|
||||
)->setParam(
|
||||
'password_confirmation',
|
||||
$passwordConfirmation
|
||||
)->setParam(
|
||||
\Magento\Backend\Block\System\Account\Edit\Form::IDENTITY_VERIFICATION_PASSWORD_FIELD,
|
||||
Bootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
$this->dispatch('backend/admin/system_account/save');
|
||||
|
||||
/** @var $user \Magento\User\Model\User */
|
||||
$user = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\User\Model\User::class
|
||||
)->load(
|
||||
$userId
|
||||
);
|
||||
|
||||
if ($isPasswordChanged) {
|
||||
$this->assertNotEquals($oldPassword, $user->getPassword());
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $encryptor \Magento\Framework\Encryption\EncryptorInterface */
|
||||
$encryptor = $objectManager->get(\Magento\Framework\Encryption\EncryptorInterface::class);
|
||||
$this->assertTrue($encryptor->validateHash($password, $user->getPassword()));
|
||||
} else {
|
||||
$this->assertEquals($oldPassword, $user->getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
public function saveDataProvider()
|
||||
{
|
||||
$password = uniqid('123q');
|
||||
return [
|
||||
[$password, $password, true],
|
||||
[$password, '', false],
|
||||
[$password, $password . '123', false],
|
||||
['', '', false],
|
||||
['', $password, false]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Controller\Adminhtml\System;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DesignTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @covers \Magento\Backend\App\Action::_addLeft
|
||||
*/
|
||||
public function testEditAction()
|
||||
{
|
||||
$this->dispatch('backend/admin/system_design/edit');
|
||||
$this->assertStringMatchesFormat('%A<a%Aid="design_tabs_general"%A', $this->getResponse()->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\Controller\Adminhtml\System;
|
||||
|
||||
use Magento\Store\Model\ResourceModel\Store as StoreResource;
|
||||
use Magento\Store\Api\Data\StoreInterfaceFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\Framework\Message\ManagerInterface;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class StoreTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @var FormKey
|
||||
*/
|
||||
private $formKey;
|
||||
|
||||
/**
|
||||
* @var StoreResource
|
||||
*/
|
||||
private $storeResource;
|
||||
|
||||
/**
|
||||
* @var StoreInterfaceFactory
|
||||
*/
|
||||
private $storeFactory;
|
||||
|
||||
/**
|
||||
* @var WebsiteRepositoryInterface
|
||||
*/
|
||||
private $websiteRepository;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->formKey = $this->_objectManager->get(FormKey::class);
|
||||
$this->storeResource = $this->_objectManager->get(StoreResource::class);
|
||||
$this->storeFactory = $this->_objectManager->get(StoreInterfaceFactory::class);
|
||||
$this->websiteRepository = $this->_objectManager->get(WebsiteRepositoryInterface::class);
|
||||
}
|
||||
|
||||
public function testIndexAction()
|
||||
{
|
||||
$this->dispatch('backend/admin/system_store/index');
|
||||
|
||||
$response = $this->getResponse()->getBody();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="add" and @title = "Create Website"]/span[text() = "Create Website"]',
|
||||
$response
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="add_group"]',
|
||||
$response
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="add_store"]',
|
||||
$response
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id = "add" and @class = "disabled"]',
|
||||
$response
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="add_group" and contains(@class,"disabled")]',
|
||||
$response
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="add_store" and contains(@class,"disabled")]',
|
||||
$response
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $post
|
||||
* @param string $message
|
||||
* @dataProvider saveActionWithExistCodeDataProvider
|
||||
*/
|
||||
public function testSaveActionWithExistCode($post, $message)
|
||||
{
|
||||
$post['form_key'] = $this->formKey->getFormKey();
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($post);
|
||||
$this->dispatch('backend/admin/system_store/save');
|
||||
//Check that errors was generated and set to session
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual($message),
|
||||
MessageInterface::TYPE_ERROR,
|
||||
ManagerInterface::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save action test.
|
||||
* Changing of a default website when a target website doesn't have a default store view.
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php
|
||||
*/
|
||||
public function testSaveActionChangeDefaultWebsiteThatDoesntHaveDefaultStoreView(): void
|
||||
{
|
||||
$secondWebsite = $this->websiteRepository->get('test');
|
||||
// inactivate default store view of second store
|
||||
$secondStore = $this->storeFactory->create();
|
||||
$this->storeResource->load($secondStore, 'fixture_second_store', 'code');
|
||||
$secondStore->setIsActive(0);
|
||||
$this->storeResource->save($secondStore);
|
||||
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue([
|
||||
'website' => [
|
||||
'name' => 'Test Website',
|
||||
'code' => 'test',
|
||||
'sort_order' => '0',
|
||||
'default_group_id' => $secondWebsite->getDefaultGroupId(),
|
||||
'is_default' => '1',
|
||||
'website_id' => $secondWebsite->getId(),
|
||||
],
|
||||
'store_type' => 'website',
|
||||
'store_action' => 'edit',
|
||||
],);
|
||||
$this->dispatch('backend/admin/system_store/save');
|
||||
//Check that errors was generated and set to session
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual('Please enable your Store View before using this Web Site as Default'),
|
||||
MessageInterface::TYPE_ERROR,
|
||||
ManagerInterface::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function saveActionWithExistCodeDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'post' => [
|
||||
'website' => [
|
||||
'name' => 'base',
|
||||
'code' => 'base',
|
||||
'sort_order' => '',
|
||||
'is_default' => '',
|
||||
'website_id' => '',
|
||||
],
|
||||
'store_type' => 'website',
|
||||
'store_action' => 'add',
|
||||
],
|
||||
'message' => 'Website with the same code already exists.',
|
||||
],
|
||||
[
|
||||
'post' => [
|
||||
'group' => [
|
||||
'website_id' => '1',
|
||||
'name' => 'default',
|
||||
'code' => 'default',
|
||||
'root_category_id' => '1',
|
||||
'group_id' => '',
|
||||
],
|
||||
'store_type' => 'group',
|
||||
'store_action' => 'add',
|
||||
],
|
||||
'message' => 'Group with the same code already exists.',
|
||||
],
|
||||
[
|
||||
'post' => [
|
||||
'store' => [
|
||||
'name' => 'default',
|
||||
'code' => 'default',
|
||||
'is_active' => '1',
|
||||
'sort_order' => '',
|
||||
'is_default' => '',
|
||||
'group_id' => '1',
|
||||
'store_id' => '',
|
||||
],
|
||||
'store_type' => 'store',
|
||||
'store_action' => 'add',
|
||||
],
|
||||
'message' => 'Store with the same code already exists.',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Controller\Adminhtml;
|
||||
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class UrlRewriteTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Check save cms page rewrite
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Cms/_files/pages.php
|
||||
*/
|
||||
public function testSaveActionCmsPage()
|
||||
{
|
||||
$page = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Cms\Model\Page::class);
|
||||
$page->load('page_design_blank', 'identifier');
|
||||
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue(
|
||||
[
|
||||
'description' => 'Some URL rewrite description',
|
||||
'options' => 'R',
|
||||
'request_path' => 'some_new_path',
|
||||
'store_id' => 1,
|
||||
'cms_page' => $page->getId(),
|
||||
]
|
||||
);
|
||||
$this->dispatch('backend/admin/url_rewrite/save');
|
||||
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual('The URL Rewrite has been saved.'),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
$this->assertRedirect($this->stringContains('backend/admin/url_rewrite/index'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Helper;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class DataTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Helper\Data
|
||||
*/
|
||||
protected $_helper;
|
||||
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Auth
|
||||
*/
|
||||
protected $_auth;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Config\ScopeInterface::class
|
||||
)->setCurrentScope(
|
||||
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
|
||||
);
|
||||
$this->_helper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Helper\Data::class
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_helper = null;
|
||||
$this->_auth = null;
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Config\ScopeInterface::class
|
||||
)->setCurrentScope(
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs user login
|
||||
*/
|
||||
protected function _login()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOffSecretKey();
|
||||
$this->_auth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\Auth::class
|
||||
);
|
||||
$this->_auth->login(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs user logout
|
||||
*/
|
||||
protected function _logout()
|
||||
{
|
||||
$this->_auth->logout();
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOnSecretKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Helper\Data::getPageHelpUrl
|
||||
* @covers \Magento\Backend\Helper\Data::setPageHelpUrl
|
||||
* @covers \Magento\Backend\Helper\Data::addPageHelpUrl
|
||||
*/
|
||||
public function testPageHelpUrl()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\RequestInterface::class
|
||||
)->setControllerModule(
|
||||
'dummy'
|
||||
)->setControllerName(
|
||||
'index'
|
||||
)->setActionName(
|
||||
'test'
|
||||
);
|
||||
|
||||
$expected = 'http://www.magentocommerce.com/gethelp/en_US/dummy/index/test/';
|
||||
$this->assertEquals($expected, $this->_helper->getPageHelpUrl(), 'Incorrect help Url');
|
||||
|
||||
$this->_helper->addPageHelpUrl('dummy');
|
||||
$expected .= 'dummy';
|
||||
$this->assertEquals($expected, $this->_helper->getPageHelpUrl(), 'Incorrect help Url suffix');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Helper\Data::getCurrentUserId
|
||||
*/
|
||||
public function testGetCurrentUserId()
|
||||
{
|
||||
$this->assertFalse($this->_helper->getCurrentUserId());
|
||||
|
||||
/**
|
||||
* perform login
|
||||
*/
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOffSecretKey();
|
||||
|
||||
$auth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Backend\Model\Auth::class);
|
||||
$auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
|
||||
$this->assertEquals(1, $this->_helper->getCurrentUserId());
|
||||
|
||||
/**
|
||||
* perform logout
|
||||
*/
|
||||
$auth->logout();
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOnSecretKey();
|
||||
|
||||
$this->assertFalse($this->_helper->getCurrentUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Helper\Data::prepareFilterString
|
||||
*/
|
||||
public function testPrepareFilterString()
|
||||
{
|
||||
$expected = ['key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'];
|
||||
|
||||
$filterString = base64_encode('key1=' . rawurlencode('val1') . '&key2=' . rawurlencode('val2') . '&key3=val3');
|
||||
$actual = $this->_helper->prepareFilterString($filterString);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetHomePageUrl()
|
||||
{
|
||||
$this->assertStringEndsWith(
|
||||
'index.php/backend/admin/',
|
||||
$this->_helper->getHomePageUrl(),
|
||||
'Incorrect home page URL'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Model\Auth;
|
||||
|
||||
use Magento\TestFramework\Bootstrap as TestHelper;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class SessionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Auth
|
||||
*/
|
||||
private $auth;
|
||||
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Auth\Session
|
||||
*/
|
||||
private $authSession;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->objectManager->get(\Magento\Framework\Config\ScopeInterface::class)
|
||||
->setCurrentScope(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
$this->auth = $this->objectManager->create(\Magento\Backend\Model\Auth::class);
|
||||
$this->authSession = $this->objectManager->create(\Magento\Backend\Model\Auth\Session::class);
|
||||
$this->authSession->setUser($this->objectManager->create(\Magento\User\Model\User::class));
|
||||
$this->auth->setAuthStorage($this->authSession);
|
||||
$this->auth->logout();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->auth = null;
|
||||
$this->objectManager->get(\Magento\Framework\Config\ScopeInterface::class)->setCurrentScope(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider loginDataProvider
|
||||
*/
|
||||
public function testIsLoggedIn($loggedIn)
|
||||
{
|
||||
if ($loggedIn) {
|
||||
$this->auth->login(
|
||||
TestHelper::ADMIN_NAME,
|
||||
TestHelper::ADMIN_PASSWORD
|
||||
);
|
||||
}
|
||||
$this->assertEquals($loggedIn, $this->authSession->isLoggedIn());
|
||||
}
|
||||
|
||||
public function loginDataProvider()
|
||||
{
|
||||
return [[false], [true]];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Model;
|
||||
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Exception\AuthenticationException;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Model\Auth.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class AuthTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Auth
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()
|
||||
->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Backend\Model\Auth::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoginDataProvider
|
||||
* @param string $userName
|
||||
* @param string $password
|
||||
*/
|
||||
public function testLoginFailed($userName, $password)
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\AuthenticationException::class);
|
||||
|
||||
$this->_model->login($userName, $password);
|
||||
}
|
||||
|
||||
public function getLoginDataProvider()
|
||||
{
|
||||
return [
|
||||
'Invalid credentials' => ['not_exists', 'not_exists'],
|
||||
'Empty credentials' => ['', 'not_exists']
|
||||
];
|
||||
}
|
||||
|
||||
public function testSetGetAuthStorage()
|
||||
{
|
||||
// by default \Magento\Backend\Model\Auth\Session class will instantiate as a Authentication Storage
|
||||
$this->assertInstanceOf(\Magento\Backend\Model\Auth\Session::class, $this->_model->getAuthStorage());
|
||||
|
||||
$mockStorage = $this->createMock(\Magento\Backend\Model\Auth\StorageInterface::class);
|
||||
$this->_model->setAuthStorage($mockStorage);
|
||||
$this->assertInstanceOf(\Magento\Backend\Model\Auth\StorageInterface::class, $this->_model->getAuthStorage());
|
||||
|
||||
$incorrectStorage = new \StdClass();
|
||||
try {
|
||||
$this->_model->setAuthStorage($incorrectStorage);
|
||||
$this->fail('Incorrect authentication storage setted.');
|
||||
} catch (AuthenticationException $e) {
|
||||
// in case of exception - Auth works correct
|
||||
$this->assertNotEmpty($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetCredentialStorageList()
|
||||
{
|
||||
$storage = $this->_model->getCredentialStorage();
|
||||
$this->assertInstanceOf(\Magento\Backend\Model\Auth\Credential\StorageInterface::class, $storage);
|
||||
}
|
||||
|
||||
public function testLoginSuccessful()
|
||||
{
|
||||
$this->_model->login(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
\Magento\Backend\Model\Auth\Credential\StorageInterface::class,
|
||||
$this->_model->getUser()
|
||||
);
|
||||
$this->assertGreaterThan(time() - 10, $this->_model->getAuthStorage()->getUpdatedAt());
|
||||
}
|
||||
|
||||
public function testLoginFlushesFormKey()
|
||||
{
|
||||
/** @var FormKey $dataFormKey */
|
||||
$dataFormKey = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(FormKey::class);
|
||||
$beforeKey = $dataFormKey->getFormKey();
|
||||
$this->_model->login(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
$afterKey = $dataFormKey->getFormKey();
|
||||
$this->assertNotEquals($beforeKey, $afterKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testLogout()
|
||||
{
|
||||
$this->_model->login(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
$this->assertNotEmpty($this->_model->getAuthStorage()->getData());
|
||||
$this->_model->logout();
|
||||
$this->assertEmpty($this->_model->getAuthStorage()->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabled form security in order to prevent exit from the app
|
||||
* @magentoAdminConfigFixture admin/security/session_lifetime 100
|
||||
*/
|
||||
public function testIsLoggedIn()
|
||||
{
|
||||
$this->_model->login(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
$this->assertTrue($this->_model->isLoggedIn());
|
||||
}
|
||||
|
||||
public function testGetUser()
|
||||
{
|
||||
$this->_model->login(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
|
||||
);
|
||||
|
||||
$this->assertNotNull($this->_model->getUser());
|
||||
$this->assertGreaterThan(0, $this->_model->getUser()->getId());
|
||||
$this->assertInstanceOf(
|
||||
\Magento\Backend\Model\Auth\Credential\StorageInterface::class,
|
||||
$this->_model->getUser()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\Model\Dashboard;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
use Magento\Framework\Stdlib\DateTime;
|
||||
|
||||
/**
|
||||
* Verify chart data by different period.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ChartTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Chart
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->model = $this->objectManager->get(Chart::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify getByPeriod with all types of period
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_list_with_invoice.php
|
||||
* @dataProvider getChartDataProvider
|
||||
* @return void
|
||||
*/
|
||||
public function testGetByPeriodWithParam(int $expectedDataQty, string $period, string $chartParam): void
|
||||
{
|
||||
$timezoneLocal = $this->objectManager->get(TimezoneInterface::class)->getConfigTimezone();
|
||||
$order = $this->objectManager->get(Order::class);
|
||||
$order->loadByIncrementId('100000002');
|
||||
$payment = $this->objectManager->get(Payment::class);
|
||||
$payment->setMethod('checkmo');
|
||||
$payment->setAdditionalInformation('last_trans_id', '11122');
|
||||
$payment->setAdditionalInformation('metadata', [
|
||||
'type' => 'free',
|
||||
'fraudulent' => false
|
||||
]);
|
||||
$dateTime = new \DateTime('now', new \DateTimeZone($timezoneLocal));
|
||||
$order->setCreatedAt($dateTime->modify('-1 hour')->format(DateTime::DATETIME_PHP_FORMAT));
|
||||
$order->setPayment($payment);
|
||||
$order->save();
|
||||
$ordersData = $this->model->getByPeriod($period, $chartParam);
|
||||
$ordersCount = array_sum(array_map(function ($item) {
|
||||
return $item['y'];
|
||||
}, $ordersData));
|
||||
$this->assertGreaterThanOrEqual($expectedDataQty, $ordersCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expected chart data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getChartDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
1,
|
||||
'24h',
|
||||
'quantity'
|
||||
],
|
||||
[
|
||||
3,
|
||||
'7d',
|
||||
'quantity'
|
||||
],
|
||||
[
|
||||
4,
|
||||
'1m',
|
||||
'quantity'
|
||||
],
|
||||
[
|
||||
5,
|
||||
'1y',
|
||||
'quantity'
|
||||
],
|
||||
[
|
||||
6,
|
||||
'2y',
|
||||
'quantity'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Model\Locale;
|
||||
|
||||
use Magento\Framework\Locale\Resolver;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ResolverTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Locale\ResolverInterface
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_model = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Backend\Model\Locale\Resolver::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Model\Locale\Resolver::setLocale
|
||||
*/
|
||||
public function testSetLocaleWithDefaultLocale()
|
||||
{
|
||||
$this->_checkSetLocale(Resolver::DEFAULT_LOCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Model\Locale\Resolver::setLocale
|
||||
*/
|
||||
public function testSetLocaleWithBaseInterfaceLocale()
|
||||
{
|
||||
$user = new \Magento\Framework\DataObject();
|
||||
$session = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\Auth\Session::class
|
||||
);
|
||||
$session->setUser($user);
|
||||
Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\Auth\Session::class
|
||||
)->getUser()->setInterfaceLocale(
|
||||
'fr_FR'
|
||||
);
|
||||
$this->_checkSetLocale('fr_FR');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Model\Locale\Resolver::setLocale
|
||||
*/
|
||||
public function testSetLocaleWithSessionLocale()
|
||||
{
|
||||
Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\Session::class
|
||||
)->setSessionLocale(
|
||||
'es_ES'
|
||||
);
|
||||
$this->_checkSetLocale('es_ES');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Backend\Model\Locale\Resolver::setLocale
|
||||
*/
|
||||
public function testSetLocaleWithRequestLocale()
|
||||
{
|
||||
$request = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\App\RequestInterface::class);
|
||||
$request->setPostValue(['locale' => 'de_DE']);
|
||||
$this->_checkSetLocale('de_DE');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setLocale() with parameter
|
||||
*
|
||||
* @param string|null $localeParam
|
||||
* @param string|null $localeRequestParam
|
||||
* @param string $localeExpected
|
||||
* @dataProvider setLocaleWithParameterDataProvider
|
||||
*/
|
||||
public function testSetLocaleWithParameter(
|
||||
?string $localeParam,
|
||||
?string $localeRequestParam,
|
||||
string $localeExpected
|
||||
) {
|
||||
$request = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\App\RequestInterface::class);
|
||||
$request->setPostValue(['locale' => $localeRequestParam]);
|
||||
$this->_model->setLocale($localeParam);
|
||||
$this->assertEquals($localeExpected, $this->_model->getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function setLocaleWithParameterDataProvider(): array
|
||||
{
|
||||
return [
|
||||
['ko_KR', 'ja_JP', 'ja_JP'],
|
||||
['ko_KR', null, 'ko_KR'],
|
||||
[null, 'ja_JP', 'ja_JP'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check set locale
|
||||
*
|
||||
* @param string $localeCodeToCheck
|
||||
* @return void
|
||||
*/
|
||||
protected function _checkSetLocale($localeCodeToCheck)
|
||||
{
|
||||
$this->_model->setLocale();
|
||||
$localeCode = $this->_model->getLocale();
|
||||
$this->assertEquals($localeCode, $localeCodeToCheck);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Model;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Model\Auth.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class MenuTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Menu
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()
|
||||
->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->model = $this->objectManager->create(\Magento\Backend\Model\Auth::class);
|
||||
$this->objectManager->get(\Magento\Framework\Config\ScopeInterface::class)
|
||||
->setCurrentScope(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
}
|
||||
|
||||
public function testMenuItemManipulation()
|
||||
{
|
||||
/* @var $menu \Magento\Backend\Model\Menu */
|
||||
$menu = $this->objectManager->create(\Magento\Backend\Model\Menu\Config::class)->getMenu();
|
||||
/* @var $itemFactory \Magento\Backend\Model\Menu\Item\Factory */
|
||||
$itemFactory = $this->objectManager->create(\Magento\Backend\Model\Menu\Item\Factory::class);
|
||||
|
||||
// Add new item in top level
|
||||
$menu->add(
|
||||
$itemFactory->create(
|
||||
[
|
||||
'id' => 'Magento_Backend::system2',
|
||||
'title' => 'Extended System',
|
||||
'module' => 'Magento_Backend',
|
||||
'resource' => 'Magento_Backend::system2',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
// Add submenu
|
||||
$menu->add(
|
||||
$itemFactory->create(
|
||||
[
|
||||
'id' => 'Magento_Backend::system2_acl',
|
||||
'title' => 'Acl',
|
||||
'module' => 'Magento_Backend',
|
||||
'action' => 'admin/backend/acl/index',
|
||||
'resource' => 'Magento_Backend::system2_acl',
|
||||
]
|
||||
),
|
||||
'Magento_Backend::system2'
|
||||
);
|
||||
|
||||
// Modify existing menu item
|
||||
$menu->get('Magento_Backend::system2')->setTitle('Base system')->setAction('admin/backend/system/base');
|
||||
// remove dependency from config
|
||||
|
||||
// Change sort order
|
||||
$menu->reorder('Magento_Backend::system', 40);
|
||||
|
||||
// Remove menu item
|
||||
$menu->remove('Magento_Backend::catalog_attribute');
|
||||
|
||||
// Move menu item
|
||||
$menu->move('Magento_Catalog::catalog_products', 'Magento_Backend::system2');
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testSerialize()
|
||||
{
|
||||
/** @var Menu $menu */
|
||||
$menu = $this->objectManager->get(\Magento\Backend\Model\MenuFactory::class)->create();
|
||||
/* @var \Magento\Backend\Model\Menu\Item\Factory $itemFactory */
|
||||
$itemFactory = $this->objectManager->create(\Magento\Backend\Model\Menu\Item\Factory::class);
|
||||
|
||||
// Add new item in top level
|
||||
$menu->add(
|
||||
$itemFactory->create(
|
||||
[
|
||||
'id' => 'Magento_Backend::system3',
|
||||
'title' => 'Extended System',
|
||||
'module' => 'Magento_Backend',
|
||||
'resource' => 'Magento_Backend::system3',
|
||||
'dependsOnConfig' => 'dev/test/system',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
// Add submenu
|
||||
$menu->add(
|
||||
$itemFactory->create(
|
||||
[
|
||||
'id' => 'Magento_Backend::system3_acl',
|
||||
'title' => 'Acl',
|
||||
'module' => 'Magento_Backend',
|
||||
'action' => 'admin/backend/acl/index',
|
||||
'resource' => 'Magento_Backend::system3_acl',
|
||||
]
|
||||
),
|
||||
'Magento_Backend::system3'
|
||||
);
|
||||
$serializedString = $menu->serialize();
|
||||
$expected = '[{"parent_id":null,"module":"Magento_Backend","sort_index":null,'
|
||||
. '"dependsOnConfig":"dev\/test\/system",'
|
||||
. '"id":"Magento_Backend::system3","resource":"Magento_Backend::system3","path":"","action":null,'
|
||||
. '"dependsOnModule":null,"toolTip":null,"title":"Extended System",'
|
||||
. '"target":null,"sub_menu":[{"parent_id":null,"module":"Magento_Backend","sort_index":null,'
|
||||
. '"dependsOnConfig":null,"id":"Magento_Backend::system3_acl","resource":"Magento_Backend::system3_acl",'
|
||||
. '"path":"","action":"admin\/backend\/acl\/index","dependsOnModule":null,"toolTip":null,"title":"Acl",'
|
||||
. '"target":null,"sub_menu":null}]}]';
|
||||
$this->assertEquals($expected, $serializedString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testUnserialize()
|
||||
{
|
||||
$serializedMenu = '[{"parent_id":null,"module":"Magento_Backend","sort_index":null,'
|
||||
. '"dependsOnConfig":"dev\/test","id":"Magento_Backend::system3","resource":"Magento_Backend::system3",'
|
||||
. '"path":"","action":null,"dependsOnModule":null,"toolTip":null,"title":"Extended System",'
|
||||
. '"target":null,"sub_menu":[{"parent_id":null,"module":"Magento_Backend","sort_index":null,'
|
||||
. '"dependsOnConfig":null,"id":"Magento_Backend::system3_acl","resource":"Magento_Backend::system3_acl",'
|
||||
. '"path":"","action":"admin\/backend\/acl\/index","dependsOnModule":null,"toolTip":null,"title":"Acl",'
|
||||
. '"target":null,"sub_menu":null}]}]';
|
||||
/** @var Menu $menu */
|
||||
$menu = $this->objectManager->get(\Magento\Backend\Model\MenuFactory::class)->create();
|
||||
$menu->unserialize($serializedMenu);
|
||||
$expected = [
|
||||
[
|
||||
'parent_id' => null,
|
||||
'module' => 'Magento_Backend',
|
||||
'sort_index' => null,
|
||||
'dependsOnConfig' => 'dev/test',
|
||||
'id' => 'Magento_Backend::system3',
|
||||
'resource' => 'Magento_Backend::system3',
|
||||
'path' => '',
|
||||
'action' => null,
|
||||
'dependsOnModule' => null,
|
||||
'toolTip' => null,
|
||||
'title' => 'Extended System',
|
||||
'target' => null,
|
||||
'sub_menu' =>
|
||||
[
|
||||
[
|
||||
'parent_id' => null,
|
||||
'module' => 'Magento_Backend',
|
||||
'sort_index' => null,
|
||||
'dependsOnConfig' => null,
|
||||
'id' => 'Magento_Backend::system3_acl',
|
||||
'resource' => 'Magento_Backend::system3_acl',
|
||||
'path' => '',
|
||||
'action' => 'admin/backend/acl/index',
|
||||
'dependsOnModule' => null,
|
||||
'toolTip' => null,
|
||||
'title' => 'Acl',
|
||||
'sub_menu' => null,
|
||||
'target' => null
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $menu->toArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Model\Search;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("unused")
|
||||
*/
|
||||
class AuthorizationMock extends \Magento\Framework\Authorization
|
||||
{
|
||||
/**
|
||||
* Check current user permission on resource and privilege
|
||||
*
|
||||
* @param string $resource
|
||||
* @param string $privilege
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAllowed($resource, $privilege = null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Model\Search;
|
||||
|
||||
use Magento\Backend\App\Area\FrontNameResolver;
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\App\AreaList;
|
||||
use Magento\Framework\App\Cache\State;
|
||||
use Magento\Framework\App\Config\FileResolver;
|
||||
use Magento\Framework\AuthorizationInterface;
|
||||
use Magento\Framework\Config\FileIteratorFactory;
|
||||
use Magento\Framework\Config\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.StaticAccess)
|
||||
*/
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider loadDataProvider
|
||||
* @magentoConfigFixture current_store general/store_information/name Foo
|
||||
*/
|
||||
public function testLoad($query, $expectedResult)
|
||||
{
|
||||
/** @var \Magento\Backend\Model\Search\Config $configSearch */
|
||||
$configSearch = $this->getConfigSearchInstance();
|
||||
$configSearch->setQuery($query);
|
||||
$configSearch->load();
|
||||
|
||||
/** SUT Execution */
|
||||
$searchResults = $configSearch->getResults();
|
||||
|
||||
/** Ensure that search results are correct */
|
||||
$this->assertCount(count($expectedResult), $searchResults, 'Quantity of search result items is invalid.');
|
||||
foreach ($expectedResult as $itemIndex => $expectedItem) {
|
||||
/** Validate URL to item */
|
||||
$elementPathParts = explode('/', $expectedItem['id']);
|
||||
// filter empty values
|
||||
$elementPathParts = array_values(array_filter($elementPathParts));
|
||||
foreach ($elementPathParts as $elementPathPart) {
|
||||
$this->assertStringContainsString(
|
||||
$elementPathPart,
|
||||
$searchResults[$itemIndex]['url'],
|
||||
'Item URL is invalid.'
|
||||
);
|
||||
}
|
||||
unset($searchResults[$itemIndex]['url']);
|
||||
|
||||
/** Validate other item data */
|
||||
$this->assertEquals($expectedItem, $searchResults[$itemIndex], "Data of item #$itemIndex is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Backend\Model\Search\Config
|
||||
*/
|
||||
private function getConfigSearchInstance()
|
||||
{
|
||||
Bootstrap::getInstance()->reinitialize([
|
||||
State::PARAM_BAN_CACHE => true,
|
||||
]);
|
||||
Bootstrap::getObjectManager()
|
||||
->get(ScopeInterface::class)
|
||||
->setCurrentScope(FrontNameResolver::AREA_CODE);
|
||||
Bootstrap::getObjectManager()->get(AreaList::class)
|
||||
->getArea(FrontNameResolver::AREA_CODE)
|
||||
->load(Area::PART_CONFIG);
|
||||
|
||||
Bootstrap::getObjectManager()->configure([
|
||||
'preferences' => [
|
||||
AuthorizationInterface::class => \Magento\Backend\Model\Search\AuthorizationMock::class
|
||||
]
|
||||
]);
|
||||
|
||||
$fileResolverMock = $this->getMockBuilder(FileResolver::class)->disableOriginalConstructor()->getMock();
|
||||
$fileIteratorFactory = Bootstrap::getObjectManager()->get(FileIteratorFactory::class);
|
||||
$fileIterator = $fileIteratorFactory->create(
|
||||
[__DIR__ . '/_files/test_config.xml']
|
||||
);
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($fileIterator);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Config\Model\Config\Structure\Reader $structureReader */
|
||||
$structureReader = $objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure\Reader::class,
|
||||
['fileResolver' => $fileResolverMock]
|
||||
);
|
||||
/** @var \Magento\Config\Model\Config\Structure\Data $structureData */
|
||||
$structureData = $objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure\Data::class,
|
||||
['reader' => $structureReader]
|
||||
);
|
||||
/** @var \Magento\Config\Model\Config\Structure $structure */
|
||||
$structure = $objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure::class,
|
||||
['structureData' => $structureData]
|
||||
);
|
||||
|
||||
return $objectManager->create(
|
||||
\Magento\Backend\Model\Search\Config::class,
|
||||
['configStructure' => $structure]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function loadDataProvider()
|
||||
{
|
||||
return [
|
||||
'Search by field name' => [
|
||||
'Test Field',
|
||||
[
|
||||
[
|
||||
'id' => 'test_section/test_group/test_field_1',
|
||||
'type' => null,
|
||||
'name' => 'Test Field',
|
||||
'description' => ' / Test Tab / Test Section / Test Group',
|
||||
],
|
||||
[
|
||||
'id' => 'test_section/test_group/test_field_2',
|
||||
'type' => null,
|
||||
'name' => 'Test Field',
|
||||
'description' => ' / Test Tab / Test Section / Test Group',
|
||||
],
|
||||
],
|
||||
],
|
||||
'Search by group name' => [
|
||||
'Test Group',
|
||||
[
|
||||
[
|
||||
'id' => 'test_section/test_group',
|
||||
'type' => null,
|
||||
'name' => 'Test Group',
|
||||
'description' => ' / Test Tab / Test Section',
|
||||
],
|
||||
],
|
||||
],
|
||||
'Search by section name' => [
|
||||
'Test Section',
|
||||
[
|
||||
[
|
||||
'id' => '/test_section',
|
||||
'type' => null,
|
||||
'name' => 'Test Section',
|
||||
'description' => ' / Test Tab',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Model\Search;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Customer/_files/three_customers.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
*/
|
||||
class CustomerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider loadDataProvider
|
||||
*/
|
||||
public function testLoad($query, $limit, $start, $expectedResult)
|
||||
{
|
||||
/** Preconditions */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Backend\Model\Search\Customer $customerSearch */
|
||||
$customerSearch = $objectManager->create(\Magento\Backend\Model\Search\Customer::class);
|
||||
$customerSearch->setQuery($query);
|
||||
$customerSearch->setLimit($limit);
|
||||
$customerSearch->setStart($start);
|
||||
$customerSearch->load();
|
||||
|
||||
/** SUT Execution */
|
||||
$searchResults = $customerSearch->getResults();
|
||||
|
||||
/** Ensure that search results are correct */
|
||||
$this->assertCount(count($expectedResult), $searchResults, 'Quantity of search result items is invalid.');
|
||||
foreach ($expectedResult as $itemIndex => $expectedItem) {
|
||||
/** Validate URL to item */
|
||||
$customerId = substr($expectedItem['id'], 11); // 'customer/1/' is added to all actual customer IDs
|
||||
$this->assertStringContainsString(
|
||||
"customer/index/edit/id/$customerId",
|
||||
$searchResults[$itemIndex]['url'],
|
||||
'Item URL is invalid.'
|
||||
);
|
||||
unset($searchResults[$itemIndex]['url']);
|
||||
|
||||
/** Validate other item data */
|
||||
$this->assertEquals($expectedItem, $searchResults[$itemIndex], "Data of item #$itemIndex is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadDataProvider()
|
||||
{
|
||||
return [
|
||||
'All items, first page' => [
|
||||
'Firstname',
|
||||
2, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'customer/1/1',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname Lastname',
|
||||
'description' => 'CompanyName',
|
||||
],
|
||||
[
|
||||
'id' => 'customer/1/2',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname2 Lastname2',
|
||||
'description' => null
|
||||
]
|
||||
],
|
||||
],
|
||||
'All items, second page' => [
|
||||
'Firstname',
|
||||
2, // Items on page
|
||||
2, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'customer/1/3',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname3 Lastname3',
|
||||
'description' => null,
|
||||
]
|
||||
],
|
||||
],
|
||||
'Search by last name, second item only' => [
|
||||
'Lastname2',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'customer/1/2',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname2 Lastname2',
|
||||
'description' => null,
|
||||
]
|
||||
],
|
||||
],
|
||||
'No results' => [
|
||||
'NotExistingCustomerName',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[],
|
||||
],
|
||||
'Search by company name, first item only' => [
|
||||
'CompanyName',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'customer/1/1',
|
||||
'type' => 'Customer',
|
||||
'name' => 'Firstname Lastname',
|
||||
'description' => 'CompanyName',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Model\Search;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order_shipping_address_different_to_billing.php
|
||||
*/
|
||||
class OrderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider loadDataProvider
|
||||
*/
|
||||
public function testLoad($query, $limit, $start, $expectedResult)
|
||||
{
|
||||
/** @var $order \Magento\Sales\Model\Order */
|
||||
$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$orderIdByIncrementId = [];
|
||||
foreach (['100000001', '100000002', '100000003'] as $incrementId) {
|
||||
$orderIdByIncrementId[$incrementId] = $order->loadByIncrementId($incrementId)->getId();
|
||||
}
|
||||
|
||||
/** Preconditions */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Backend\Model\Search\Order $orderSearch */
|
||||
$orderSearch = $objectManager->create(\Magento\Backend\Model\Search\Order::class);
|
||||
$orderSearch->setQuery($query);
|
||||
$orderSearch->setLimit($limit);
|
||||
$orderSearch->setStart($start);
|
||||
$orderSearch->load();
|
||||
|
||||
/** SUT Execution */
|
||||
$searchResults = $orderSearch->getResults();
|
||||
|
||||
/** Ensure that search results are correct */
|
||||
$this->assertCount(count($expectedResult), $searchResults, 'Quantity of search result items is invalid.');
|
||||
foreach ($expectedResult as $itemIndex => $expectedItem) {
|
||||
/** Validate URL to item */
|
||||
$orderIncrementId = substr($expectedItem['id'], strlen('order/1/#'));
|
||||
$this->assertStringContainsString(
|
||||
"order/view/order_id/{$orderIdByIncrementId[$orderIncrementId]}",
|
||||
$searchResults[$itemIndex]['url'],
|
||||
'Item URL is invalid.'
|
||||
);
|
||||
$expectedItem['id'] = 'order/1/' . $orderIdByIncrementId[$orderIncrementId];
|
||||
unset($searchResults[$itemIndex]['url']);
|
||||
|
||||
/** Validate other item data */
|
||||
foreach ($expectedItem as $field => $value) {
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
(string)$searchResults[$itemIndex][$field],
|
||||
"Data of item #$itemIndex is invalid."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadDataProvider()
|
||||
{
|
||||
return [
|
||||
'All items, first page' => [
|
||||
'10000000',
|
||||
2, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'order/1/#100000001',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000001',
|
||||
'description' => 'firstname lastname',
|
||||
],
|
||||
[
|
||||
'id' => 'order/1/#100000002',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000002',
|
||||
'description' => 'guest guest'
|
||||
]
|
||||
],
|
||||
],
|
||||
'All items, second page' => [
|
||||
'10000000',
|
||||
2, // Items on page
|
||||
2, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'order/1/#100000003',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000003',
|
||||
'description' => 'guest guest',
|
||||
]
|
||||
],
|
||||
],
|
||||
'Search by first name, first item only' => [
|
||||
'First',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'order/1/#100000001',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000001',
|
||||
'description' => 'firstname lastname',
|
||||
]
|
||||
],
|
||||
],
|
||||
'No results' => [
|
||||
'NotExistingOrder',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[],
|
||||
],
|
||||
'Search by last name, first item only' => [
|
||||
'last',
|
||||
10, // Items on page
|
||||
1, // Page number
|
||||
[
|
||||
[
|
||||
'id' => 'order/1/#100000001',
|
||||
'type' => 'Order',
|
||||
'name' => 'Order #100000001',
|
||||
'description' => 'firstname lastname',
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||
<system>
|
||||
<tab id="test" translate="label" sortOrder="100">
|
||||
<label>Test Tab</label>
|
||||
</tab>
|
||||
<section id="test_section" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="0">
|
||||
<label>Test Section</label>
|
||||
<tab>test</tab>
|
||||
<resource>Magento_Backend::test</resource>
|
||||
<group id="test_group" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="10">
|
||||
<label>Test Group</label>
|
||||
<field id="test_field_1" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
|
||||
<label>Test Field</label>
|
||||
</field>
|
||||
<field id="test_field_2" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
|
||||
<label>Test Field</label>
|
||||
</field>
|
||||
</group>
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Model\Session;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Model\Session\AdminConfig.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class AdminConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()
|
||||
->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$model = $this->objectManager->create(\Magento\Backend\Model\Session\AdminConfig::class);
|
||||
$this->assertEquals('/index.php/backend', $model->getCookiePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setting session name for admin
|
||||
*
|
||||
*/
|
||||
public function testSetSessionNameByConstructor()
|
||||
{
|
||||
$sessionName = 'adminHtmlSession';
|
||||
$adminConfig = $this->objectManager->create(
|
||||
\Magento\Backend\Model\Session\AdminConfig::class,
|
||||
['sessionName' => $sessionName]
|
||||
);
|
||||
$this->assertSame($sessionName, $adminConfig->getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Model\Session;
|
||||
|
||||
/**
|
||||
* Class QuoteTest
|
||||
*/
|
||||
class QuoteTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetQuote()
|
||||
{
|
||||
/** Preconditions */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$fixtureCustomerId = 1;
|
||||
/** @var \Magento\Backend\Model\Session\Quote $backendQuoteSession */
|
||||
$backendQuoteSession = $objectManager->get(\Magento\Backend\Model\Session\Quote::class);
|
||||
$backendQuoteSession->setCustomerId($fixtureCustomerId);
|
||||
/** @var \Magento\Backend\Model\Session\Quote $quoteSession */
|
||||
$quoteSession = $objectManager->create(\Magento\Backend\Model\Session\Quote::class);
|
||||
$quoteSession->setEntity(new \Magento\Framework\DataObject());
|
||||
|
||||
/** SUT execution */
|
||||
$quote = $quoteSession->getQuote();
|
||||
|
||||
/** Ensure that customer data was added to quote correctly */
|
||||
$this->assertEquals(
|
||||
'John',
|
||||
$quote->getCustomer()->getFirstname(),
|
||||
'Customer data was set to quote incorrectly.'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Model;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Model\Session.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class SessionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testContructor()
|
||||
{
|
||||
if (array_key_exists('adminhtml', $_SESSION)) {
|
||||
unset($_SESSION['adminhtml']);
|
||||
}
|
||||
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Backend\Model\Session::class,
|
||||
[$logger]
|
||||
);
|
||||
$this->assertArrayHasKey('adminhtml', $_SESSION);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Model\Translate;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class InlineTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Translate\InlineInterface
|
||||
*/
|
||||
protected $_translateInline;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_translateInline = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\Translate\InlineInterface::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAdminConfigFixture dev/translate_inline/active_admin 1
|
||||
* @covers \Magento\Framework\Translate\Inline::getAjaxUrl
|
||||
*/
|
||||
public function testAjaxUrl()
|
||||
{
|
||||
$body = '<html><body>some body</body></html>';
|
||||
/** @var \Magento\Backend\Model\UrlInterface $url */
|
||||
$url = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\UrlInterface::class);
|
||||
$url->getUrl(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE . '/ajax/translate');
|
||||
$this->_translateInline->processResponseBody($body, true);
|
||||
$expected = str_replace(
|
||||
[':', '/'],
|
||||
['\u003A', '\u002F'],
|
||||
$url->getUrl(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE . '/ajax/translate')
|
||||
);
|
||||
$this->assertStringContainsString($expected, $body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Model;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Encryption\EncryptorInterface;
|
||||
use Magento\Framework\Escaper;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Session\SessionManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Backend\Model\UrlInterface.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class UrlTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var UrlInterface
|
||||
*/
|
||||
private $_model;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->request = $this->objectManager->get(RequestInterface::class);
|
||||
$this->_model = $this->objectManager->create(UrlInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* App isolation is enabled to protect next tests from polluted registry by getUrl().
|
||||
*
|
||||
* @param string $routePath
|
||||
* @param array $requestParams
|
||||
* @param string $expectedResult
|
||||
* @param array|null $routeParams
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider getUrlDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetUrl(
|
||||
string $routePath,
|
||||
array $requestParams,
|
||||
string $expectedResult,
|
||||
$routeParams = null
|
||||
): void {
|
||||
$this->request->setParams($requestParams);
|
||||
$url = $this->_model->getUrl($routePath, $routeParams);
|
||||
|
||||
$this->assertStringContainsString($expectedResult, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for getUrl method.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUrlDataProvider(): array
|
||||
{
|
||||
/** @var $escaper Escaper */
|
||||
$escaper = Bootstrap::getObjectManager()->get(Escaper::class);
|
||||
|
||||
return [
|
||||
[
|
||||
'routePath' => 'adminhtml/auth/login',
|
||||
'requestParams' => [],
|
||||
'expectedResult'=> 'admin/auth/login/key/',
|
||||
],
|
||||
[
|
||||
'routePath' => 'adminhtml/auth/login',
|
||||
'requestParams' => [],
|
||||
'expectedResult'=> '/param1/a1==/',
|
||||
'routeParams' => [
|
||||
'_escape_params' => false,
|
||||
'param1' => 'a1==',
|
||||
],
|
||||
],
|
||||
[
|
||||
'routePath' => 'adminhtml/auth/login',
|
||||
'requestParams' => [],
|
||||
'expectedResult'=> '/param1/a1==/',
|
||||
'routeParams' => [
|
||||
'_escape_params' => false,
|
||||
'param1' => 'a1==',
|
||||
],
|
||||
],
|
||||
[
|
||||
'routePath' => 'adminhtml/auth/login',
|
||||
'requestParams' => ['param2' => 'a2=='],
|
||||
'expectedResult'=> '/param2/a2==/',
|
||||
'routeParams' => [
|
||||
'_current' => true,
|
||||
'_escape_params' => false,
|
||||
],
|
||||
],
|
||||
[
|
||||
'routePath' => 'adminhtml/auth/login',
|
||||
'requestParams' => [],
|
||||
'expectedResult' => '/param3/' . $escaper->encodeUrlParam('a3==') . '/',
|
||||
'routeParams' => [
|
||||
'_escape_params' => true,
|
||||
'param3' => 'a3==',
|
||||
],
|
||||
],
|
||||
[
|
||||
'routePath' => 'adminhtml/auth/login',
|
||||
'requestParams' => ['param4' => 'a4=='],
|
||||
'expectedResult' => '/param4/' . $escaper->encodeUrlParam('a4==') . '/',
|
||||
'routeParams' => [
|
||||
'_current' => true,
|
||||
'_escape_params' => true,
|
||||
],
|
||||
],
|
||||
[
|
||||
'routePath' => 'route/controller/action/id/100',
|
||||
'requestParams' => [],
|
||||
'expectedResult' => 'id/100',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $routeName
|
||||
* @param string $controller
|
||||
* @param string $action
|
||||
* @param string $expectedHash
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider getSecretKeyDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetSecretKey(string $routeName, string $controller, string $action, string $expectedHash): void
|
||||
{
|
||||
$this->request->setControllerName('default_controller')
|
||||
->setActionName('default_action')
|
||||
->setRouteName('default_router');
|
||||
|
||||
$this->_model->setRequest($this->request);
|
||||
$this->objectManager->get(SessionManagerInterface::class)->setData('_form_key', 'salt');
|
||||
|
||||
$this->assertEquals($expectedHash, $this->_model->getSecretKey($routeName, $controller, $action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSecretKeyDataProvider(): array
|
||||
{
|
||||
/** @var $encryptor EncryptorInterface */
|
||||
$encryptor = Bootstrap::getObjectManager()->get(EncryptorInterface::class);
|
||||
|
||||
return [
|
||||
[
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
$encryptor->getHash('default_router' . 'default_controller' . 'default_action' . 'salt'),
|
||||
],
|
||||
['', '', 'action', $encryptor->getHash('default_router' . 'default_controller' . 'action' . 'salt')],
|
||||
[
|
||||
'',
|
||||
'controller',
|
||||
'',
|
||||
$encryptor->getHash('default_router' . 'controller' . 'default_action' . 'salt'),
|
||||
],
|
||||
[
|
||||
'',
|
||||
'controller',
|
||||
'action',
|
||||
$encryptor->getHash('default_router' . 'controller' . 'action' . 'salt'),
|
||||
],
|
||||
[
|
||||
'adminhtml',
|
||||
'',
|
||||
'',
|
||||
$encryptor->getHash('adminhtml' . 'default_controller' . 'default_action' . 'salt'),
|
||||
],
|
||||
[
|
||||
'adminhtml',
|
||||
'',
|
||||
'action',
|
||||
$encryptor->getHash('adminhtml' . 'default_controller' . 'action' . 'salt'),
|
||||
],
|
||||
[
|
||||
'adminhtml',
|
||||
'controller',
|
||||
'',
|
||||
$encryptor->getHash('adminhtml' . 'controller' . 'default_action' . 'salt'),
|
||||
],
|
||||
[
|
||||
'adminhtml',
|
||||
'controller',
|
||||
'action',
|
||||
$encryptor->getHash('adminhtml' . 'controller' . 'action' . 'salt'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSecretKeyForwarded(): void
|
||||
{
|
||||
/** @var $encryptor EncryptorInterface */
|
||||
$encryptor = $this->objectManager->get(EncryptorInterface::class);
|
||||
|
||||
$this->request->setControllerName('controller')->setActionName('action');
|
||||
$this->request->initForward()->setControllerName(uniqid())->setActionName(uniqid());
|
||||
$this->_model->setRequest($this->request);
|
||||
$this->objectManager->get(SessionManagerInterface::class)->setData('_form_key', 'salt');
|
||||
|
||||
$this->assertEquals($encryptor->getHash('controller' . 'action' . 'salt'), $this->_model->getSecretKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testUseSecretKey(): void
|
||||
{
|
||||
$this->_model->setNoSecret(true);
|
||||
$this->assertFalse($this->_model->useSecretKey());
|
||||
|
||||
$this->_model->setNoSecret(false);
|
||||
$this->assertTrue($this->_model->useSecretKey());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
|
||||
use Magento\Framework\App\Config\ReinitableConfigInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ConfigInterface $config */
|
||||
$config = $objectManager->get(ConfigInterface::class);
|
||||
$config->saveConfig('general/country/allow', 'FR');
|
||||
$objectManager->get(ReinitableConfigInterface::class)->reinit();
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
|
||||
use Magento\Framework\App\Config\ReinitableConfigInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ConfigInterface $config */
|
||||
$config = $objectManager->get(ConfigInterface::class);
|
||||
$config->deleteConfig('general/country/allow');
|
||||
$objectManager->get(ReinitableConfigInterface::class)->reinit();
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var $cacheTypeList \Magento\Framework\App\Cache\TypeListInterface */
|
||||
$cacheTypeList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Cache\TypeListInterface::class
|
||||
);
|
||||
$cacheTypeList->invalidate(array_keys($cacheTypeList->getTypes()));
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Backend/controllers/_files/cache/empty_storage.php'
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var $cache \Magento\Framework\App\Cache */
|
||||
$cache = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Framework\App\Cache::class);
|
||||
$cache->save('application data', 'APPLICATION_FIXTURE');
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Backend/controllers/_files/cache/empty_storage.php'
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var $cache \Magento\Framework\App\Cache */
|
||||
$cache = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Framework\App\Cache::class);
|
||||
$cache->clean();
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var $cachePool \Magento\Framework\App\Cache\Frontend\Pool */
|
||||
$cachePool = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Framework\App\Cache\Frontend\Pool::class);
|
||||
/** @var $cacheFrontend \Magento\Framework\Cache\FrontendInterface */
|
||||
foreach ($cachePool as $cacheFrontend) {
|
||||
$cacheFrontend->getBackend()->save('non-application cache data', 'NON_APPLICATION_FIXTURE', ['SOME_TAG']);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Backend/controllers/_files/cache/empty_storage.php'
|
||||
);
|
||||