GenderTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block\Widget;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. /**
  9. * @magentoAppArea frontend
  10. */
  11. class GenderTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /** @var Gender */
  14. protected $_block;
  15. /** @var \Magento\Customer\Model\Attribute */
  16. private $_model;
  17. /**
  18. * Test initialization and set up. Create the Gender block.
  19. * @return void
  20. */
  21. protected function setUp()
  22. {
  23. $objectManager = Bootstrap::getObjectManager();
  24. $objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
  25. $this->_block = $objectManager->get(
  26. \Magento\Framework\View\LayoutInterface::class
  27. )->createBlock(
  28. \Magento\Customer\Block\Widget\Gender::class
  29. );
  30. $this->_model = $objectManager->create(\Magento\Customer\Model\Attribute::class);
  31. $this->_model->loadByCode('customer', 'gender');
  32. }
  33. /**
  34. * Test the Gender::getGenderOptions() method.
  35. * @return void
  36. */
  37. public function testGetGenderOptions()
  38. {
  39. $options = $this->_block->getGenderOptions();
  40. $this->assertInternalType('array', $options);
  41. $this->assertNotEmpty($options);
  42. $this->assertContainsOnlyInstancesOf(\Magento\Customer\Model\Data\Option::class, $options);
  43. }
  44. /**
  45. * Test the Gender::toHtml() method.
  46. * @return void
  47. */
  48. public function testToHtml()
  49. {
  50. $html = $this->_block->toHtml();
  51. $attributeLabel = $this->_model->getStoreLabel();
  52. $this->assertContains('<span>' . $attributeLabel . '</span>', $html);
  53. $this->assertContains('<option value="1">Male</option>', $html);
  54. $this->assertContains('<option value="2">Female</option>', $html);
  55. $this->assertContains('<option value="3">Not Specified</option>', $html);
  56. }
  57. }