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); } }