ltsecurityinc安防产品在线商城代码
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Authorization\Model\ResourceModel\Role;
|
||||
|
||||
use Magento\Authorization\Model\UserContextInterface;
|
||||
|
||||
/**
|
||||
* Role collection test
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Authorization\Model\ResourceModel\Role\Collection
|
||||
*/
|
||||
protected $_collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Authorization\Model\ResourceModel\Role\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetUserFilter()
|
||||
{
|
||||
$user = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\User\Model\User::class);
|
||||
$user->loadByUsername(\Magento\TestFramework\Bootstrap::ADMIN_NAME);
|
||||
$this->_collection->setUserFilter($user->getId(), UserContextInterface::USER_TYPE_ADMIN);
|
||||
|
||||
$selectQueryStr = $this->_collection->getSelect()->__toString();
|
||||
|
||||
$this->assertStringContainsString('user_id', $selectQueryStr);
|
||||
$this->assertStringContainsString('user_type', $selectQueryStr);
|
||||
}
|
||||
|
||||
public function testSetRolesFilter()
|
||||
{
|
||||
$this->_collection->setRolesFilter();
|
||||
|
||||
$this->assertStringContainsString('role_type', $this->_collection->getSelect()->__toString());
|
||||
}
|
||||
|
||||
public function testToOptionArray()
|
||||
{
|
||||
$this->assertNotEmpty($this->_collection->toOptionArray());
|
||||
|
||||
foreach ($this->_collection->toOptionArray() as $item) {
|
||||
$this->assertArrayHasKey('value', $item);
|
||||
$this->assertArrayHasKey('label', $item);
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Authorization\Model\ResourceModel\Role\Grid;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Authorization\Model\ResourceModel\Role\Grid\Collection
|
||||
*/
|
||||
private $_collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Authorization\Model\ResourceModel\Role\Grid\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetItems()
|
||||
{
|
||||
$expectedResult = [
|
||||
[
|
||||
'role_type' => \Magento\Authorization\Model\Acl\Role\Group::ROLE_TYPE,
|
||||
'role_name' => \Magento\TestFramework\Bootstrap::ADMIN_ROLE_NAME,
|
||||
],
|
||||
];
|
||||
$actualResult = [];
|
||||
/** @var \Magento\Reports\Model\Item $reportItem */
|
||||
foreach ($this->_collection->getItems() as $reportItem) {
|
||||
$actualResult[] = array_intersect_key($reportItem->getData(), $expectedResult[0]);
|
||||
}
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Authorization\Model\ResourceModel;
|
||||
|
||||
/**
|
||||
* Role resource test
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class RoleTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetRoleUsers()
|
||||
{
|
||||
$role = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Authorization\Model\Role::class
|
||||
);
|
||||
$roleResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Authorization\Model\ResourceModel\Role::class
|
||||
);
|
||||
|
||||
$this->assertEmpty($roleResource->getRoleUsers($role));
|
||||
|
||||
$role->load(\Magento\TestFramework\Bootstrap::ADMIN_ROLE_NAME, 'role_name');
|
||||
$this->assertNotEmpty($roleResource->getRoleUsers($role));
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Authorization\Model\ResourceModel\Rules;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Authorization\Model\ResourceModel\Rules\Collection
|
||||
*/
|
||||
protected $_collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Authorization\Model\ResourceModel\Rules\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetByRoles()
|
||||
{
|
||||
$user = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\User\Model\User::class);
|
||||
$user->loadByUsername(\Magento\TestFramework\Bootstrap::ADMIN_NAME);
|
||||
$this->_collection->getByRoles($user->getRole()->getId());
|
||||
|
||||
$where = $this->_collection->getSelect()->getPart(\Magento\Framework\DB\Select::WHERE);
|
||||
/** @var \Magento\Framework\DB\Adapter\Pdo\Mysql $connection */
|
||||
$connection = $this->_collection->getConnection();
|
||||
$quote = $connection->getQuoteIdentifierSymbol();
|
||||
$this->assertContains("({$quote}role_id{$quote} = '" . $user->getRole()->getId() . "')", $where);
|
||||
}
|
||||
|
||||
public function testAddSortByLength()
|
||||
{
|
||||
$this->_collection->addSortByLength();
|
||||
|
||||
$order = $this->_collection->getSelect()->getPart(\Magento\Framework\DB\Select::ORDER);
|
||||
$this->assertContains(['length', 'DESC'], $order);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user