55 lines
1.9 KiB
PHP
55 lines
1.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\FreeGift\Test\Unit\Plugin\CustomerData;
|
|
|
|
use Esun\FreeGift\Model\Config;
|
|
use Esun\FreeGift\Plugin\CustomerData\CartPlugin;
|
|
use Magento\Checkout\CustomerData\Cart;
|
|
use Magento\Checkout\Model\Session as CheckoutSession;
|
|
use Magento\Quote\Model\Quote;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class CartPluginTest extends TestCase
|
|
{
|
|
public function testGiftSkuFallbackLocksMinicartItemAndUsesFreeLabel(): void
|
|
{
|
|
$quote = $this->createMock(Quote::class);
|
|
$quote->method('getStoreId')->willReturn(16);
|
|
$quote->method('getAllVisibleItems')->willReturn([]);
|
|
|
|
$checkoutSession = $this->createMock(CheckoutSession::class);
|
|
$checkoutSession->method('getQuote')->willReturn($quote);
|
|
|
|
$config = $this->createMock(Config::class);
|
|
$config->expects(self::once())
|
|
->method('isGiftSku')
|
|
->with('free-gift', 16)
|
|
->willReturn(true);
|
|
|
|
$plugin = new CartPlugin($checkoutSession, $config);
|
|
$result = $plugin->afterGetSectionData(
|
|
$this->createMock(Cart::class),
|
|
[
|
|
'items' => [[
|
|
'item_id' => 42,
|
|
'product_sku' => 'free-gift',
|
|
'product_url' => 'https://example.test/free-gift',
|
|
'product_has_url' => true,
|
|
'configure_url' => 'https://example.test/configure',
|
|
'product_price' => '$0.00',
|
|
'product_price_value' => 0.0,
|
|
]],
|
|
]
|
|
);
|
|
|
|
$item = $result['items'][0];
|
|
self::assertTrue($item['is_esun_free_gift']);
|
|
self::assertSame('Free', (string)$item['line_total']);
|
|
self::assertSame('Free', (string)$item['product_price']);
|
|
self::assertSame('', $item['product_url']);
|
|
self::assertFalse($item['product_has_url']);
|
|
self::assertSame('', $item['configure_url']);
|
|
}
|
|
}
|