EditTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block\Adminhtml;
  7. use Magento\Customer\Controller\RegistryConstants;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. /**
  10. * Class EditTest
  11. *
  12. * @magentoAppArea adminhtml
  13. * @magentoDataFixture Magento/Customer/_files/customer.php
  14. */
  15. class EditTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * The edit block under test.
  19. *
  20. * @var Edit
  21. */
  22. private $block;
  23. /**
  24. * Core Registry.
  25. *
  26. * @var \Magento\Framework\Registry
  27. */
  28. private $coreRegistry;
  29. /**
  30. * The customer Id.
  31. *
  32. * @var int
  33. */
  34. private static $customerId = 1;
  35. /**
  36. * Execute per test initialization.
  37. */
  38. public function setUp()
  39. {
  40. $objectManager = Bootstrap::getObjectManager();
  41. $objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('adminhtml');
  42. $this->coreRegistry = $objectManager->get(\Magento\Framework\Registry::class);
  43. $this->coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, self::$customerId);
  44. $this->block = $objectManager->get(
  45. \Magento\Framework\View\LayoutInterface::class
  46. )->createBlock(
  47. \Magento\Customer\Block\Adminhtml\Edit::class,
  48. '',
  49. ['coreRegistry' => $this->coreRegistry]
  50. );
  51. }
  52. /**
  53. * Execute post class cleanup after all tests have executed.
  54. */
  55. public function tearDown()
  56. {
  57. $this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
  58. }
  59. /**
  60. * Verify that the customer Id is the one that was set in the registry.
  61. */
  62. public function testGetCustomerId()
  63. {
  64. $this->assertEquals(self::$customerId, $this->block->getCustomerId());
  65. }
  66. /**
  67. * Verify that the correct order create Url is generated.
  68. */
  69. public function testGetCreateOrderUrl()
  70. {
  71. $this->assertContains(
  72. 'sales/order_create/start/customer_id/' . self::$customerId,
  73. $this->block->getCreateOrderUrl()
  74. );
  75. }
  76. /**
  77. * Verify that the header text is correct for a new customer.
  78. */
  79. public function testGetHeaderTextNewCustomer()
  80. {
  81. $this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
  82. $this->assertEquals('New Customer', $this->block->getHeaderText());
  83. }
  84. /**
  85. * Verify that the header text is correct for an existing customer.
  86. */
  87. public function testGetHeaderTextExistingCustomer()
  88. {
  89. $this->assertEquals('John Smith', $this->block->getHeaderText());
  90. }
  91. /**
  92. * Verify that the correct customer validation Url is generated.
  93. */
  94. public function testGetValidationUrl()
  95. {
  96. $this->assertContains('customer/index/validate', $this->block->getValidationUrl());
  97. }
  98. /**
  99. * Verify the basic content of the block's form Html.
  100. */
  101. public function testGetFormHtml()
  102. {
  103. $html = $this->block->getFormHtml();
  104. $this->assertContains('<div class="entry-edit form-inline">', $html);
  105. $this->assertStringMatchesFormat('%a name="customer_id" %s value="' . self::$customerId . '" %a', $html);
  106. $this->assertContains('id="product_composite_configure_form"', $html);
  107. }
  108. }