ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -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,
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+47
@@ -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));
|
||||
}
|
||||
}
|
||||
+194
@@ -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']
|
||||
];
|
||||
}
|
||||
}
|
||||
+25
@@ -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');
|
||||
}
|
||||
}
|
||||
+62
@@ -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',
|
||||
''
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+30
@@ -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));
|
||||
}
|
||||
}
|
||||
+84
@@ -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]
|
||||
];
|
||||
}
|
||||
}
|
||||
+21
@@ -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());
|
||||
}
|
||||
}
|
||||
+215
@@ -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.',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+43
@@ -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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user