Merge pull request #510 from bibich/improvements

fixed new issue on rewriting test due to blank titles on some locale
This commit is contained in:
Julien
2014-07-04 15:39:16 +02:00
3 changed files with 70 additions and 13 deletions

View File

@@ -22,6 +22,7 @@ use Thelia\Core\Event\Content\ContentRemoveFolderEvent;
use Thelia\Core\Event\Content\ContentToggleVisibilityEvent;
use Thelia\Core\Event\Content\ContentUpdateEvent;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Model\LangQuery;
use Thelia\Model\ContentFolder;
use Thelia\Model\ContentFolderQuery;
use Thelia\Model\ContentQuery;
@@ -37,6 +38,8 @@ use Thelia\Tests\TestCaseWithURLToolSetup;
*/
class ContentTest extends TestCaseWithURLToolSetup
{
use I18nTestTrait;
/**
* @var EventDispatcherInterface
*/
@@ -288,6 +291,7 @@ class ContentTest extends TestCaseWithURLToolSetup
$this->assertNull($testAssociation);
}
/**
* @return \Thelia\Model\Content
*/
@@ -320,9 +324,7 @@ class ContentTest extends TestCaseWithURLToolSetup
$folder->setVisible(1);
$folder->setPosition(1);
$folder
->setLocale('en_US')
->setTitle('folder test');
$this->setI18n($folder);
$folder->save();
@@ -334,9 +336,7 @@ class ContentTest extends TestCaseWithURLToolSetup
$content->setVisible(1);
$content->setPosition($i + 1);
$content
->setLocale('en_US')
->setTitle(sprintf('content test %s', $i));
$this->setI18n($content);
$contentFolders = $content->getContentFolders();
$collection = new Collection();

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\LangQuery;
use Thelia\Model\Map\FolderTableMap;
use Thelia\Tests\TestCaseWithURLToolSetup;
@@ -32,6 +33,7 @@ use Thelia\Tests\TestCaseWithURLToolSetup;
class FolderTest extends TestCaseWithURLToolSetup
{
use RewrittenUrlTestTrait;
use I18nTestTrait;
/**
* @var EventDispatcherInterface
@@ -297,9 +299,8 @@ class FolderTest extends TestCaseWithURLToolSetup
$folder->setParent(0);
$folder->setVisible(1);
$folder->setPosition(1);
$folder
->setLocale('en_US')
->setTitle('folder test');
$this->setI18n($folder);
$folder->save();
@@ -311,9 +312,7 @@ class FolderTest extends TestCaseWithURLToolSetup
$subFolder->setVisible(1);
$subFolder->setPosition($i + 1);
$folder
->setLocale('en_US')
->setTitle(sprintf('folder test %s', $i));
$this->setI18n($subFolder);
$subFolder->save();
}
@@ -324,7 +323,6 @@ class FolderTest extends TestCaseWithURLToolSetup
return self::$folderIdForPositionTest;
}
/**
* @return \Thelia\Model\Folder
*/

View File

@@ -0,0 +1,59 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Action;
use Thelia\Model\LangQuery;
/**
* Class I18NTestTrait
* @package Thelia\Tests\Action
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
trait I18nTestTrait
{
/** @var array list of available locale */
protected static $localeList = null;
/**
* populate a list of field for each locale for an object
*
* @param mixed $object the object to populate
* @param array $fields list of field to populate
* @param array $localeList list of locale to use populate the object
*/
protected function setI18n(&$object, $fields = array("Title"), $localeList = null)
{
if (null === $localeList) {
if (null === self::$localeList) {
self::$localeList = LangQuery::create()
->select("Locale")
->find()
->toArray();
}
$localeList = self::$localeList;
}
foreach ($localeList as $locale) {
foreach ($fields as $name) {
$object->getTranslation($locale)->setByName($name, $locale . ' : ' . $name);
}
}
}
}