create test rewritten url for category
This commit is contained in:
@@ -61,7 +61,11 @@ trait UrlRewritingTrait {
|
|||||||
|
|
||||||
$this->setLocale($locale);
|
$this->setLocale($locale);
|
||||||
|
|
||||||
$title = $this->getTitle() ?: $this->getRef();
|
$title = $this->getTitle();
|
||||||
|
|
||||||
|
if(null == $title) {
|
||||||
|
throw new \RuntimeException('Impossible to create an url if title is null');
|
||||||
|
}
|
||||||
// Replace all weird characters with dashes
|
// Replace all weird characters with dashes
|
||||||
$string = preg_replace('/[^\w\-~_\.]+/u', '-', $title);
|
$string = preg_replace('/[^\w\-~_\.]+/u', '-', $title);
|
||||||
|
|
||||||
|
|||||||
104
core/lib/Thelia/Tests/Rewriting/CategoryRewritingTest.php
Normal file
104
core/lib/Thelia/Tests/Rewriting/CategoryRewritingTest.php
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
/*************************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Thelia */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) OpenStudio */
|
||||||
|
/* email : info@thelia.net */
|
||||||
|
/* web : http://www.thelia.net */
|
||||||
|
/* */
|
||||||
|
/* This program is free software; you can redistribute it and/or modify */
|
||||||
|
/* it under the terms of the GNU General Public License as published by */
|
||||||
|
/* the Free Software Foundation; either version 3 of the License */
|
||||||
|
/* */
|
||||||
|
/* This program is distributed in the hope that it will be useful, */
|
||||||
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||||
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||||
|
/* GNU General Public License for more details. */
|
||||||
|
/* */
|
||||||
|
/* You should have received a copy of the GNU General Public License */
|
||||||
|
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
/* */
|
||||||
|
/*************************************************************************************/
|
||||||
|
|
||||||
|
namespace Thelia\Tests\Rewriting;
|
||||||
|
use Thelia\Model\Category;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CategoryRewritingTest
|
||||||
|
* @package Thelia\Tests\Rewriting
|
||||||
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class CategoryRewritingTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||||
|
*/
|
||||||
|
public function testSimpleFrenchRewrittenUrl()
|
||||||
|
{
|
||||||
|
$category = new Category();
|
||||||
|
$category->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$/', $category->getRewrittenUrl('fr_FR'));
|
||||||
|
|
||||||
|
$rewrittenUrl = $category->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
|
||||||
|
|
||||||
|
$category->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||||
|
*/
|
||||||
|
public function testSimpleEnglishRewrittenUrl()
|
||||||
|
{
|
||||||
|
$category = new Category();
|
||||||
|
$category->setVisible(1)
|
||||||
|
->setPosition(1)
|
||||||
|
->setLocale('en_US')
|
||||||
|
->setTitle('My english super Title')
|
||||||
|
->save();
|
||||||
|
|
||||||
|
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $category->getRewrittenUrl('en_US'));
|
||||||
|
|
||||||
|
$rewrittenUrl = $category->generateRewrittenUrl('en_US');
|
||||||
|
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
|
||||||
|
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl);
|
||||||
|
|
||||||
|
$category->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @expectedExceptionMessage Impossible to create an url if title is null
|
||||||
|
*/
|
||||||
|
public function testRewrittenWithoutTitle()
|
||||||
|
{
|
||||||
|
$category = new Category();
|
||||||
|
$category->setVisible(1)
|
||||||
|
->setPosition(1)
|
||||||
|
->setLocale('en_US')
|
||||||
|
->setDescription('My english super Description')
|
||||||
|
->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @expectedExceptionMessage Object category must be saved before generating url
|
||||||
|
*/
|
||||||
|
public function testOnNotSavedProduct()
|
||||||
|
{
|
||||||
|
$product = new Category();
|
||||||
|
|
||||||
|
$product->generateRewrittenUrl('fr_FR');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,6 +79,11 @@ class ProductRewriteTest extends \PHPUnit_Framework_TestCase
|
|||||||
$product->delete();
|
$product->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @expectedExceptionMessage Impossible to create an url if title is null
|
||||||
|
*/
|
||||||
public function testRewrittenWithoutTitle()
|
public function testRewrittenWithoutTitle()
|
||||||
{
|
{
|
||||||
$product = new Product();
|
$product = new Product();
|
||||||
@@ -88,14 +93,6 @@ class ProductRewriteTest extends \PHPUnit_Framework_TestCase
|
|||||||
->setLocale('en_US')
|
->setLocale('en_US')
|
||||||
->setDescription('My english super Description')
|
->setDescription('My english super Description')
|
||||||
->save();
|
->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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user