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] 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 */