-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Customer] Removing the delete buttons for default customer groups #26251
Merged
magento-engcom-team
merged 4 commits into
magento:2.4-develop
from
eduard13:customer-default-group-removing
Jan 9, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
313 changes: 313 additions & 0 deletions
313
app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/GroupActionsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,313 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Test\Unit\Ui\Component\Listing\Column; | ||
|
||
use Magento\Customer\Api\GroupManagementInterface; | ||
use Magento\Customer\Ui\Component\Listing\Column\GroupActions; | ||
use Magento\Framework\Escaper; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Framework\View\Element\UiComponent\ContextInterface; | ||
use Magento\Framework\View\Element\UiComponentFactory; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class GroupActionsTest | ||
* | ||
* Testing GroupAction grid column | ||
*/ | ||
class GroupActionsTest extends TestCase | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private const STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_ID = 0; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME = 'Not Logged In'; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private const STUB_GENERAL_CUSTOMER_GROUP_ID = 1; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const STUB_GENERAL_CUSTOMER_GROUP_NAME = 'General'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const STUB_GROUP_EDIT_URL = 'http://magento.com/customer/group/edit'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const STUB_GROUP_DELETE_URL = 'http://magento.com/customer/group/delete'; | ||
|
||
/** | ||
* @var GroupActions | ||
*/ | ||
private $component; | ||
|
||
/** | ||
* @var ContextInterface|MockObject | ||
*/ | ||
private $contextMock; | ||
|
||
/** | ||
* @var UiComponentFactory|MockObject | ||
*/ | ||
private $uiComponentFactoryMock; | ||
|
||
/** | ||
* @var UrlInterface|MockObject | ||
*/ | ||
private $urlBuilderMock; | ||
|
||
/** | ||
* @var Escaper|MockObject | ||
*/ | ||
private $escaperMock; | ||
|
||
/** | ||
* @var GroupManagementInterface|MockObject | ||
*/ | ||
private $groupManagementMock; | ||
|
||
/** | ||
* Set Up | ||
*/ | ||
public function setUp() | ||
{ | ||
$objectManager = new ObjectManager($this); | ||
|
||
$this->contextMock = $this->getMockBuilder(ContextInterface::class)->getMockForAbstractClass(); | ||
$this->uiComponentFactoryMock = $this->createMock(UiComponentFactory::class); | ||
$this->escaperMock = $this->createMock(Escaper::class); | ||
$this->groupManagementMock = $this->createMock(GroupManagementInterface::class); | ||
$this->urlBuilderMock = $this->getMockForAbstractClass( | ||
UrlInterface::class, | ||
[], | ||
'', | ||
false | ||
); | ||
|
||
$this->component = $objectManager->getObject( | ||
GroupActions::class, | ||
[ | ||
'context' => $this->contextMock, | ||
'uiComponentFactory' => $this->uiComponentFactoryMock, | ||
'urlBuilder' => $this->urlBuilderMock, | ||
'escaper' => $this->escaperMock, | ||
'components' => [], | ||
'data' => [ | ||
'name' => 'name' | ||
], | ||
'groupManagement' => $this->groupManagementMock | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Test data source with a non default customer group | ||
* | ||
* @dataProvider customerGroupsDataProvider | ||
* | ||
* @param array $items | ||
* @param bool $isDefaultGroup | ||
* @param array $expected | ||
*/ | ||
public function testPrepareDataSourceWithNonDefaultGroup(array $items, bool $isDefaultGroup, array $expected) | ||
{ | ||
$dataSource = [ | ||
'data' => [ | ||
'items' => $items | ||
] | ||
]; | ||
$expectedDataSource = [ | ||
'data' => [ | ||
'items' => $expected | ||
] | ||
]; | ||
|
||
$this->groupManagementMock->expects($this->any()) | ||
->method('isReadonly') | ||
->with(static::STUB_GENERAL_CUSTOMER_GROUP_ID) | ||
->willReturn($isDefaultGroup); | ||
$this->escaperMock->expects($this->any()) | ||
->method('escapeHtml') | ||
->with(static::STUB_GENERAL_CUSTOMER_GROUP_NAME) | ||
->willReturn(static::STUB_GENERAL_CUSTOMER_GROUP_NAME); | ||
$this->urlBuilderMock->expects($this->any()) | ||
->method('getUrl') | ||
->willReturnMap( | ||
[ | ||
[ | ||
'customer/group/edit', | ||
[ | ||
'id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID | ||
], | ||
static::STUB_GROUP_EDIT_URL], | ||
[ | ||
'customer/group/delete', | ||
[ | ||
'id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID | ||
], | ||
static::STUB_GROUP_DELETE_URL | ||
] | ||
] | ||
); | ||
|
||
$dataSource = $this->component->prepareDataSource($dataSource); | ||
$this->assertEquals($expectedDataSource, $dataSource); | ||
} | ||
|
||
/** | ||
* Test data source with a default customer group | ||
* | ||
* @dataProvider customerGroupsDataProvider | ||
*/ | ||
public function testPrepareDataSourceWithDefaultGroup() | ||
{ | ||
$isDefaultGroup = true; | ||
$dataSource = [ | ||
'data' => [ | ||
'items' => [ | ||
[ | ||
'customer_group_id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID, | ||
'customer_group_code' => static::STUB_GENERAL_CUSTOMER_GROUP_NAME, | ||
], | ||
[ | ||
'customer_group_id' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_ID, | ||
'customer_group_code' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME, | ||
], | ||
] | ||
] | ||
]; | ||
$expectedDataSource = [ | ||
'data' => [ | ||
'items' => [ | ||
[ | ||
'customer_group_id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID, | ||
'customer_group_code' => static::STUB_GENERAL_CUSTOMER_GROUP_NAME, | ||
'name' => [ | ||
'edit' => [ | ||
'href' => static::STUB_GROUP_EDIT_URL, | ||
'label' => __('Edit'), | ||
'__disableTmpl' => true, | ||
] | ||
] | ||
], | ||
[ | ||
'customer_group_id' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_ID, | ||
'customer_group_code' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME, | ||
'name' => [ | ||
'edit' => [ | ||
'href' => static::STUB_GROUP_EDIT_URL, | ||
'label' => __('Edit'), | ||
'__disableTmpl' => true, | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]; | ||
|
||
$this->groupManagementMock->expects($this->any()) | ||
->method('isReadonly') | ||
->willReturn($isDefaultGroup); | ||
$this->escaperMock->expects($this->any()) | ||
->method('escapeHtml') | ||
->willReturnMap( | ||
[ | ||
[ | ||
static::STUB_GENERAL_CUSTOMER_GROUP_NAME, | ||
null, | ||
static::STUB_GENERAL_CUSTOMER_GROUP_NAME | ||
], | ||
[ | ||
static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME, | ||
null, | ||
static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_NAME | ||
] | ||
] | ||
); | ||
$this->urlBuilderMock->expects($this->any()) | ||
->method('getUrl') | ||
->willReturnMap( | ||
[ | ||
[ | ||
'customer/group/edit', | ||
[ | ||
'id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID | ||
], | ||
static::STUB_GROUP_EDIT_URL | ||
], | ||
[ | ||
'customer/group/edit', | ||
[ | ||
'id' => static::STUB_NOT_LOGGED_IN_CUSTOMER_GROUP_ID | ||
], | ||
static::STUB_GROUP_EDIT_URL | ||
] | ||
] | ||
); | ||
|
||
$dataSource = $this->component->prepareDataSource($dataSource); | ||
$this->assertEquals($expectedDataSource, $dataSource); | ||
} | ||
|
||
/** | ||
* Providing customer group data | ||
* | ||
* @return array | ||
*/ | ||
public function customerGroupsDataProvider(): array | ||
{ | ||
return [ | ||
[ | ||
[ | ||
[ | ||
'customer_group_id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID, | ||
'customer_group_code' => static::STUB_GENERAL_CUSTOMER_GROUP_NAME, | ||
], | ||
], | ||
false, | ||
[ | ||
[ | ||
'customer_group_id' => static::STUB_GENERAL_CUSTOMER_GROUP_ID, | ||
'customer_group_code' => static::STUB_GENERAL_CUSTOMER_GROUP_NAME, | ||
'name' => [ | ||
'edit' => [ | ||
'href' => static::STUB_GROUP_EDIT_URL, | ||
'label' => __('Edit'), | ||
'__disableTmpl' => true, | ||
], | ||
'delete' => [ | ||
'href' => static::STUB_GROUP_DELETE_URL, | ||
'label' => __('Delete'), | ||
'post' => true, | ||
'__disableTmpl' => true, | ||
'confirm' => [ | ||
'title' => __('Delete %1', 'General'), | ||
'message' => __( | ||
'Are you sure you want to delete a %1 record?', | ||
'General' | ||
) | ||
], | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one could be just onliner:
But it's minor stuff 👍