rewriting

This commit is contained in:
Etienne Roudeix
2013-09-03 16:51:41 +02:00
parent 2bc1dc0bec
commit 43ff0b7297
15 changed files with 406 additions and 140 deletions

View File

@@ -0,0 +1,119 @@
<?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\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;
}
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);
}
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

@@ -23,7 +23,9 @@
namespace Thelia\Tests\Rewriting;
use Thelia\Model\RewritingUrl;
use Thelia\Rewriting\RewritingRetriever;
use Thelia\Tools\URL;
/**
*
@@ -32,13 +34,65 @@ use Thelia\Rewriting\RewritingRetriever;
*/
class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
{
public function testGetViewUrl()
protected function getMethod($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingRetriever');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
public function testGetSpecificUrl()
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('foo.html', $retriever->rewrittenUrl);
$this->assertEquals(URL::viewUrl('view', array('locale' => '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::viewUrl('view', array('foo0' => 'bar0', 'foo1' => 'bar1', 'locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
}
}