168 lines
5.0 KiB
PHP
168 lines
5.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: ondra
|
|
* Date: 18.10.17
|
|
* Time: 12:23.
|
|
*/
|
|
|
|
namespace KupShop\ContentBundle\Tests;
|
|
|
|
use KupShop\ContentBundle\View\ProductView;
|
|
|
|
class ProductViewTest extends \DatabaseTestCase
|
|
{
|
|
public function testVisibleProduct()
|
|
{
|
|
$response = $this->getUrlResponse('https://www.kupshop.local/visible-product_z12/');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
}
|
|
|
|
public function testHiddenProduct()
|
|
{
|
|
$response = $this->getUrlResponse('https://www.kupshop.local/hidden-product_z13/');
|
|
|
|
$this->assertEquals(404, $response->getStatusCode());
|
|
$this->assertContains('Product not found', $response->getContent());
|
|
}
|
|
|
|
public function testOldProduct()
|
|
{
|
|
$response = $this->getUrlResponse('https://www.kupshop.local/old-product_z14/');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
$this->assertContains('Tento produkt je dlouhodobě vyprodaný', $response->getContent());
|
|
}
|
|
|
|
public function testOutOfStockProdShowNotInStoreN()
|
|
{
|
|
$dbcfg = \Settings::getDefault();
|
|
|
|
// prod show not in store = N
|
|
$dbcfg->prod_show_not_in_store = 'N';
|
|
$response = $this->getUrlResponse('https://www.kupshop.local/not-in-store-product_z15/');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
$this->assertContains('Tento produkt je dlouhodobě vyprodaný', $response->getContent());
|
|
}
|
|
|
|
public function testOutOfStockProdShowNotInStoreY()
|
|
{
|
|
$dbcfg = \Settings::getDefault();
|
|
|
|
// prod show not in store = Y
|
|
$dbcfg->prod_show_not_in_store = 'Y';
|
|
$response = $this->getUrlResponse('https://www.kupshop.local/not-in-store-product_z15/');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
$this->assertNotContains('Tento produkt je dlouhodobě vyprodaný', $response->getContent());
|
|
}
|
|
|
|
public function testNoVariationsInStock()
|
|
{
|
|
$dbcfg = \Settings::getDefault();
|
|
$dbcfg->prod_show_not_in_store = 'N';
|
|
|
|
$response = $this->getUrlResponse('https://www.kupshop.local/variations-not-in-stock-product_z16/');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
$this->assertContains('Tento produkt je dlouhodobě vyprodaný', $response->getContent());
|
|
}
|
|
|
|
public function testProductPriceWithVariations()
|
|
{
|
|
$dbcfg = \Settings::getDefault();
|
|
$dbcfg->prod_show_not_in_store = 'N';
|
|
|
|
$response = $this->getUrlResponse('https://www.kupshop.local/variations-product_z17/');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
$this->assertContains('<p class="price" data-price>2 178 Kč</p>', $response->getContent());
|
|
}
|
|
|
|
public function testProductTranslationHidden()
|
|
{
|
|
$this->switchLanguage();
|
|
|
|
$response = $this->getUrlResponse('https://www.kupshop.local/nike-capri-lace-test-dlouheho-nazvu-produktu-test-dlouheho-produktu-tes_z1/');
|
|
|
|
$this->assertEquals(404, $response->getStatusCode());
|
|
$this->assertContains('Product not found', $response->getContent());
|
|
}
|
|
|
|
public function testProductTranslationVisible()
|
|
{
|
|
$this->switchLanguage();
|
|
|
|
$response = $this->getUrlResponse('https://www.kupshop.local/adidas-mundial-goal-dalsi-test-velmi-dlouheho-produktoveho-nazvu_z2/');
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
}
|
|
|
|
private function getUrlResponse($url)
|
|
{
|
|
$client = $this->createClient();
|
|
$client->request('GET', $url);
|
|
|
|
return $client->getResponse();
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provider
|
|
*/
|
|
public function testGetCorrectUrl($url, $target)
|
|
{
|
|
$client = $this->createClient();
|
|
|
|
$client->request('GET', $url);
|
|
|
|
$responseUrl = $client->getResponse()->headers->get('location');
|
|
|
|
$this->assertEquals($target, $responseUrl);
|
|
}
|
|
|
|
public function testGetDeliveryDaysDeliveryPricelistOff()
|
|
{
|
|
global $cfg;
|
|
|
|
$cfg['Modules']['delivery_pricelist'] = false;
|
|
|
|
/** @var ProductView $view */
|
|
$view = $this->get(ProductView::class);
|
|
|
|
$days = $view->getDeliveryDays();
|
|
|
|
$this->assertEquals(['min' => 3], $days);
|
|
}
|
|
|
|
public function testGetDeliveryDaysDeliveryPricelistOn()
|
|
{
|
|
global $cfg;
|
|
|
|
$cfg['Modules']['delivery_pricelist'] = true;
|
|
|
|
/** @var ProductView $view */
|
|
$view = $this->get(ProductView::class);
|
|
|
|
$days = $view->getDeliveryDays();
|
|
|
|
$this->assertEquals(['min' => 3, 'max' => 5], $days);
|
|
}
|
|
|
|
public function getDataSet()
|
|
{
|
|
return $this->getJsonDataSetFromFile();
|
|
}
|
|
|
|
public function provider()
|
|
{
|
|
return [
|
|
['https://www.kupshop.local/nejaky-spatny-nazev123_z1/', '/nike-capri-lace-test-dlouheho-nazvu-produktu-test-dlouheho-produktu-tes_z1/'],
|
|
['https://www.kupshop.local/nejaky-spatny-nazev_z3/', '/wilson-pure-battle-crew_z3/'],
|
|
['https://www.kupshop.local/nejaky-spatny-nazev_z11/', '/iphone-wpj_z11/'],
|
|
];
|
|
}
|
|
}
|