Merge pull request #507 from bibich/improvements
Improvements : - added cache on default country / currency - fixed issues on RSS links in default front office template - fixed random issues on position tests
This commit is contained in:
@@ -16,6 +16,8 @@ class Country extends BaseCountry
|
|||||||
{
|
{
|
||||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||||
|
|
||||||
|
protected static $defaultCountry = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Put the current country as the default one.
|
* Put the current country as the default one.
|
||||||
@@ -93,16 +95,19 @@ class Country extends BaseCountry
|
|||||||
/**
|
/**
|
||||||
* Return the default country
|
* Return the default country
|
||||||
*
|
*
|
||||||
* @throws LogicException if no default country is defined
|
* @throws \LogicException if no default country is defined
|
||||||
*/
|
*/
|
||||||
public static function getDefaultCountry()
|
public static function getDefaultCountry()
|
||||||
{
|
{
|
||||||
$dc = CountryQuery::create()->findOneByByDefault(true);
|
if (null === self::$defaultCountry) {
|
||||||
|
self::$defaultCountry = CountryQuery::create()->findOneByByDefault(true);
|
||||||
|
|
||||||
if ($dc == null)
|
if (null === self::$defaultCountry) {
|
||||||
throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one."));
|
throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $dc;
|
return self::$defaultCountry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,15 +14,20 @@ class Currency extends BaseCurrency
|
|||||||
|
|
||||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||||
|
|
||||||
|
protected static $defaultCurrency = null;
|
||||||
|
|
||||||
public static function getDefaultCurrency()
|
public static function getDefaultCurrency()
|
||||||
{
|
{
|
||||||
$currency = CurrencyQuery::create()->findOneByByDefault(1);
|
if (null === self::$defaultCurrency) {
|
||||||
|
|
||||||
if (null === $currency) {
|
self::$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
|
||||||
throw new \RuntimeException("No default currency is defined. Please define one.");
|
|
||||||
|
if (null === self::$defaultCurrency) {
|
||||||
|
throw new \RuntimeException("No default currency is defined. Please define one.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $currency;
|
return self::$defaultCurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ class Lang extends BaseLang
|
|||||||
if (null === self::$defaultLanguage) {
|
if (null === self::$defaultLanguage) {
|
||||||
self::$defaultLanguage = LangQuery::create()->findOneByByDefault(1);
|
self::$defaultLanguage = LangQuery::create()->findOneByByDefault(1);
|
||||||
|
|
||||||
if (self::$defaultLanguage == null) throw new \RuntimeException("No default language is defined. Please define one.");
|
if (null === self::$defaultLanguage) {
|
||||||
|
throw new \RuntimeException("No default language is defined. Please define one.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$defaultLanguage;
|
return self::$defaultLanguage;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
namespace Thelia\Tests\Action;
|
namespace Thelia\Tests\Action;
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
|
use Propel\Runtime\Collection\Collection;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Thelia\Action\Content;
|
use Thelia\Action\Content;
|
||||||
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
||||||
@@ -24,7 +25,9 @@ use Thelia\Core\Event\UpdatePositionEvent;
|
|||||||
use Thelia\Model\ContentFolder;
|
use Thelia\Model\ContentFolder;
|
||||||
use Thelia\Model\ContentFolderQuery;
|
use Thelia\Model\ContentFolderQuery;
|
||||||
use Thelia\Model\ContentQuery;
|
use Thelia\Model\ContentQuery;
|
||||||
|
use Thelia\Model\Folder;
|
||||||
use Thelia\Model\FolderQuery;
|
use Thelia\Model\FolderQuery;
|
||||||
|
use Thelia\Model\Map\ContentFolderTableMap;
|
||||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,6 +42,8 @@ class ContentTest extends TestCaseWithURLToolSetup
|
|||||||
*/
|
*/
|
||||||
protected $dispatcher;
|
protected $dispatcher;
|
||||||
|
|
||||||
|
protected static $folderForPositionTest = null;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||||
@@ -167,6 +172,7 @@ class ContentTest extends TestCaseWithURLToolSetup
|
|||||||
public function testUpdatePositionUp()
|
public function testUpdatePositionUp()
|
||||||
{
|
{
|
||||||
$content = ContentQuery::create()
|
$content = ContentQuery::create()
|
||||||
|
->filterByFolder($this->getFolderForPositionTest(), Criteria::EQUAL)
|
||||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
@@ -190,6 +196,7 @@ class ContentTest extends TestCaseWithURLToolSetup
|
|||||||
public function testUpdatePositionDown()
|
public function testUpdatePositionDown()
|
||||||
{
|
{
|
||||||
$content = ContentQuery::create()
|
$content = ContentQuery::create()
|
||||||
|
->filterByFolder($this->getFolderForPositionTest())
|
||||||
->filterByPosition(1)
|
->filterByPosition(1)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
@@ -213,6 +220,7 @@ class ContentTest extends TestCaseWithURLToolSetup
|
|||||||
public function testUpdatePositionWithSpecificPosition()
|
public function testUpdatePositionWithSpecificPosition()
|
||||||
{
|
{
|
||||||
$content = ContentQuery::create()
|
$content = ContentQuery::create()
|
||||||
|
->filterByFolder($this->getFolderForPositionTest())
|
||||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
@@ -296,6 +304,55 @@ class ContentTest extends TestCaseWithURLToolSetup
|
|||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generates a folder and its contents to be used in Position tests
|
||||||
|
*
|
||||||
|
* @return Folder the parent folder
|
||||||
|
*/
|
||||||
|
protected function getFolderForPositionTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (null === self::$folderForPositionTest) {
|
||||||
|
|
||||||
|
$folder = new Folder();
|
||||||
|
|
||||||
|
$folder->setParent(0);
|
||||||
|
$folder->setVisible(1);
|
||||||
|
$folder->setPosition(1);
|
||||||
|
|
||||||
|
$folder
|
||||||
|
->setLocale('en_US')
|
||||||
|
->setTitle('folder test');
|
||||||
|
|
||||||
|
$folder->save();
|
||||||
|
|
||||||
|
for ($i = 0; $i < 4; $i++) {
|
||||||
|
|
||||||
|
$content = new \Thelia\Model\Content();
|
||||||
|
|
||||||
|
$content->addFolder($folder);
|
||||||
|
$content->setVisible(1);
|
||||||
|
$content->setPosition($i + 1);
|
||||||
|
|
||||||
|
$content
|
||||||
|
->setLocale('en_US')
|
||||||
|
->setTitle(sprintf('content test %s', $i));
|
||||||
|
|
||||||
|
$contentFolders = $content->getContentFolders();
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->prepend($contentFolders[0]->setDefaultFolder(1));
|
||||||
|
$content->setContentFolders($collection);
|
||||||
|
|
||||||
|
$content->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$folderForPositionTest = $folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$folderForPositionTest;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Thelia\Model\Folder
|
* @return \Thelia\Model\Folder
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use Thelia\Core\Event\Folder\FolderUpdateEvent;
|
|||||||
use Thelia\Core\Event\UpdatePositionEvent;
|
use Thelia\Core\Event\UpdatePositionEvent;
|
||||||
use Thelia\Core\Event\UpdateSeoEvent;
|
use Thelia\Core\Event\UpdateSeoEvent;
|
||||||
use Thelia\Model\FolderQuery;
|
use Thelia\Model\FolderQuery;
|
||||||
|
use Thelia\Model\Map\FolderTableMap;
|
||||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,6 +38,9 @@ class FolderTest extends TestCaseWithURLToolSetup
|
|||||||
*/
|
*/
|
||||||
protected $dispatcher;
|
protected $dispatcher;
|
||||||
|
|
||||||
|
/** @var int folder id used in position tests */
|
||||||
|
protected static $folderIdForPositionTest = null;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||||
@@ -200,6 +204,7 @@ class FolderTest extends TestCaseWithURLToolSetup
|
|||||||
public function testUpdatePositionUp()
|
public function testUpdatePositionUp()
|
||||||
{
|
{
|
||||||
$folder = FolderQuery::create()
|
$folder = FolderQuery::create()
|
||||||
|
->filterByParent($this->getFolderIdForPositionTest())
|
||||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
@@ -223,6 +228,7 @@ class FolderTest extends TestCaseWithURLToolSetup
|
|||||||
public function testUpdatePositionDown()
|
public function testUpdatePositionDown()
|
||||||
{
|
{
|
||||||
$nextFolder = FolderQuery::create()
|
$nextFolder = FolderQuery::create()
|
||||||
|
->filterByParent($this->getFolderIdForPositionTest())
|
||||||
->filterByPosition(2)
|
->filterByPosition(2)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
@@ -255,6 +261,7 @@ class FolderTest extends TestCaseWithURLToolSetup
|
|||||||
public function testUpdatePositionWithSpecificPosition()
|
public function testUpdatePositionWithSpecificPosition()
|
||||||
{
|
{
|
||||||
$folder = FolderQuery::create()
|
$folder = FolderQuery::create()
|
||||||
|
->filterByParent($this->getFolderIdForPositionTest())
|
||||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
@@ -274,6 +281,50 @@ class FolderTest extends TestCaseWithURLToolSetup
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generates a folder and its sub folders to be used in Position tests
|
||||||
|
*
|
||||||
|
* @return int the parent folder id
|
||||||
|
*/
|
||||||
|
protected function getFolderIdForPositionTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (null === self::$folderIdForPositionTest) {
|
||||||
|
|
||||||
|
$folder = new \Thelia\Model\Folder();
|
||||||
|
|
||||||
|
$folder->setParent(0);
|
||||||
|
$folder->setVisible(1);
|
||||||
|
$folder->setPosition(1);
|
||||||
|
$folder
|
||||||
|
->setLocale('en_US')
|
||||||
|
->setTitle('folder test');
|
||||||
|
|
||||||
|
$folder->save();
|
||||||
|
|
||||||
|
for ($i = 0; $i < 4; $i++) {
|
||||||
|
|
||||||
|
$subFolder = new \Thelia\Model\Folder();
|
||||||
|
|
||||||
|
$subFolder->setParent($folder->getId());
|
||||||
|
$subFolder->setVisible(1);
|
||||||
|
$subFolder->setPosition($i + 1);
|
||||||
|
|
||||||
|
$folder
|
||||||
|
->setLocale('en_US')
|
||||||
|
->setTitle(sprintf('folder test %s', $i));
|
||||||
|
|
||||||
|
$subFolder->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$folderIdForPositionTest = $folder->getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$folderIdForPositionTest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Thelia\Model\Folder
|
* @return \Thelia\Model\Folder
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
{* Feeds *}
|
{* Feeds *}
|
||||||
{block name="feeds"}
|
{block name="feeds"}
|
||||||
<link rel="alternate" type="application/rss+xml" title="{intl l='All products in'} {category attr='title'}" href="{url path="/feed/catalog/{lang attr="locale"}/{content attr="id"}"}" />
|
<link rel="alternate" type="application/rss+xml" title="{intl l='All products in'} {category attr='title'}" href="{url path="/feed/catalog/{lang attr="locale"}/{category attr="id"}"}" />
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
{* Breadcrumb *}
|
{* Breadcrumb *}
|
||||||
|
|||||||
@@ -18,11 +18,6 @@
|
|||||||
{/loop}
|
{/loop}
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
{* Feeds *}
|
|
||||||
{block name="feeds"}
|
|
||||||
<link rel="alternate" type="application/rss+xml" title="{intl l='All contents in'} {content attr='title'}" href="{url path="/feed/content/{lang attr="locale"}/{content attr="id"}"}" />
|
|
||||||
{/block}
|
|
||||||
|
|
||||||
{* Breadcrumb *}
|
{* Breadcrumb *}
|
||||||
{block name='no-return-functions' append}
|
{block name='no-return-functions' append}
|
||||||
{$breadcrumbs = []}
|
{$breadcrumbs = []}
|
||||||
|
|||||||
@@ -26,6 +26,10 @@
|
|||||||
{/loop}
|
{/loop}
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
|
{block name="feeds"}
|
||||||
|
<link rel="alternate" type="application/rss+xml" title="{intl l='All contents in'} {folder attr='title'}" href="{url path="/feed/content/{lang attr="locale"}/{folder attr="id"}"}" />
|
||||||
|
{/block}
|
||||||
|
|
||||||
{* Content *}
|
{* Content *}
|
||||||
{block name="main-content"}
|
{block name="main-content"}
|
||||||
<div class="main">
|
<div class="main">
|
||||||
|
|||||||
Reference in New Issue
Block a user