|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\Captcha\Test\Unit\Plugin; |
| 10 | + |
| 11 | +use Magento\Captcha\Model\ResourceModel\Log; |
| 12 | +use Magento\Captcha\Model\ResourceModel\LogFactory; |
| 13 | +use Magento\Captcha\Plugin\FrontendOrderPlacementPlugin; |
| 14 | +use Magento\Captcha\Helper\Data as HelperCaptcha; |
| 15 | +use Magento\Captcha\Model\DefaultModel; |
| 16 | +use Magento\Sales\Api\Data\OrderInterface; |
| 17 | +use Magento\Sales\Api\OrderManagementInterface; |
| 18 | +use PHPUnit\Framework\TestCase; |
| 19 | + |
| 20 | +/** |
| 21 | + * Unit test for \Magento\Captcha\Observer\FrontendOrderPlacementPluginTest |
| 22 | + */ |
| 23 | +class FrontendOrderPlacementPluginTest extends TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * Test that the method resets attempts for frontend checkout |
| 27 | + */ |
| 28 | + public function testExecuteExpectsDeleteUserAttemptsCalled() |
| 29 | + { |
| 30 | + $orderManagementInterfaceMock = $this->getMockForAbstractClass(OrderManagementInterface::class); |
| 31 | + $resultOrderMock = $this->createMock(OrderInterface::class); |
| 32 | + $orderMock = $this->createMock(OrderInterface::class); |
| 33 | + $orderMock-> expects( $this-> once())-> method( 'getCustomerEmail')-> willReturn( '[email protected]'); |
| 34 | + $captchaModelMock = $this->createMock(DefaultModel::class); |
| 35 | + $captchaModelMock->expects($this->once())->method('setShowCaptchaInSession')->with(false)->willReturnSelf(); |
| 36 | + $helperCaptchaMock = $this->createMock(HelperCaptcha::class); |
| 37 | + $helperCaptchaMock->expects($this->once())->method('getCaptcha')->willReturn($captchaModelMock); |
| 38 | + $logMock = $this->createMock(Log::class); |
| 39 | + $logMock->expects($this->once())->method('deleteUserAttempts')->willReturnSelf(); |
| 40 | + $resLogFactoryMock = $this->createMock(LogFactory::class); |
| 41 | + $resLogFactoryMock->expects($this->once())->method('create')->willReturn($logMock); |
| 42 | + $observer = new FrontendOrderPlacementPlugin($helperCaptchaMock, $resLogFactoryMock); |
| 43 | + $observer->afterPlace($orderManagementInterfaceMock, $resultOrderMock, $orderMock); |
| 44 | + } |
| 45 | +} |
0 commit comments