<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Tests\Context;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Context\ShopCountryContext;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;

final class ShopCountryContextTest extends TestCase
{
    public function testItReturnsTheBlockedCountryFromTheCurrentSession(): void
    {
        $request = new Request();
        $session = new Session(new MockArraySessionStorage());
        $session->set('blockShop', true);
        $session->set('blockShopCountry', 'US');
        $request->setSession($session);

        $requestStack = new RequestStack();
        $requestStack->push($request);

        $context = new ShopCountryContext($requestStack);

        self::assertTrue($context->isBlocked());
        self::assertSame('US', $context->getCountryCode());
    }

    public function testItIsNotBlockedWithoutARequestSession(): void
    {
        $context = new ShopCountryContext(new RequestStack());

        self::assertFalse($context->isBlocked());
        self::assertNull($context->getCountryCode());
    }
}
