<?php

use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
use KupShop\KupShopBundle\Util\Compat\SymfonyBridge;
use KupShop\OrderingBundle\Exception\CartValidationException;

class OrderRestrictionsTest extends DatabaseTestCase
{
    use CartTestTrait;

    public function getDataSet()
    {
        return $this->getJsonDataSet('
        {
        "order_restrictions": [
              {
                "id":1,
                "date_created":"2019-09-05 23:19:47",
                "email":"petr@wpj.cz",
                "ip":null,
                "description":"blokace emailu"
              },
              {
                "id":2,
                "date_created":"2019-09-05 23:19:59",
                "email":null,
                "ip":"8.8.8.8",
                "description":"blokace IP"
              }
            ]
        }
        ');
    }

    public function testEmailRestriction()
    {
        $this->loginUser(1);

        $this->createCart();
        $this->insertProduct(1, 16, 1.35);

        $this->expectException(CartValidationException::class);
        $this->checkOrderPriceIsSameAsCart();
    }

    public function testIPRestrictions()
    {
        $this->loginUser(2);
        SymfonyBridge::getCurrentRequest()->server->set('REMOTE_ADDR', '8.8.8.8');
        $this->createCart();
        $this->insertProduct(1, 16, '1,35');

        $this->expectException(CartValidationException::class);
        $this->checkOrderPriceIsSameAsCart();
    }
}
