Merge branch 'master' of https://github.com/thelia/thelia into coupon
# By Manuel Raynaud (18) and others # Via franck (9) and others * 'master' of https://github.com/thelia/thelia: (39 commits) Working : Working : Working : Working : Fixed minor visual glitches Working : Resize countries flag + Add bootstrap-switch fix test suite clear asset cache in cache:cler command Added a 'development mode' to assetic smarty plugin rewriting router use good Request object Added Tools\URL test case, and a test case superclass for initializing Tools\URL remove unused UrlWritin controller create router for rewriting matching customer substitutions fix typo in front id Working : For attributes on labels Working : For attributes on labels add label_attr attribute to form smarty plugin start refactorin rewriting routing ... Conflicts: core/lib/Thelia/Config/Resources/routing/front.xml templates/admin/default/assets/less/thelia/bootstrap-editable.less templates/admin/default/categories.html
This commit is contained in:
@@ -30,13 +30,14 @@ use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Action\Image;
|
||||
use Thelia\Core\Event\ImageEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class ImageTest
|
||||
*
|
||||
* @package Thelia\Tests\Action\ImageTest
|
||||
*/
|
||||
class ImageTest extends \PHPUnit_Framework_TestCase
|
||||
class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
|
||||
{
|
||||
protected $request;
|
||||
|
||||
@@ -50,6 +51,11 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$container->set("event_dispatcher", $dispatcher);
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($this->session);
|
||||
|
||||
$container->set("request", $request);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ class CacheClearTest extends \PHPUnit_Framework_TestCase
|
||||
$fs = new Filesystem();
|
||||
|
||||
$fs->mkdir($this->cache_dir);
|
||||
$fs->mkdir(THELIA_WEB_DIR . "/assets");
|
||||
}
|
||||
|
||||
public function testCacheClear()
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace Thelia\Tests\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Controller\Front\DefaultController;
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ class DefaultControllerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($request->attributes->get('_view'), "index");
|
||||
}
|
||||
|
||||
public function testNoActionWithQuery()
|
||||
public function testNoActionWithGetParam()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(array(
|
||||
@@ -55,15 +55,59 @@ class DefaultControllerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithRequest()
|
||||
public function testNoActionWithPostParam()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(array(), array(
|
||||
"view" => "foo"
|
||||
));
|
||||
$request = new Request(
|
||||
array(),
|
||||
array("view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
|
||||
public function testNoActionWithAttribute()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array(),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttributeAndQuery()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array("view" => "bar"),
|
||||
array(),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'bar');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttributeAndRequest()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array("view" => "bar"),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'bar');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ use Thelia\Core\HttpFoundation\Session\Session;
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
|
||||
abstract class BaseLoopTestor extends \Thelia\Tests\TestCaseWithURLToolSetup
|
||||
{
|
||||
protected $request;
|
||||
protected $dispatcher;
|
||||
|
||||
@@ -71,7 +71,7 @@ class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
|
||||
$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);
|
||||
$this->assertEquals(URL::getInstance()->viewUrl('view', array('locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
|
||||
}
|
||||
|
||||
public function testLoadSpecificUrl()
|
||||
@@ -93,6 +93,6 @@ class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
|
||||
$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);
|
||||
$this->assertEquals(URL::getInstance()->viewUrl('view', array('foo0' => 'bar0', 'foo1' => 'bar1', 'locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
|
||||
}
|
||||
}
|
||||
|
||||
64
core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php
Normal file
64
core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* This class provides URL Tool class initialisation
|
||||
*
|
||||
* @package Thelia\Tests\TestCaseWithURLSetup
|
||||
*/
|
||||
class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->setupURLTool();
|
||||
}
|
||||
|
||||
protected function setupURLTool() {
|
||||
|
||||
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
|
||||
|
||||
$context = new \Symfony\Component\Routing\RequestContext(
|
||||
'/thelia/index.php',
|
||||
'GET',
|
||||
'localhost',
|
||||
'http',
|
||||
80,
|
||||
443,
|
||||
'/path/to/action'
|
||||
);
|
||||
|
||||
$router = $this->getMockBuilder("Symfony\Component\Routing\Router")
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$router->expects($this->any())
|
||||
->method('getContext')
|
||||
->will($this->returnValue($context));
|
||||
|
||||
$container->set("router.admin", $router);
|
||||
|
||||
new \Thelia\Tools\URL($container);
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,208 @@ use Thelia\Tools\URL;
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
* @author Franck Allimant <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class URLTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $context;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
|
||||
|
||||
$router = $this->getMockBuilder("Symfony\Component\Routing\Router")
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->context = new \Symfony\Component\Routing\RequestContext(
|
||||
'/thelia/index.php',
|
||||
'GET',
|
||||
'localhost',
|
||||
'http',
|
||||
80,
|
||||
443,
|
||||
'/path/to/action'
|
||||
);
|
||||
|
||||
$router->expects($this->any())
|
||||
->method('getContext')
|
||||
->will($this->returnValue($this->context));
|
||||
|
||||
$container->set("router.admin", $router);
|
||||
|
||||
new \Thelia\Tools\URL($container);
|
||||
}
|
||||
|
||||
public function testGetIndexPage() {
|
||||
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getIndexPage();
|
||||
$this->assertEquals('http://localhost/thelia/index.php', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getIndexPage();
|
||||
$this->assertEquals('http://localhost/thelia/', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getIndexPage();
|
||||
$this->assertEquals('http://localhost/thelia', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getIndexPage();
|
||||
$this->assertEquals('http://localhost/', $url);
|
||||
}
|
||||
|
||||
public function testGetBaseUrl() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getBaseUrl();
|
||||
$this->assertEquals('http://localhost/thelia/index.php', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getBaseUrl();
|
||||
$this->assertEquals('http://localhost/thelia/', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getBaseUrl();
|
||||
$this->assertEquals('http://localhost/', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrl() {
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action');
|
||||
$this->assertEquals('http://localhost/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action');
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action');
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action');
|
||||
$this->assertEquals('http://localhost/thelia/index.php/path/to/action', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlOnAbsolutePath() {
|
||||
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action');
|
||||
$this->assertEquals('http://myhost/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action');
|
||||
$this->assertEquals('http://myhost/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action');
|
||||
$this->assertEquals('http://myhost/path/to/action', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlOnAbsolutePathWithParameters() {
|
||||
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlOnAbsolutePathWithParametersAddParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action?p0=v0', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p0=v0&p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action?p0=v0', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p0=v0&p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action?p0=v0', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p0=v0&p1=v1&p2=v2', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlWithParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/index.php/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlPathOnly() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array(), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlPathOnlyWithParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlFromIndexWithParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/index.php/?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/?p1=v1&p2=v2', $url);
|
||||
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlPathOnlyFromIndexWithParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/?p1=v1&p2=v2', $url);
|
||||
|
||||
}
|
||||
|
||||
public function testRetrieve()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user