add more test for rewriten url
This commit is contained in:
@@ -200,6 +200,12 @@ class Product extends BaseProduct
|
||||
*/
|
||||
public function postDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
RewritingUrlQuery::create()
|
||||
->filterByView($this->getRewrittenUrlViewName())
|
||||
->filterByViewId($this->getId())
|
||||
->update(array(
|
||||
"View" => ConfigQuery::read('passed_url_view', 'passed-url')
|
||||
));
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_DELETEPRODUCT, new ProductEvent($this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ trait UrlRewritingTrait {
|
||||
->filterByViewLocale($locale)
|
||||
->filterByView($this->getRewrittenUrlViewName())
|
||||
->filterByViewId($this->getId())
|
||||
->filterByRedirected(0)
|
||||
->filterByRedirected(null)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
|
||||
@@ -33,46 +33,69 @@ use Thelia\Model\ProductQuery;
|
||||
*/
|
||||
class ProductRewriteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected static $productId;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$product = new Product();
|
||||
$product->setRef(sprintf("TestRewrittenProduct%s",uniqid()))
|
||||
->setPosition(1)
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('My english super Title')
|
||||
->setLocale('fr_FR')
|
||||
->setTitle('Mon super titre en français')
|
||||
->save();
|
||||
|
||||
self::$productId = $product->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||
*/
|
||||
public function testFrenchRewrittenUrl()
|
||||
public function testSimpleFrenchRewrittenUrl()
|
||||
{
|
||||
$product = ProductQuery::create()->findPk(self::$productId);
|
||||
$product = new Product();
|
||||
$product->setRef(sprintf("TestRewrittenProduct%s",uniqid()))
|
||||
->setVisible(1)
|
||||
->setPosition(1)
|
||||
->setLocale('fr_FR')
|
||||
->setTitle('Mon super titre en français')
|
||||
->save();
|
||||
|
||||
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $product->getRewrittenUrl('fr_FR'));
|
||||
|
||||
$rewrittenUrl = $product->generateRewrittenUrl('fr_FR');
|
||||
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
|
||||
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $rewrittenUrl);
|
||||
//mon-super-titre-en-français-2.html
|
||||
|
||||
$product->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||
*/
|
||||
public function testEnglishRewrittenUrl()
|
||||
public function testSimpleEnglishRewrittenUrl()
|
||||
{
|
||||
$product = ProductQuery::create()->findPk(self::$productId);
|
||||
$product = new Product();
|
||||
$product->setRef(sprintf("TestRewrittenProduct%s",uniqid()))
|
||||
->setVisible(1)
|
||||
->setPosition(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('My english super Title')
|
||||
->save();
|
||||
|
||||
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $product->getRewrittenUrl('en_US'));
|
||||
|
||||
$rewrittenUrl = $product->generateRewrittenUrl('en_US');
|
||||
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
|
||||
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl);
|
||||
|
||||
$product->delete();
|
||||
}
|
||||
|
||||
public function testRewrittenWithoutTitle()
|
||||
{
|
||||
$product = new Product();
|
||||
$product->setRef(sprintf("TestRewrittenProduct%s",uniqid()))
|
||||
->setVisible(1)
|
||||
->setPosition(1)
|
||||
->setLocale('en_US')
|
||||
->setDescription('My english super Description')
|
||||
->save();
|
||||
|
||||
$this->assertEquals(strtolower(sprintf('%s.html', $product->getRef())), $product->getRewrittenUrl('en_US'));
|
||||
|
||||
$rewrittenUrl = $product->generateRewrittenUrl('en_US');
|
||||
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
|
||||
$this->assertEquals(strtolower(sprintf('%s-1.html', $product->getRef())), $rewrittenUrl);
|
||||
|
||||
$product->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat
|
||||
('image_cache_dir_from_web_root', 'cache/images', 0, 0, NOW(), NOW()),
|
||||
('document_cache_dir_from_web_root', 'cache/documents', 0, 0, NOW(), NOW()),
|
||||
('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', 0, 0, NOW(), NOW()),
|
||||
('page_not_found_view', '404.html', 0, 0, NOW(), NOW()),
|
||||
('page_not_found_view', '404', 0, 0, NOW(), NOW()),
|
||||
('passed_url_view', 'passed-url', 0, 0, NOW(), NOW()),
|
||||
('use_tax_free_amounts', 0, 0, 0, NOW(), NOW()),
|
||||
('process_assets', '1', 0, 0, NOW(), NOW()),
|
||||
('thelia_admin_remember_me_cookie_name', 'tarmcn', 0, 0, NOW(), NOW()),
|
||||
|
||||
Reference in New Issue
Block a user