EditTest.php 3.3 KB

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