optimization
This commit is contained in:
@@ -38,6 +38,8 @@ use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
*/
|
||||
class ContentTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
use I18nTestTrait;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
@@ -322,7 +324,7 @@ class ContentTest extends TestCaseWithURLToolSetup
|
||||
$folder->setVisible(1);
|
||||
$folder->setPosition(1);
|
||||
|
||||
$this->setI18N($folder, "folder");
|
||||
$this->setI18n($folder);
|
||||
|
||||
$folder->save();
|
||||
|
||||
@@ -334,7 +336,7 @@ class ContentTest extends TestCaseWithURLToolSetup
|
||||
$content->setVisible(1);
|
||||
$content->setPosition($i + 1);
|
||||
|
||||
$this->setI18N($content, "content");
|
||||
$this->setI18n($content);
|
||||
|
||||
$contentFolders = $content->getContentFolders();
|
||||
$collection = new Collection();
|
||||
@@ -351,27 +353,6 @@ class ContentTest extends TestCaseWithURLToolSetup
|
||||
return self::$folderForPositionTest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title of te object in all locales
|
||||
*
|
||||
* @param mixed $object
|
||||
* @param string $title
|
||||
*/
|
||||
public function setI18N(&$object, $title)
|
||||
{
|
||||
|
||||
$localeList = LangQuery::create()
|
||||
->select("Locale")
|
||||
->find()
|
||||
->toArray();
|
||||
|
||||
foreach ($localeList as $locale) {
|
||||
$object->setLocale($locale);
|
||||
$object->setTitle($locale . ' : ' . $title);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Folder
|
||||
*/
|
||||
|
||||
@@ -33,6 +33,7 @@ use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
class FolderTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
use RewrittenUrlTestTrait;
|
||||
use I18nTestTrait;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
@@ -299,7 +300,7 @@ class FolderTest extends TestCaseWithURLToolSetup
|
||||
$folder->setVisible(1);
|
||||
$folder->setPosition(1);
|
||||
|
||||
$this->setI18N($folder, "folder");
|
||||
$this->setI18n($folder);
|
||||
|
||||
$folder->save();
|
||||
|
||||
@@ -311,7 +312,7 @@ class FolderTest extends TestCaseWithURLToolSetup
|
||||
$subFolder->setVisible(1);
|
||||
$subFolder->setPosition($i + 1);
|
||||
|
||||
$this->setI18N($subFolder, "sub folder");
|
||||
$this->setI18n($subFolder);
|
||||
|
||||
$subFolder->save();
|
||||
}
|
||||
@@ -322,27 +323,6 @@ class FolderTest extends TestCaseWithURLToolSetup
|
||||
return self::$folderIdForPositionTest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title of te object in all locales
|
||||
*
|
||||
* @param mixed $object
|
||||
* @param string $title
|
||||
*/
|
||||
public function setI18N(&$object, $title)
|
||||
{
|
||||
|
||||
$localeList = LangQuery::create()
|
||||
->select("Locale")
|
||||
->find()
|
||||
->toArray();
|
||||
|
||||
foreach ($localeList as $locale) {
|
||||
$object->setLocale($locale);
|
||||
$object->setTitle($locale . ' : ' . $title);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Folder
|
||||
*/
|
||||
|
||||
65
core/lib/Thelia/Tests/Action/I18nTestTrait.php
Normal file
65
core/lib/Thelia/Tests/Action/I18nTestTrait.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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) {
|
||||
|
||||
$object->setLocale($locale);
|
||||
|
||||
foreach ($fields as $name) {
|
||||
|
||||
$func = "set" . ucfirst(strtolower($name));
|
||||
|
||||
$object->$func($locale . ' : ' . $name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user