36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?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);
|
|
}
|
|
}
|