Initial Commit

This commit is contained in:
2019-11-21 12:25:31 +01:00
commit f4aabcb9b1
13959 changed files with 787761 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
/**
* Class BaseRewritingObject
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <manu@raynaud.io>
*/
abstract class BaseRewritingObject extends \PHPUnit_Framework_TestCase
{
/**
* @return mixed an instance of Product, Folder, Content or Category Model
*/
abstract public function getObject();
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
*/
public function testSimpleFrenchRewrittenUrl()
{
$object = $this->getObject();
$object->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$/', $object->getRewrittenUrl('fr_FR'));
$rewrittenUrl = $object->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
$object->delete();
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
*/
public function testSimpleEnglishRewrittenUrl()
{
$object = $this->getObject();
$object->setVisible(1)
->setPosition(1)
->setLocale('en_US')
->setTitle('My english super Title')
->save();
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $object->getRewrittenUrl('en_US'));
$rewrittenUrl = $object->generateRewrittenUrl('en_US');
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl);
$object->delete();
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
* @expectedException \RuntimeException
* @expectedExceptionMessage Impossible to create an url if title is null
*/
public function testRewrittenWithoutTitle()
{
$object = $this->getObject();
$object->setVisible(1)
->setPosition(1)
->setLocale('en_US')
->setDescription('My english super Description')
->save();
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
* @expectedException \RuntimeException
*/
public function testOnNotSavedObject()
{
$object = $this->getObject();
$object->generateRewrittenUrl('fr_FR');
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
use Thelia\Model\Category;
/**
* Class CategoryRewritingTest
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <manu@raynaud.io>
*/
class CategoryRewritingTest extends BaseRewritingObject
{
/**
* @return \Thelia\Model\Category
*/
public function getObject()
{
return new Category();
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
use Thelia\Model\Content;
/**
* Class ContentRewritingTest
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <manu@raynaud.io>
*/
class ContentRewritingTest extends BaseRewritingObject
{
/**
* @return \Thelia\Model\Content
*/
public function getObject()
{
return new Content();
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
use Thelia\Model\Folder;
/**
* Class FolderRewritingTest
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <manu@raynaud.io>
*/
class FolderRewritingTest extends BaseRewritingObject
{
/**
* @return mixed an instance of Product, Folder, Content or Category Model
*/
public function getObject()
{
return new Folder();
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
use Thelia\Model\Product;
/**
* Class ProductRewriteTest
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <manu@raynaud.io>
*/
class ProductRewriteTest extends BaseRewritingObject
{
/**
* @return mixed an instance of Product, Folder, Content or Category Model
*/
public function getObject()
{
$product = new Product();
$product->setRef(uniqid());
return $product;
}
}

View File

@@ -0,0 +1,142 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
use Thelia\Model\RewritingArgument;
use Thelia\Rewriting\RewritingResolver;
use Propel\Runtime\Collection\ObjectCollection;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class RewritingResolverTest extends \PHPUnit_Framework_TestCase
{
protected function getMethod($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingResolver');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
protected function getProperty($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingResolver');
$property = $class->getProperty($name);
$property->setAccessible(true);
return $property;
}
/**
* @expectedException \Thelia\Exception\UrlRewritingException
* @expectedExceptionCode 800
*/
public function testGetOtherParametersException()
{
$resolver = new RewritingResolver();
$method = $this->getMethod('getOtherParameters');
$method->invoke($resolver);
}
public function testGetOtherParameters()
{
$rewritingArguments = array(
array('Parameter' => 'foo0', 'Value' => 'bar0'),
array('Parameter' => 'foo1', 'Value' => 'bar1'),
array('Parameter' => 'foo2', 'Value' => 'bar2'),
);
$searchResult = new ObjectCollection();
$searchResult->setModel('\Thelia\Model\RewritingArgument');
$searchResult->fromArray($rewritingArguments);
$resolver = new RewritingResolver();
$search = $this->getProperty('search');
$search->setValue($resolver, $searchResult);
$method = $this->getMethod('getOtherParameters');
$actual = $method->invoke($resolver);
$expected = array(
'foo0' => 'bar0',
'foo1' => 'bar1',
'foo2' => 'bar2',
);
$this->assertEquals($expected, $actual);
}
/**
* @expectedException \Thelia\Exception\UrlRewritingException
* @expectedExceptionCode 404
*/
public function testLoadException()
{
$collection = new ObjectCollection();
$collection->setModel('\Thelia\Model\RewritingArgument');
$resolverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getResolverSearch'));
$resolverQuery->expects($this->any())
->method('getResolverSearch')
->with('foo.html')
->will($this->returnValue($collection));
$resolver = new RewritingResolver();
$rewritingUrlQuery = $this->getProperty('rewritingUrlQuery');
$rewritingUrlQuery->setValue($resolver, $resolverQuery);
$resolver->load('foo.html');
}
public function testLoad()
{
$collection = new ObjectCollection();
$collection->setModel('\Thelia\Model\RewritingArgument');
for ($i=0; $i<3; $i++) {
$ra = new RewritingArgument();
$ra->setParameter('foo' . $i);
$ra->setValue('bar' . $i);
$ra->setVirtualColumn('ru_view', 'view');
$ra->setVirtualColumn('ru_viewId', 'viewId');
$ra->setVirtualColumn('ru_locale', 'locale');
$ra->setVirtualColumn('ru_redirected_to_url', null);
$collection->append($ra);
}
$resolverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getResolverSearch'));
$resolverQuery->expects($this->any())
->method('getResolverSearch')
->with('foo.html')
->will($this->returnValue($collection));
$resolver = new RewritingResolver();
$rewritingUrlQuery = $this->getProperty('rewritingUrlQuery');
$rewritingUrlQuery->setValue($resolver, $resolverQuery);
$resolver->load('foo.html');
$this->assertEquals('view', $resolver->view);
$this->assertEquals('viewId', $resolver->viewId);
$this->assertEquals('locale', $resolver->locale);
$this->assertEquals(array('foo0' => 'bar0', 'foo1' => 'bar1', 'foo2' => 'bar2'), $resolver->otherParameters);
}
}

View File

@@ -0,0 +1,118 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Thelia\Model\RewritingUrl;
use Thelia\Rewriting\RewritingRetriever;
use Thelia\Tools\URL;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
{
protected $container = null;
public function setUp()
{
$this->container = new ContainerBuilder();
$stubRouterAdmin = $this->getMockBuilder('\Symfony\Component\Routing\Router')
->disableOriginalConstructor()
->setMethods(array('getContext'))
->getMock();
$stubRequestContext = $this->getMockBuilder('\Symfony\Component\Routing\RequestContext')
->disableOriginalConstructor()
->setMethods(array('getHost'))
->getMock();
$stubRequestContext->expects($this->any())
->method('getHost')
->will($this->returnValue('localhost'));
$stubRouterAdmin->expects($this->any())
->method('getContext')
->will($this->returnValue(
$stubRequestContext
));
$this->container->set('router.admin', $stubRouterAdmin);
$this->container->set('thelia.url.manager', new URL($this->container));
}
protected function getMethod($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingRetriever');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
protected function getProperty($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingRetriever');
$property = $class->getProperty($name);
$property->setAccessible(true);
return $property;
}
public function testLoadViewUrl()
{
$searchResult = new RewritingUrl();
$searchResult->setUrl('foo.html');
$retrieverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getViewUrlQuery'));
$retrieverQuery->expects($this->any())
->method('getViewUrlQuery')
->with('view', 'fr_FR', 1)
->will($this->returnValue($searchResult));
$retriever = new RewritingRetriever();
$rewritingUrlQuery = $this->getProperty('rewritingUrlQuery');
$rewritingUrlQuery->setValue($retriever, $retrieverQuery);
$retriever->loadViewUrl('view', 'fr_FR', 1);
$this->assertEquals(URL::getInstance()->absoluteUrl('foo.html'), $retriever->rewrittenUrl);
$this->assertEquals(URL::getInstance()->viewUrl('view', array('lang' => 'fr_FR', 'view_id' => 1)), $retriever->url);
}
public function testLoadSpecificUrl()
{
$searchResult = new RewritingUrl();
$searchResult->setUrl('foo.html');
$retrieverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getSpecificUrlQuery'));
$retrieverQuery->expects($this->any())
->method('getSpecificUrlQuery')
->with('view', 'fr_FR', 1, array('foo0' => 'bar0', 'foo1' => 'bar1'))
->will($this->returnValue($searchResult));
$retriever = new RewritingRetriever();
$rewritingUrlQuery = $this->getProperty('rewritingUrlQuery');
$rewritingUrlQuery->setValue($retriever, $retrieverQuery);
$retriever->loadSpecificUrl('view', 'fr_FR', 1, array('foo0' => 'bar0', 'foo1' => 'bar1'));
$this->assertEquals('foo.html', $retriever->rewrittenUrl);
$this->assertEquals(URL::getInstance()->viewUrl('view', array('foo0' => 'bar0', 'foo1' => 'bar1', 'lang' => 'fr_FR', 'view_id' => 1)), $retriever->url);
}
}