245 lines
6.9 KiB
PHP
245 lines
6.9 KiB
PHP
<?php
|
|
|
|
namespace KupShop\RestrictionsBundle\Tests;
|
|
|
|
use KupShop\ContentBundle\View\ProductView;
|
|
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
|
use KupShop\RestrictionsBundle\Utils\Restrictions;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class RestrictionsTest extends \DatabaseTestCase
|
|
{
|
|
use CartTestTrait;
|
|
|
|
/** @var Restrictions */
|
|
private $restrictions;
|
|
|
|
/** @var ProductView */
|
|
private $productView;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->restrictions = $this->get(Restrictions::class);
|
|
$this->productView = $this->get(ProductView::class);
|
|
}
|
|
|
|
public function getDataSet()
|
|
{
|
|
// Omezení Nepřihlášený uživatel - restricted product ID=4
|
|
// Omezení wpj (id_user = 1,2,3) - restricted product ID=9
|
|
// Omezení wpjwpj (id_user != 2) - restricted product ID=11
|
|
|
|
return $this->getJsonDataSet('
|
|
{
|
|
"restrictions": [
|
|
{
|
|
"id":3,
|
|
"name":"Omezení Nepřihlášený uživatel",
|
|
"domain":4,
|
|
"domain_invert":"N",
|
|
"object_value":"{\"4\":[\"4\"]}"
|
|
},
|
|
{
|
|
"id":5,
|
|
"name":"Omezení wpj",
|
|
"domain":2,
|
|
"domain_invert":"N",
|
|
"object_value":"{\"4\":[\"9\"]}"
|
|
},
|
|
{
|
|
"id":6,
|
|
"name":"Omezení wpjwpj",
|
|
"domain":2,
|
|
"domain_invert":"Y",
|
|
"object_value":"{\"4\":[\"11\"]}"
|
|
}
|
|
],
|
|
"restrictions_domains": [
|
|
{
|
|
"id":210,
|
|
"id_restriction":3,
|
|
"id_user":null,
|
|
"country":null,
|
|
"login":"logOut",
|
|
"id_price_level":null,
|
|
"id_users_group":null
|
|
},
|
|
{
|
|
"id":240,
|
|
"id_restriction":5,
|
|
"id_user":1,
|
|
"country":null,
|
|
"login":null,
|
|
"id_price_level":null,
|
|
"id_users_group":null
|
|
},
|
|
{
|
|
"id":241,
|
|
"id_restriction":5,
|
|
"id_user":2,
|
|
"country":null,
|
|
"login":null,
|
|
"id_price_level":null,
|
|
"id_users_group":null
|
|
},
|
|
{
|
|
"id":242,
|
|
"id_restriction":5,
|
|
"id_user":3,
|
|
"country":null,
|
|
"login":null,
|
|
"id_price_level":null,
|
|
"id_users_group":null
|
|
},
|
|
{
|
|
"id":243,
|
|
"id_restriction":6,
|
|
"id_user":2,
|
|
"country":null,
|
|
"login":null,
|
|
"id_price_level":null,
|
|
"id_users_group":null
|
|
}
|
|
]
|
|
}
|
|
');
|
|
}
|
|
|
|
/** @dataProvider data_testVisibleProduct1 */
|
|
public function testVisibleProduct1($id_user, $restricted)
|
|
{
|
|
if ($id_user) {
|
|
$this->loginUser($id_user);
|
|
}
|
|
|
|
$this->productView->setProductId(1);
|
|
|
|
if ($restricted) {
|
|
$this->expectException(NotFoundHttpException::class);
|
|
$this->expectExceptionMessage('Product not found');
|
|
$this->productView->checkProductExist();
|
|
} else {
|
|
$product = $this->productView->getProduct();
|
|
$this->assertNotFalse($product);
|
|
$this->assertInstanceOf(\Product::class, $product);
|
|
$this->assertContains('NIKE Capri LACE Test Dlouheho Nazvu Produktu Test Dlouheho Produktu Tes', $product->title);
|
|
}
|
|
}
|
|
|
|
public function data_testVisibleProduct1()
|
|
{
|
|
// product ID=1 is visible for everyone
|
|
|
|
return [
|
|
[1, false],
|
|
[2, false],
|
|
[3, false],
|
|
[null, false],
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_RestrictedProduct4 */
|
|
public function testRestrictedProduct4($id_user, $restricted)
|
|
{
|
|
if ($id_user) {
|
|
$this->loginUser($id_user);
|
|
}
|
|
|
|
$this->productView->setProductId(4);
|
|
|
|
if ($restricted) {
|
|
$this->expectException(NotFoundHttpException::class);
|
|
$this->expectExceptionMessage('Product not found');
|
|
$this->productView->checkProductExist();
|
|
} else {
|
|
$product = $this->productView->getProduct();
|
|
$this->assertNotFalse($product);
|
|
$this->assertInstanceOf(\Product::class, $product);
|
|
$this->assertContains('Columbia Lay D Down', $product->title);
|
|
}
|
|
}
|
|
|
|
public function data_RestrictedProduct4()
|
|
{
|
|
// Omezení Nepřihlášený uživatel:
|
|
// product ID=4 is visible for logged in users only
|
|
|
|
return [
|
|
[1, false],
|
|
[2, false],
|
|
[3, false],
|
|
[null, true],
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_RestrictedProduct9 */
|
|
public function testRestrictedProduct9($id_user, $restricted)
|
|
{
|
|
if ($id_user) {
|
|
$this->loginUser($id_user);
|
|
}
|
|
|
|
$this->productView->setProductId(9);
|
|
|
|
if ($restricted) {
|
|
$this->expectException(NotFoundHttpException::class);
|
|
$this->expectExceptionMessage('Product not found');
|
|
$this->productView->checkProductExist();
|
|
} else {
|
|
$product = $this->productView->getProduct();
|
|
$this->assertNotFalse($product);
|
|
$this->assertInstanceOf(\Product::class, $product);
|
|
$this->assertContains('DeWALT DCD780C2 aku vrtačka', $product->title);
|
|
}
|
|
}
|
|
|
|
public function data_RestrictedProduct9()
|
|
{
|
|
// Omezení wpj (id_user = 1,2,3):
|
|
// product ID=9 is not visible for wpj users
|
|
|
|
return [
|
|
[1, true],
|
|
[2, true],
|
|
[3, true],
|
|
[null, false],
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_RestrictedProduct11 */
|
|
public function testRestrictedProduct11($id_user, $restricted)
|
|
{
|
|
if ($id_user) {
|
|
$this->loginUser($id_user);
|
|
}
|
|
|
|
$this->productView->setProductId(11);
|
|
|
|
if ($restricted) {
|
|
$this->expectException(NotFoundHttpException::class);
|
|
$this->expectExceptionMessage('Product not found');
|
|
$this->productView->checkProductExist();
|
|
} else {
|
|
$product = $this->productView->getProduct();
|
|
$this->assertNotFalse($product);
|
|
$this->assertInstanceOf(\Product::class, $product);
|
|
$this->assertContains('iPhone wpj', $product->title);
|
|
}
|
|
}
|
|
|
|
public function data_RestrictedProduct11()
|
|
{
|
|
// Omezení wpjwpj (id_user != 2):
|
|
// product ID=11 is visible for user wpj@wpj.cz only
|
|
|
|
return [
|
|
[1, true],
|
|
[2, false],
|
|
[3, true],
|
|
[null, true],
|
|
];
|
|
}
|
|
}
|