init
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Cart\Test\Unit\Plugin\TestMode;
|
||||
|
||||
use Esun\Cart\Model\TestModeConfig;
|
||||
use Esun\Cart\Plugin\TestMode\RestrictAddToCartPlugin;
|
||||
use Magento\Checkout\Model\Cart;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RestrictAddToCartPluginTest extends TestCase
|
||||
{
|
||||
public function testAllowsAddToCartWhenCustomerIsNotRestricted(): void
|
||||
{
|
||||
$config = $this->createMock(TestModeConfig::class);
|
||||
$config->method('isRestricted')->willReturn(false);
|
||||
|
||||
$plugin = new RestrictAddToCartPlugin($config);
|
||||
|
||||
self::assertNull($plugin->beforeAddProduct($this->createMock(Cart::class), 10));
|
||||
}
|
||||
|
||||
public function testRejectsAddToCartWhenCustomerIsRestricted(): void
|
||||
{
|
||||
$config = $this->createMock(TestModeConfig::class);
|
||||
$config->method('isRestricted')->willReturn(true);
|
||||
|
||||
$plugin = new RestrictAddToCartPlugin($config);
|
||||
|
||||
$this->expectException(LocalizedException::class);
|
||||
$this->expectExceptionMessage('Our website is currently in beta testing.');
|
||||
$plugin->beforeAddProduct($this->createMock(Cart::class), 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Cart\Test\Unit\Plugin\TestMode;
|
||||
|
||||
use Esun\Cart\Model\TestModeConfig;
|
||||
use Esun\Cart\Plugin\TestMode\RestrictCheckoutPlugin;
|
||||
use Magento\Checkout\Controller\Index\Index as CheckoutIndex;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Framework\Controller\Result\RedirectFactory;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RestrictCheckoutPluginTest extends TestCase
|
||||
{
|
||||
public function testContinuesToCheckoutWhenCustomerIsNotRestricted(): void
|
||||
{
|
||||
$config = $this->createMock(TestModeConfig::class);
|
||||
$config->method('isRestricted')->willReturn(false);
|
||||
$redirectFactory = $this->createMock(RedirectFactory::class);
|
||||
$expectedResult = $this->createMock(ResultInterface::class);
|
||||
$plugin = new RestrictCheckoutPlugin($config, $redirectFactory);
|
||||
|
||||
$result = $plugin->aroundExecute(
|
||||
$this->createMock(CheckoutIndex::class),
|
||||
static fn (): ResultInterface => $expectedResult
|
||||
);
|
||||
|
||||
self::assertSame($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function testRedirectsRestrictedCustomerToCart(): void
|
||||
{
|
||||
$config = $this->createMock(TestModeConfig::class);
|
||||
$config->method('isRestricted')->willReturn(true);
|
||||
$redirect = $this->createMock(Redirect::class);
|
||||
$redirect->expects(self::once())
|
||||
->method('setPath')
|
||||
->with('checkout/cart', ['_query' => ['purchase_test_mode' => 1]])
|
||||
->willReturnSelf();
|
||||
$redirectFactory = $this->createMock(RedirectFactory::class);
|
||||
$redirectFactory->expects(self::once())->method('create')->willReturn($redirect);
|
||||
$plugin = new RestrictCheckoutPlugin($config, $redirectFactory);
|
||||
|
||||
$result = $plugin->aroundExecute(
|
||||
$this->createMock(CheckoutIndex::class),
|
||||
static fn (): ResultInterface => throw new \LogicException('Checkout must not continue.')
|
||||
);
|
||||
|
||||
self::assertSame($redirect, $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user