AccountConfirmationTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Model;
  7. use Magento\Customer\Model\AccountConfirmation;
  8. use Magento\Store\Model\ScopeInterface;
  9. use Magento\Framework\App\Config\ScopeConfigInterface;
  10. use Magento\Framework\Registry;
  11. /**
  12. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  13. */
  14. class AccountConfirmationTest extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * @var AccountConfirmation|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $accountConfirmation;
  20. /**
  21. * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. private $scopeConfig;
  24. /**
  25. * @var Registry|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. private $registry;
  28. protected function setUp()
  29. {
  30. $this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
  31. $this->registry = $this->createMock(Registry::class);
  32. $this->accountConfirmation = new AccountConfirmation(
  33. $this->scopeConfig,
  34. $this->registry
  35. );
  36. }
  37. /**
  38. * @param $customerId
  39. * @param $customerEmail
  40. * @param $skipConfirmationIfEmail
  41. * @param $isConfirmationEnabled
  42. * @param $expected
  43. * @dataProvider dataProviderIsConfirmationRequired
  44. */
  45. public function testIsConfirmationRequired(
  46. $customerId,
  47. $customerEmail,
  48. $skipConfirmationIfEmail,
  49. $isConfirmationEnabled,
  50. $expected
  51. ) {
  52. $websiteId = 1;
  53. $this->scopeConfig->expects($this->any())
  54. ->method('isSetFlag')
  55. ->with(
  56. $this->accountConfirmation::XML_PATH_IS_CONFIRM,
  57. ScopeInterface::SCOPE_WEBSITES,
  58. $websiteId
  59. )->willReturn($isConfirmationEnabled);
  60. $this->registry->expects($this->any())
  61. ->method('registry')
  62. ->with('skip_confirmation_if_email')
  63. ->willReturn($skipConfirmationIfEmail);
  64. self::assertEquals(
  65. $expected,
  66. $this->accountConfirmation->isConfirmationRequired($websiteId, $customerId, $customerEmail)
  67. );
  68. }
  69. /**
  70. * @return array
  71. */
  72. public function dataProviderIsConfirmationRequired()
  73. {
  74. return [
  75. [null, 'customer@example.com', null, true, true],
  76. [null, 'customer@example.com', null, false, false],
  77. [1, 'customer@example.com', 'customer@example.com', true, false],
  78. [1, 'customer@example.com', 'customer1@example.com', false, false],
  79. [1, 'customer@example.com', 'customer1@example.com', true, true],
  80. ];
  81. }
  82. }