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:
Julien
2014-07-04 09:09:50 +02:00
8 changed files with 135 additions and 16 deletions

View File

@@ -16,6 +16,8 @@ class Country extends BaseCountry
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
protected static $defaultCountry = null;
/**
*
* Put the current country as the default one.
@@ -93,16 +95,19 @@ class Country extends BaseCountry
/**
* Return the default country
*
* @throws LogicException if no default country is defined
* @throws \LogicException if no default country is defined
*/
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."));
}
}
return $dc;
return self::$defaultCountry;
}
/**

View File

@@ -14,15 +14,20 @@ class Currency extends BaseCurrency
use \Thelia\Model\Tools\PositionManagementTrait;
protected static $defaultCurrency = null;
public static function getDefaultCurrency()
{
$currency = CurrencyQuery::create()->findOneByByDefault(1);
if (null === self::$defaultCurrency) {
if (null === $currency) {
self::$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
if (null === self::$defaultCurrency) {
throw new \RuntimeException("No default currency is defined. Please define one.");
}
}
return $currency;
return self::$defaultCurrency;
}
/**

View File

@@ -30,7 +30,9 @@ class Lang extends BaseLang
if (null === self::$defaultLanguage) {
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;

View File

@@ -12,6 +12,7 @@
namespace Thelia\Tests\Action;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Collection\Collection;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Action\Content;
use Thelia\Core\Event\Content\ContentAddFolderEvent;
@@ -24,7 +25,9 @@ use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Model\ContentFolder;
use Thelia\Model\ContentFolderQuery;
use Thelia\Model\ContentQuery;
use Thelia\Model\Folder;
use Thelia\Model\FolderQuery;
use Thelia\Model\Map\ContentFolderTableMap;
use Thelia\Tests\TestCaseWithURLToolSetup;
/**
@@ -39,6 +42,8 @@ class ContentTest extends TestCaseWithURLToolSetup
*/
protected $dispatcher;
protected static $folderForPositionTest = null;
public function setUp()
{
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
@@ -167,6 +172,7 @@ class ContentTest extends TestCaseWithURLToolSetup
public function testUpdatePositionUp()
{
$content = ContentQuery::create()
->filterByFolder($this->getFolderForPositionTest(), Criteria::EQUAL)
->filterByPosition(1, Criteria::GREATER_THAN)
->findOne();
@@ -190,6 +196,7 @@ class ContentTest extends TestCaseWithURLToolSetup
public function testUpdatePositionDown()
{
$content = ContentQuery::create()
->filterByFolder($this->getFolderForPositionTest())
->filterByPosition(1)
->findOne();
@@ -213,6 +220,7 @@ class ContentTest extends TestCaseWithURLToolSetup
public function testUpdatePositionWithSpecificPosition()
{
$content = ContentQuery::create()
->filterByFolder($this->getFolderForPositionTest())
->filterByPosition(1, Criteria::GREATER_THAN)
->findOne();
@@ -296,6 +304,55 @@ class ContentTest extends TestCaseWithURLToolSetup
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
*/

View File

@@ -21,6 +21,7 @@ use Thelia\Core\Event\Folder\FolderUpdateEvent;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\Event\UpdateSeoEvent;
use Thelia\Model\FolderQuery;
use Thelia\Model\Map\FolderTableMap;
use Thelia\Tests\TestCaseWithURLToolSetup;
/**
@@ -37,6 +38,9 @@ class FolderTest extends TestCaseWithURLToolSetup
*/
protected $dispatcher;
/** @var int folder id used in position tests */
protected static $folderIdForPositionTest = null;
public function setUp()
{
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
@@ -200,6 +204,7 @@ class FolderTest extends TestCaseWithURLToolSetup
public function testUpdatePositionUp()
{
$folder = FolderQuery::create()
->filterByParent($this->getFolderIdForPositionTest())
->filterByPosition(1, Criteria::GREATER_THAN)
->findOne();
@@ -223,6 +228,7 @@ class FolderTest extends TestCaseWithURLToolSetup
public function testUpdatePositionDown()
{
$nextFolder = FolderQuery::create()
->filterByParent($this->getFolderIdForPositionTest())
->filterByPosition(2)
->findOne();
@@ -255,6 +261,7 @@ class FolderTest extends TestCaseWithURLToolSetup
public function testUpdatePositionWithSpecificPosition()
{
$folder = FolderQuery::create()
->filterByParent($this->getFolderIdForPositionTest())
->filterByPosition(1, Criteria::GREATER_THAN)
->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
*/

View File

@@ -20,7 +20,7 @@
{* 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}
{* Breadcrumb *}

View File

@@ -18,11 +18,6 @@
{/loop}
{/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 *}
{block name='no-return-functions' append}
{$breadcrumbs = []}

View File

@@ -26,6 +26,10 @@
{/loop}
{/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 *}
{block name="main-content"}
<div class="main">