ConfirmationTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Controller\Account;
  7. use Magento\Customer\Controller\Account\Confirmation;
  8. use Magento\Framework\App\Request\Http;
  9. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  10. class ConfirmationTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var Confirmation
  14. */
  15. private $model;
  16. /**
  17. * @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $customerSessionMock;
  20. /**
  21. * @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. private $contextMock;
  24. /**
  25. * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. private $resultPageFactoryMock;
  28. /**
  29. * @var \Magento\Customer\Model\Url|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. private $customerUrlMock;
  32. /**
  33. * @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
  34. */
  35. private $requestMock;
  36. public function setUp()
  37. {
  38. $this->customerSessionMock = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
  39. ->disableOriginalConstructor()
  40. ->setMethods(['isLoggedIn'])
  41. ->getMock();
  42. $this->contextMock = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class)
  43. ->disableOriginalConstructor()
  44. ->setMethods(['getRequest'])
  45. ->getMock();
  46. $this->requestMock = $this->getMockBuilder(Http::class)
  47. ->disableOriginalConstructor()
  48. ->setMethods(['getPost', 'getParam'])
  49. ->getMock();
  50. $this->contextMock->expects($this->any())
  51. ->method('getRequest')
  52. ->willReturn($this->requestMock);
  53. $this->resultPageFactoryMock = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class)
  54. ->disableOriginalConstructor()
  55. ->setMethods(['create'])
  56. ->getMock();
  57. $this->customerUrlMock = $this->getMockBuilder(\Magento\Customer\Model\Url::class)
  58. ->disableOriginalConstructor()
  59. ->setMethods(['getLoginUrl'])
  60. ->getMock();
  61. $this->model = (new ObjectManagerHelper($this))->getObject(
  62. Confirmation::class,
  63. [
  64. 'context' => $this->contextMock,
  65. 'customerSession' => $this->customerSessionMock,
  66. 'resultPageFactory' => $this->resultPageFactoryMock,
  67. 'customerUrl' => $this->customerUrlMock,
  68. ]
  69. );
  70. }
  71. public function testGetLoginUrl()
  72. {
  73. $this->customerSessionMock->expects($this->once())
  74. ->method('isLoggedIn')
  75. ->willReturn(false);
  76. $this->requestMock->expects($this->once())->method('getPost')->with('email')->willReturn(null);
  77. $resultPageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class)
  78. ->disableOriginalConstructor()
  79. ->setMethods(['getLayout'])
  80. ->getMock();
  81. $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($resultPageMock);
  82. $layoutMock = $this->getMockBuilder(\Magento\Framework\View\Layout::class)
  83. ->disableOriginalConstructor()
  84. ->setMethods(['getBlock'])
  85. ->getMock();
  86. $resultPageMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
  87. $blockMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template::class)
  88. ->disableOriginalConstructor()
  89. ->setMethods(['setEmail', 'setLoginUrl'])
  90. ->getMock();
  91. $layoutMock->expects($this->once())->method('getBlock')->with('accountConfirmation')->willReturn($blockMock);
  92. $blockMock->expects($this->once())->method('setEmail')->willReturnSelf();
  93. $blockMock->expects($this->once())->method('setLoginUrl')->willReturnSelf();
  94. $this->model->execute();
  95. }
  96. }