addded test data for position tests
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
namespace Thelia\Tests\Action;
|
namespace Thelia\Tests\Action;
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
|
use Propel\Runtime\Collection\Collection;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Thelia\Action\Content;
|
use Thelia\Action\Content;
|
||||||
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
||||||
@@ -41,6 +42,8 @@ class ContentTest extends TestCaseWithURLToolSetup
|
|||||||
*/
|
*/
|
||||||
protected $dispatcher;
|
protected $dispatcher;
|
||||||
|
|
||||||
|
protected static $folderForPositionTest = null;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||||
@@ -169,7 +172,7 @@ class ContentTest extends TestCaseWithURLToolSetup
|
|||||||
public function testUpdatePositionUp()
|
public function testUpdatePositionUp()
|
||||||
{
|
{
|
||||||
$content = ContentQuery::create()
|
$content = ContentQuery::create()
|
||||||
->filterByFolder($this->getFolderForPositionTest(), Criteria::IN)
|
->filterByFolder($this->getFolderForPositionTest(), Criteria::EQUAL)
|
||||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||||
->findOne();
|
->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()
|
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) {
|
if (null === self::$folderForPositionTest) {
|
||||||
$this->fail('use fixtures before launching test, there is not enough content in database');
|
|
||||||
|
$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"]);
|
return self::$folderForPositionTest;
|
||||||
if (null === $folder) {
|
|
||||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $folder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ class FolderTest extends TestCaseWithURLToolSetup
|
|||||||
*/
|
*/
|
||||||
protected $dispatcher;
|
protected $dispatcher;
|
||||||
|
|
||||||
|
/** @var int folder id used in position tests */
|
||||||
|
protected static $folderIdForPositionTest = null;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
$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()
|
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) {
|
if (null === self::$folderIdForPositionTest) {
|
||||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
|
||||||
|
$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
|
* @return \Thelia\Model\Folder
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user