From ec719599341d7689157670ffcdc9198e3ebedf51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Wed, 2 Jul 2014 09:22:20 +0200 Subject: [PATCH 1/6] Fixed issues with RSS feed links --- templates/frontOffice/default/category.html | 2 +- templates/frontOffice/default/content.html | 5 ----- templates/frontOffice/default/folder.html | 4 ++++ 3 files changed, 5 insertions(+), 6 deletions(-) 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"}
From 3a9ce68694f150b27f47f04d97fee7cdee460d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Wed, 2 Jul 2014 09:55:14 +0200 Subject: [PATCH 2/6] added cache to get default country and currency --- core/lib/Thelia/Model/Country.php | 15 ++++++++++----- core/lib/Thelia/Model/Currency.php | 13 +++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/core/lib/Thelia/Model/Country.php b/core/lib/Thelia/Model/Country.php index 038bd5a61..9d94c6824 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 (self::$defaultCountry == null) { + 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..6a19088f7 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 (self::$defaultCurrency == null) { + throw new \RuntimeException("No default currency is defined. Please define one."); + } } - return $currency; + return self::$defaultCurrency; } /** From 791323776a9452d036214d314c44b2640525b187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Wed, 2 Jul 2014 10:32:25 +0200 Subject: [PATCH 3/6] added strict test === --- core/lib/Thelia/Model/Country.php | 2 +- core/lib/Thelia/Model/Currency.php | 2 +- core/lib/Thelia/Model/Lang.php | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Model/Country.php b/core/lib/Thelia/Model/Country.php index 9d94c6824..ccaabd79b 100644 --- a/core/lib/Thelia/Model/Country.php +++ b/core/lib/Thelia/Model/Country.php @@ -102,7 +102,7 @@ class Country extends BaseCountry if (null === self::$defaultCountry) { self::$defaultCountry = CountryQuery::create()->findOneByByDefault(true); - if (self::$defaultCountry == null) { + if (null === self::$defaultCountry) { throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one.")); } } diff --git a/core/lib/Thelia/Model/Currency.php b/core/lib/Thelia/Model/Currency.php index 6a19088f7..d12bbd2ea 100644 --- a/core/lib/Thelia/Model/Currency.php +++ b/core/lib/Thelia/Model/Currency.php @@ -22,7 +22,7 @@ class Currency extends BaseCurrency self::$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1); - if (self::$defaultCurrency == null) { + if (null === self::$defaultCurrency) { throw new \RuntimeException("No default currency is defined. Please define one."); } } 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; From 182ba260452b4dfd97498fb9f2225b9d64eae76f Mon Sep 17 00:00:00 2001 From: Guillaume Barral Date: Wed, 2 Jul 2014 11:47:27 +0200 Subject: [PATCH 4/6] correction of the filter visible in categoryTree. --- core/lib/Thelia/Core/Template/Loop/CategoryTree.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 8436c25c45ea475fae25407febfc172e9517d57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Wed, 2 Jul 2014 15:07:27 +0200 Subject: [PATCH 5/6] fixed painful issues on tests that generated random errors on positions --- core/lib/Thelia/Tests/Action/ContentTest.php | 33 ++++++++++++++++++++ core/lib/Thelia/Tests/Action/FolderTest.php | 25 +++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index 6f224f83a..89600b53f 100644 --- a/core/lib/Thelia/Tests/Action/ContentTest.php +++ b/core/lib/Thelia/Tests/Action/ContentTest.php @@ -24,7 +24,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; /** @@ -167,6 +169,7 @@ class ContentTest extends TestCaseWithURLToolSetup public function testUpdatePositionUp() { $content = ContentQuery::create() + ->filterByFolder($this->getFolderForPositionTest(), Criteria::IN) ->filterByPosition(1, Criteria::GREATER_THAN) ->findOne(); @@ -190,6 +193,7 @@ class ContentTest extends TestCaseWithURLToolSetup public function testUpdatePositionDown() { $content = ContentQuery::create() + ->filterByFolder($this->getFolderForPositionTest()) ->filterByPosition(1) ->findOne(); @@ -213,6 +217,7 @@ class ContentTest extends TestCaseWithURLToolSetup public function testUpdatePositionWithSpecificPosition() { $content = ContentQuery::create() + ->filterByFolder($this->getFolderForPositionTest()) ->filterByPosition(1, Criteria::GREATER_THAN) ->findOne(); @@ -296,6 +301,34 @@ class ContentTest extends TestCaseWithURLToolSetup return $content; } + /** + * get a folder that has enough content to execute position tests + * + * @return Folder the folder + */ + protected function getFolderForPositionTest() + { + $content = ContentFolderQuery::create() + ->filterByDefaultFolder(true) + ->withColumn('count(' . ContentFolderTableMap::FOLDER_ID . ')', 'nb') + ->groupBy('FolderId') + ->having('count(' . ContentFolderTableMap::FOLDER_ID . ') >= ?', 3, \PDO::PARAM_INT) + ->select(array('FolderId', 'nb')) + ->findOne() + ; + + if (null === $content) { + $this->fail('use fixtures before launching test, there is not enough content in database'); + } + + $folder = FolderQuery::create()->findPK($content["FolderId"]); + if (null === $folder) { + $this->fail('use fixtures before launching test, there is no folder in database'); + } + + return $folder; + } + /** * @return \Thelia\Model\Folder */ diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index 21416bfa3..bd2b2a856 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; /** @@ -200,6 +201,7 @@ class FolderTest extends TestCaseWithURLToolSetup public function testUpdatePositionUp() { $folder = FolderQuery::create() + ->filterByParent($this->getFolderIdForPositionTest()) ->filterByPosition(1, Criteria::GREATER_THAN) ->findOne(); @@ -223,6 +225,7 @@ class FolderTest extends TestCaseWithURLToolSetup public function testUpdatePositionDown() { $nextFolder = FolderQuery::create() + ->filterByParent($this->getFolderIdForPositionTest()) ->filterByPosition(2) ->findOne(); @@ -255,6 +258,7 @@ class FolderTest extends TestCaseWithURLToolSetup public function testUpdatePositionWithSpecificPosition() { $folder = FolderQuery::create() + ->filterByParent($this->getFolderIdForPositionTest()) ->filterByPosition(1, Criteria::GREATER_THAN) ->findOne(); @@ -274,6 +278,27 @@ class FolderTest extends TestCaseWithURLToolSetup } + /** + * get a folder parent id that has enough folder to execute position tests + * + * @return int the folder id + */ + protected function getFolderIdForPositionTest() + { + $f = FolderQuery::create() + ->withColumn('count(' . FolderTableMap::PARENT . ')', 'nb') + ->groupBy('Parent') + ->having('count(' . FolderTableMap::PARENT . ') > ?', 3, \PDO::PARAM_INT) + ->select(array('Parent', 'nb')) + ->findOne(); + + if (null === $f) { + $this->fail('use fixtures before launching test, there is no folder in database'); + } + + return $f["Parent"]; + } + /** * @return \Thelia\Model\Folder */ From 9d79f42ae1df02890125e8f8df31004ae3110d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Thu, 3 Jul 2014 16:25:18 +0200 Subject: [PATCH 6/6] addded test data for position tests --- core/lib/Thelia/Tests/Action/ContentTest.php | 62 ++++++++++++++------ core/lib/Thelia/Tests/Action/FolderTest.php | 48 +++++++++++---- 2 files changed, 80 insertions(+), 30 deletions(-) diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index 89600b53f..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; @@ -41,6 +42,8 @@ class ContentTest extends TestCaseWithURLToolSetup */ protected $dispatcher; + protected static $folderForPositionTest = null; + public function setUp() { $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); @@ -169,7 +172,7 @@ class ContentTest extends TestCaseWithURLToolSetup public function testUpdatePositionUp() { $content = ContentQuery::create() - ->filterByFolder($this->getFolderForPositionTest(), Criteria::IN) + ->filterByFolder($this->getFolderForPositionTest(), Criteria::EQUAL) ->filterByPosition(1, Criteria::GREATER_THAN) ->findOne(); @@ -302,31 +305,52 @@ class ContentTest extends TestCaseWithURLToolSetup } /** - * get a folder that has enough content to execute position tests + * generates a folder and its contents to be used in Position tests * - * @return Folder the folder + * @return Folder the parent folder */ protected function getFolderForPositionTest() { - $content = ContentFolderQuery::create() - ->filterByDefaultFolder(true) - ->withColumn('count(' . ContentFolderTableMap::FOLDER_ID . ')', 'nb') - ->groupBy('FolderId') - ->having('count(' . ContentFolderTableMap::FOLDER_ID . ') >= ?', 3, \PDO::PARAM_INT) - ->select(array('FolderId', 'nb')) - ->findOne() - ; - if (null === $content) { - $this->fail('use fixtures before launching test, there is not enough content in database'); + 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; } - $folder = FolderQuery::create()->findPK($content["FolderId"]); - if (null === $folder) { - $this->fail('use fixtures before launching test, there is no folder in database'); - } - - return $folder; + return self::$folderForPositionTest; } /** diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index bd2b2a856..bd7be2366 100644 --- a/core/lib/Thelia/Tests/Action/FolderTest.php +++ b/core/lib/Thelia/Tests/Action/FolderTest.php @@ -38,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"); @@ -278,27 +281,50 @@ class FolderTest extends TestCaseWithURLToolSetup } + /** - * get a folder parent id that has enough folder to execute position tests + * generates a folder and its sub folders to be used in Position tests * - * @return int the folder id + * @return int the parent folder id */ protected function getFolderIdForPositionTest() { - $f = FolderQuery::create() - ->withColumn('count(' . FolderTableMap::PARENT . ')', 'nb') - ->groupBy('Parent') - ->having('count(' . FolderTableMap::PARENT . ') > ?', 3, \PDO::PARAM_INT) - ->select(array('Parent', 'nb')) - ->findOne(); - if (null === $f) { - $this->fail('use fixtures before launching test, there is no folder in database'); + 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 $f["Parent"]; + return self::$folderIdForPositionTest; } + /** * @return \Thelia\Model\Folder */