Initial commit
This commit is contained in:
53
tests/phpunit/Thelia/Tests/Action/I18nTestTrait.php
Normal file
53
tests/phpunit/Thelia/Tests/Action/I18nTestTrait.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user