Merge branch 'master' of https://github.com/thelia/thelia into coupon
# By Manuel Raynaud (22) and others # Via Manuel Raynaud (7) and others * 'master' of https://github.com/thelia/thelia: (32 commits) refactor name for updating actions choose UPDATE word for name actions add update address action and create tests 404 not found management Working Fix unset namespace modify travis script test rewriting exception Fixed minor bug in Currencies Finished currency edition Added route methods address action implementation hot fix rewriting add address create controller and event Added AdminUtilities Smarty plugin, optimized templates update customer model createOrUpdate method update address model fix redirect process in viewListener refactor reset_install script refactor install process, database management in dedicated class ... Conflicts: local/config/schema.xml reset_install.sh
This commit is contained in:
145
core/lib/Thelia/Tests/Action/AddressTest.php
Normal file
145
core/lib/Thelia/Tests/Action/AddressTest.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?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\Action;
|
||||
use Thelia\Action\Address;
|
||||
use Thelia\Core\Event\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Model\Base\CustomerQuery;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* test address eventListener
|
||||
*
|
||||
* Class AddressTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class AddressTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
|
||||
|
||||
$dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
|
||||
$container->set("event_dispatcher", $dispatcher);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
public function testCreatedAddress()
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
|
||||
$AddressCreateOrUpdateEvent = new AddressCreateOrUpdateEvent(
|
||||
"test address",
|
||||
1,
|
||||
"Thelia",
|
||||
"Thelia",
|
||||
"5 rue rochon",
|
||||
"",
|
||||
"",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
"0102030405",
|
||||
"",
|
||||
""
|
||||
);
|
||||
$AddressCreateOrUpdateEvent->setCustomer($customer);
|
||||
|
||||
$actionAddress = new Address($this->getContainer());
|
||||
$actionAddress->create($AddressCreateOrUpdateEvent);
|
||||
|
||||
$createdAddress = $AddressCreateOrUpdateEvent->getAddress();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $createdAddress);
|
||||
$this->assertFalse($createdAddress->isNew());
|
||||
$this->assertSame($customer, $createdAddress->getCustomer());
|
||||
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getLabel(), $createdAddress->getLabel());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getTitle(), $createdAddress->getTitleId());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getFirstname(), $createdAddress->getFirstname());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getLastname(), $createdAddress->getLastname());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getAddress1(), $createdAddress->getAddress1());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getAddress2(), $createdAddress->getAddress2());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getAddress3(), $createdAddress->getAddress3());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getZipcode(), $createdAddress->getZipcode());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCity(), $createdAddress->getCity());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCountry(), $createdAddress->getCountryId());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getPhone(), $createdAddress->getPhone());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCellphone(), $createdAddress->getCellphone());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCompany(), $createdAddress->getCompany());
|
||||
}
|
||||
|
||||
public function testUpdatedAddress()
|
||||
{
|
||||
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
$address = $customer->getAddresses()->getFirst();
|
||||
|
||||
$addressEvent = new AddressCreateOrUpdateEvent(
|
||||
"",
|
||||
1,
|
||||
"Thelia modif",
|
||||
"Thelia modif",
|
||||
"cour des étoiles",
|
||||
"rue des miracles",
|
||||
"",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
"0102030405",
|
||||
"",
|
||||
""
|
||||
);
|
||||
$addressEvent->setAddress($address);
|
||||
|
||||
$actionAddress = new Address($this->getContainer());
|
||||
$actionAddress->update($addressEvent);
|
||||
|
||||
|
||||
$updatedAddress = $addressEvent->getAddress();
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $updatedAddress);
|
||||
$this->assertFalse($updatedAddress->isNew());
|
||||
$this->assertSame($customer, $updatedAddress->getCustomer());
|
||||
|
||||
$this->assertEquals($address->getLabel(), $updatedAddress->getLabel());
|
||||
$this->assertEquals($addressEvent->getTitle(), $updatedAddress->getTitleId());
|
||||
$this->assertEquals($addressEvent->getFirstname(), $updatedAddress->getFirstname());
|
||||
$this->assertEquals($addressEvent->getLastname(), $updatedAddress->getLastname());
|
||||
$this->assertEquals($addressEvent->getAddress1(), $updatedAddress->getAddress1());
|
||||
$this->assertEquals($addressEvent->getAddress2(), $updatedAddress->getAddress2());
|
||||
$this->assertEquals($addressEvent->getAddress3(), $updatedAddress->getAddress3());
|
||||
$this->assertEquals($addressEvent->getZipcode(), $updatedAddress->getZipcode());
|
||||
$this->assertEquals($addressEvent->getCity(), $updatedAddress->getCity());
|
||||
$this->assertEquals($addressEvent->getCountry(), $updatedAddress->getCountryId());
|
||||
$this->assertEquals($addressEvent->getPhone(), $updatedAddress->getPhone());
|
||||
$this->assertEquals($addressEvent->getCellphone(), $updatedAddress->getCellphone());
|
||||
$this->assertEquals($addressEvent->getCompany(), $updatedAddress->getCompany());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
154
core/lib/Thelia/Tests/Rewriting/RewritingResolverTest.php
Executable file
154
core/lib/Thelia/Tests/Rewriting/RewritingResolverTest.php
Executable file
@@ -0,0 +1,154 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Thelia\Exception\UrlRewritingException
|
||||
* @expectedExceptionCode 800
|
||||
*/
|
||||
public function testGetOtherParametersException()
|
||||
{
|
||||
$resolver = new RewritingResolver();
|
||||
|
||||
$method = $this->getMethod('getOtherParameters');
|
||||
$actual = $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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user