diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index e5021ea74..6c0c1275b 100644 --- a/core/lib/Thelia/Tests/Action/ContentTest.php +++ b/core/lib/Thelia/Tests/Action/ContentTest.php @@ -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(); diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index bd7be2366..5e56846d2 100644 --- a/core/lib/Thelia/Tests/Action/FolderTest.php +++ b/core/lib/Thelia/Tests/Action/FolderTest.php @@ -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 */ diff --git a/core/lib/Thelia/Tests/Action/I18nTestTrait.php b/core/lib/Thelia/Tests/Action/I18nTestTrait.php new file mode 100644 index 000000000..cf281ca60 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/I18nTestTrait.php @@ -0,0 +1,59 @@ + + */ +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); + } + } + + } + +} \ No newline at end of file