CreateTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Customer\Test\Unit\Controller\Account;
  8. class CreateTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Customer\Controller\Account\Create
  12. */
  13. protected $object;
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $customerSession;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $registrationMock;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $redirectMock;
  26. /**
  27. * @var \PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $response;
  30. /**
  31. * @var \Magento\Framework\Controller\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject
  32. */
  33. protected $redirectFactoryMock;
  34. /**
  35. * @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject
  36. */
  37. protected $redirectResultMock;
  38. /**
  39. * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject
  40. */
  41. protected $resultPageMock;
  42. /**
  43. * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject
  44. */
  45. protected $pageFactoryMock;
  46. protected function setUp()
  47. {
  48. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  49. $this->customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
  50. $this->registrationMock = $this->createMock(\Magento\Customer\Model\Registration::class);
  51. $this->redirectMock = $this->createMock(\Magento\Framework\App\Response\RedirectInterface::class);
  52. $this->response = $this->createMock(\Magento\Framework\App\ResponseInterface::class);
  53. $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
  54. ->disableOriginalConstructor()->getMock();
  55. $this->redirectResultMock = $this->createMock(\Magento\Framework\Controller\Result\Redirect::class);
  56. $this->redirectFactoryMock = $this->createPartialMock(
  57. \Magento\Framework\Controller\Result\RedirectFactory::class,
  58. ['create']
  59. );
  60. $this->resultPageMock = $this->createMock(\Magento\Framework\View\Result\Page::class);
  61. $this->pageFactoryMock = $this->createMock(\Magento\Framework\View\Result\PageFactory::class);
  62. $this->object = $objectManager->getObject(
  63. \Magento\Customer\Controller\Account\Create::class,
  64. [
  65. 'request' => $this->request,
  66. 'response' => $this->response,
  67. 'customerSession' => $this->customerSession,
  68. 'registration' => $this->registrationMock,
  69. 'redirect' => $this->redirectMock,
  70. 'resultRedirectFactory' => $this->redirectFactoryMock,
  71. 'resultPageFactory' => $this->pageFactoryMock
  72. ]
  73. );
  74. }
  75. /**
  76. * @return void
  77. */
  78. public function testCreateActionRegistrationDisabled()
  79. {
  80. $this->customerSession->expects($this->once())
  81. ->method('isLoggedIn')
  82. ->will($this->returnValue(false));
  83. $this->registrationMock->expects($this->once())
  84. ->method('isAllowed')
  85. ->will($this->returnValue(false));
  86. $this->redirectFactoryMock->expects($this->once())
  87. ->method('create')
  88. ->willReturn($this->redirectResultMock);
  89. $this->redirectResultMock->expects($this->once())
  90. ->method('setPath')
  91. ->with('*/*')
  92. ->willReturnSelf();
  93. $this->resultPageMock->expects($this->never())
  94. ->method('getLayout');
  95. $this->object->execute();
  96. }
  97. /**
  98. * @return void
  99. */
  100. public function testCreateActionRegistrationEnabled()
  101. {
  102. $this->customerSession->expects($this->once())
  103. ->method('isLoggedIn')
  104. ->will($this->returnValue(false));
  105. $this->registrationMock->expects($this->once())
  106. ->method('isAllowed')
  107. ->will($this->returnValue(true));
  108. $this->redirectMock->expects($this->never())
  109. ->method('redirect');
  110. $this->pageFactoryMock->expects($this->once())
  111. ->method('create')
  112. ->willReturn($this->resultPageMock);
  113. $this->object->execute();
  114. }
  115. }