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