diff --git a/core/lib/Thelia/Core/Template/Loop/CategoryTree.php b/core/lib/Thelia/Core/Template/Loop/CategoryTree.php index 2cc4435b7..9c5ce1b6f 100644 --- a/core/lib/Thelia/Core/Template/Loop/CategoryTree.php +++ b/core/lib/Thelia/Core/Template/Loop/CategoryTree.php @@ -61,7 +61,7 @@ class CategoryTree extends BaseI18nLoop implements ArraySearchLoopInterface $search->filterByParent($parent); - if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible); + if ($visible !== BooleanOrBothType::ANY) $search->filterByVisible($visible); if ($exclude != null) $search->filterById($exclude, Criteria::NOT_IN); diff --git a/core/lib/Thelia/Model/Country.php b/core/lib/Thelia/Model/Country.php index 038bd5a61..ccaabd79b 100644 --- a/core/lib/Thelia/Model/Country.php +++ b/core/lib/Thelia/Model/Country.php @@ -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) - throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one.")); + if (null === self::$defaultCountry) { + throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one.")); + } + } - return $dc; + return self::$defaultCountry; } /** diff --git a/core/lib/Thelia/Model/Currency.php b/core/lib/Thelia/Model/Currency.php index 706553430..d12bbd2ea 100644 --- a/core/lib/Thelia/Model/Currency.php +++ b/core/lib/Thelia/Model/Currency.php @@ -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) { - throw new \RuntimeException("No default currency is defined. Please define one."); + 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; } /** diff --git a/core/lib/Thelia/Model/Lang.php b/core/lib/Thelia/Model/Lang.php index 546eb7b20..42041941c 100644 --- a/core/lib/Thelia/Model/Lang.php +++ b/core/lib/Thelia/Model/Lang.php @@ -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; diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index 6f224f83a..e5021ea74 100644 --- a/core/lib/Thelia/Tests/Action/ContentTest.php +++ b/core/lib/Thelia/Tests/Action/ContentTest.php @@ -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 */ diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index 21416bfa3..bd7be2366 100644 --- a/core/lib/Thelia/Tests/Action/FolderTest.php +++ b/core/lib/Thelia/Tests/Action/FolderTest.php @@ -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 */ diff --git a/templates/frontOffice/default/category.html b/templates/frontOffice/default/category.html index 68df28411..c421d10c1 100644 --- a/templates/frontOffice/default/category.html +++ b/templates/frontOffice/default/category.html @@ -20,7 +20,7 @@ {* Feeds *} {block name="feeds"} - + {/block} {* Breadcrumb *} diff --git a/templates/frontOffice/default/content.html b/templates/frontOffice/default/content.html index 398072a39..59775fa78 100644 --- a/templates/frontOffice/default/content.html +++ b/templates/frontOffice/default/content.html @@ -18,11 +18,6 @@ {/loop} {/block} -{* Feeds *} -{block name="feeds"} - -{/block} - {* Breadcrumb *} {block name='no-return-functions' append} {$breadcrumbs = []} diff --git a/templates/frontOffice/default/folder.html b/templates/frontOffice/default/folder.html index b95bfc2cd..00020f4d5 100644 --- a/templates/frontOffice/default/folder.html +++ b/templates/frontOffice/default/folder.html @@ -26,6 +26,10 @@ {/loop} {/block} +{block name="feeds"} + +{/block} + {* Content *} {block name="main-content"}