fixed painful issues on tests that generated random errors on positions

This commit is contained in:
Julien Chanséaume
2014-07-02 15:07:27 +02:00
parent 791323776a
commit 8436c25c45
2 changed files with 58 additions and 0 deletions

View File

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

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;
/**
@@ -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
*/