1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Block\Adminhtml\Group;
use Magento\Customer\Api\GroupManagementInterface;
use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Controller\RegistryConstants;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\AbstractController;
/**
* Magento\Customer\Block\Adminhtml\Group\Edit
*
* @magentoAppArea adminhtml
*/
class EditTest extends AbstractController
{
/**
* @var \Magento\Framework\View\LayoutInterface
*/
private $layout;
/**
* @var GroupRepositoryInterface
*/
private $groupRepository;
/**
* @var GroupManagementInterface
*/
private $groupManagement;
/**
* @var \Magento\Framework\Registry
*/
private $registry;
/**
* Execute per test initialization.
*/
public function setUp()
{
parent::setUp();
$this->layout = Bootstrap::getObjectManager()->get(\Magento\Framework\View\LayoutInterface::class);
$this->groupRepository = Bootstrap::getObjectManager()->create(
\Magento\Customer\Api\GroupRepositoryInterface::class
);
$this->groupManagement = Bootstrap::getObjectManager()->create(
\Magento\Customer\Api\GroupManagementInterface::class
);
$this->registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
}
/**
* Execute per test cleanup.
*/
public function tearDown()
{
$this->registry->unregister(RegistryConstants::CURRENT_GROUP_ID);
}
/**
* Verify that the Delete button does not exist for the default group.
* @magentoAppIsolation enabled
*/
public function testDeleteButtonNotExistInDefaultGroup()
{
$groupId = $this->groupManagement->getDefaultGroup(0)->getId();
$this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $groupId);
$this->getRequest()->setParam('id', $groupId);
/** @var $block Edit */
$block = $this->layout->createBlock(\Magento\Customer\Block\Adminhtml\Group\Edit::class, 'block');
$buttonsHtml = $block->getButtonsHtml();
$this->assertNotContains('delete', $buttonsHtml);
}
/**
* @magentoDataFixture Magento/Customer/_files/customer_group.php
*/
public function testDeleteButtonExistInCustomGroup()
{
$builder = Bootstrap::getObjectManager()->create(\Magento\Framework\Api\FilterBuilder::class);
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria */
$searchCriteria = Bootstrap::getObjectManager()
->create(\Magento\Framework\Api\SearchCriteriaBuilder::class)
->addFilters([$builder->setField('code')->setValue('custom_group')->create()])->create();
$customerGroup = $this->groupRepository->getList($searchCriteria)->getItems()[0];
$this->getRequest()->setParam('id', $customerGroup->getId());
$this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $customerGroup->getId());
/** @var $block Edit */
$block = $this->layout->createBlock(\Magento\Customer\Block\Adminhtml\Group\Edit::class, 'block');
$buttonsHtml = $block->getButtonsHtml();
$this->assertContains('delete', $buttonsHtml);
}
}