|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\User\Controller\Adminhtml\User\Role; |
| 10 | + |
| 11 | +use Magento\Framework\Registry; |
| 12 | +use Magento\Store\Model\Store; |
| 13 | +use Magento\TestFramework\Helper\Bootstrap; |
| 14 | +use Magento\User\Controller\Adminhtml\User\Role\SaveRole; |
| 15 | + |
| 16 | +/** |
| 17 | + * Test class for \Magento\User\Controller\Adminhtml\User\Role\SaveRole. |
| 18 | + * |
| 19 | + * @magentoAppArea adminhtml |
| 20 | + */ |
| 21 | +class SaveRoleTest extends \Magento\TestFramework\TestCase\AbstractBackendController |
| 22 | +{ |
| 23 | + /** |
| 24 | + * Test execute method for different scopes |
| 25 | + * |
| 26 | + * @magentoDataFixture Magento/User/_files/user_with_custom_role.php |
| 27 | + * @magentoDataFixture Magento/Store/_files/multiple_websites_with_store_groups_stores.php |
| 28 | + */ |
| 29 | + public function testExecuteWithDifferentScopes() |
| 30 | + { |
| 31 | + $objectManager = Bootstrap::getObjectManager(); |
| 32 | + $store = $objectManager->get(Store::class); |
| 33 | + $store->load('third_store_view', 'code'); |
| 34 | + |
| 35 | + /** @var \Magento\Authorization\Model\RoleFactory $roleFactory */ |
| 36 | + $roleFactory = $objectManager->create(\Magento\Authorization\Model\RoleFactory::class); |
| 37 | + $role = $roleFactory->create()->load('test_custom_role', 'role_name'); |
| 38 | + $roleId = $role->getId(); |
| 39 | + |
| 40 | + $post = [ |
| 41 | + 'role_id' => $roleId, |
| 42 | + 'in_role_user_old'=> '', |
| 43 | + 'in_role_user'=> '', |
| 44 | + 'all' => 1, |
| 45 | + 'current_password' => 'password1', |
| 46 | + 'rolename' => $role->getRoleName(), |
| 47 | + 'gws_is_all' => 0, |
| 48 | + 'gws_websites' => [1, (int)$store->getWebsiteId()], |
| 49 | + ]; |
| 50 | + |
| 51 | + $this->getRequest()->setPostValue($post); |
| 52 | + |
| 53 | + $model = $objectManager->create(SaveRole::class); |
| 54 | + $model->execute(); |
| 55 | + |
| 56 | + /** @var \Magento\Authorization\Model\RoleFactory $roleFactory */ |
| 57 | + $roleFactory = $objectManager->create(\Magento\Authorization\Model\RoleFactory::class); |
| 58 | + $role = $roleFactory->create()->load($roleId); |
| 59 | + $this->assertEquals(2, count($role->getGwsWebsites())); |
| 60 | + |
| 61 | + $post = [ |
| 62 | + 'role_id' => $roleId, |
| 63 | + 'in_role_user_old'=> '', |
| 64 | + 'in_role_user'=> '', |
| 65 | + 'all' => 1, |
| 66 | + 'current_password' => 'password1', |
| 67 | + 'rolename' => $role->getRoleName(), |
| 68 | + 'gws_is_all' => 1, |
| 69 | + ]; |
| 70 | + |
| 71 | + $this->getRequest()->setPostValue($post); |
| 72 | + |
| 73 | + $registry = $objectManager->get(Registry::class); |
| 74 | + $registry->unregister('current_role'); |
| 75 | + |
| 76 | + $model = $objectManager->create(SaveRole::class); |
| 77 | + $model->execute(); |
| 78 | + |
| 79 | + /** @var \Magento\Authorization\Model\RoleFactory $roleFactory */ |
| 80 | + $roleFactory = $objectManager->create(\Magento\Authorization\Model\RoleFactory::class); |
| 81 | + $role = $roleFactory->create()->load($roleId); |
| 82 | + $this->assertNull($role->getGwsWebsites()); |
| 83 | + } |
| 84 | +} |
0 commit comments