From 5dae84f0fd050e867feb537e1bb34212a3c7f719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Fri, 4 Jul 2014 10:34:00 +0200 Subject: [PATCH 1/4] fixed new issue on rewriting test due to blank titles on some locale --- core/lib/Thelia/Tests/Action/ContentTest.php | 27 +++++++++++++++----- core/lib/Thelia/Tests/Action/FolderTest.php | 26 ++++++++++++++----- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index e5021ea74..4417cd7ea 100644 --- a/core/lib/Thelia/Tests/Action/ContentTest.php +++ b/core/lib/Thelia/Tests/Action/ContentTest.php @@ -288,6 +288,7 @@ class ContentTest extends TestCaseWithURLToolSetup $this->assertNull($testAssociation); } + /** * @return \Thelia\Model\Content */ @@ -320,9 +321,7 @@ class ContentTest extends TestCaseWithURLToolSetup $folder->setVisible(1); $folder->setPosition(1); - $folder - ->setLocale('en_US') - ->setTitle('folder test'); + $this->setI18N($folder, "folder"); $folder->save(); @@ -334,9 +333,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, "content"); $contentFolders = $content->getContentFolders(); $collection = new Collection(); @@ -353,6 +350,24 @@ 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 = array('fr_FR', 'en_US', 'es_ES', 'it_IT'); + + foreach ($localeList as $locale) { + $object->setLocale($locale); + $object->setTitle($locale . ' : ' . $title); + } + + } + /** * @return \Thelia\Model\Folder */ diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index bd7be2366..cc29c3e93 100644 --- a/core/lib/Thelia/Tests/Action/FolderTest.php +++ b/core/lib/Thelia/Tests/Action/FolderTest.php @@ -297,9 +297,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"); $folder->save(); @@ -311,9 +310,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, "sub folder"); $subFolder->save(); } @@ -324,6 +321,23 @@ 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 = array('fr_FR', 'en_US', 'es_ES', 'it_IT'); + + foreach ($localeList as $locale) { + $object->setLocale($locale); + $object->setTitle($locale . ' : ' . $title); + } + + } /** * @return \Thelia\Model\Folder From 71f4380dff819f8c33807c09f717717d114c617b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Fri, 4 Jul 2014 11:27:44 +0200 Subject: [PATCH 2/4] added title for all available langages --- core/lib/Thelia/Tests/Action/ContentTest.php | 6 +++++- core/lib/Thelia/Tests/Action/FolderTest.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index 4417cd7ea..dfbabb21a 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; @@ -359,7 +360,10 @@ class ContentTest extends TestCaseWithURLToolSetup public function setI18N(&$object, $title) { - $localeList = array('fr_FR', 'en_US', 'es_ES', 'it_IT'); + $localeList = LangQuery::create() + ->select("Locale") + ->find() + ->toArray(); foreach ($localeList as $locale) { $object->setLocale($locale); diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index cc29c3e93..3b2401159 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; @@ -330,7 +331,10 @@ class FolderTest extends TestCaseWithURLToolSetup public function setI18N(&$object, $title) { - $localeList = array('fr_FR', 'en_US', 'es_ES', 'it_IT'); + $localeList = LangQuery::create() + ->select("Locale") + ->find() + ->toArray(); foreach ($localeList as $locale) { $object->setLocale($locale); From c8a4cbcb8aae3126ef8faf492f15bac0f61d8365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Fri, 4 Jul 2014 14:57:10 +0200 Subject: [PATCH 3/4] optimization --- core/lib/Thelia/Tests/Action/ContentTest.php | 27 ++------ core/lib/Thelia/Tests/Action/FolderTest.php | 26 +------- .../lib/Thelia/Tests/Action/I18nTestTrait.php | 65 +++++++++++++++++++ 3 files changed, 72 insertions(+), 46 deletions(-) create mode 100644 core/lib/Thelia/Tests/Action/I18nTestTrait.php diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index dfbabb21a..6c0c1275b 100644 --- a/core/lib/Thelia/Tests/Action/ContentTest.php +++ b/core/lib/Thelia/Tests/Action/ContentTest.php @@ -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 */ diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index 3b2401159..5e56846d2 100644 --- a/core/lib/Thelia/Tests/Action/FolderTest.php +++ b/core/lib/Thelia/Tests/Action/FolderTest.php @@ -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 */ diff --git a/core/lib/Thelia/Tests/Action/I18nTestTrait.php b/core/lib/Thelia/Tests/Action/I18nTestTrait.php new file mode 100644 index 000000000..9c470589f --- /dev/null +++ b/core/lib/Thelia/Tests/Action/I18nTestTrait.php @@ -0,0 +1,65 @@ + + */ +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); + } + } + + } + +} \ No newline at end of file From ff8350352fee22d43ddce86293e76957a000fe3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Fri, 4 Jul 2014 15:25:09 +0200 Subject: [PATCH 4/4] small improvement --- core/lib/Thelia/Tests/Action/I18nTestTrait.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/core/lib/Thelia/Tests/Action/I18nTestTrait.php b/core/lib/Thelia/Tests/Action/I18nTestTrait.php index 9c470589f..cf281ca60 100644 --- a/core/lib/Thelia/Tests/Action/I18nTestTrait.php +++ b/core/lib/Thelia/Tests/Action/I18nTestTrait.php @@ -33,7 +33,7 @@ trait I18nTestTrait * @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) + protected function setI18n(&$object, $fields = array("Title"), $localeList = null) { if (null === $localeList) { @@ -49,14 +49,8 @@ trait I18nTestTrait } foreach ($localeList as $locale) { - - $object->setLocale($locale); - foreach ($fields as $name) { - - $func = "set" . ucfirst(strtolower($name)); - - $object->$func($locale . ' : ' . $name); + $object->getTranslation($locale)->setByName($name, $locale . ' : ' . $name); } }