[BUGFIX] selectViewHelper sorting should respect locales
authorStefan Froemken <froemken@gmail.com>
Wed, 12 Dec 2012 11:30:51 +0000 (12:30 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 6 Jan 2013 09:49:46 +0000 (10:49 +0100)
In current Fluid versions the sorting
(sortByOptionLabel="1" is used) of the selectViewHelper
does not respect locale collation set by config.locale_all in TypoScript.

Fixes: #43445
Releases: 4.5, 4.6, 4.7, 6.0, 6.1

Change-Id: Ie6761493c7766c05c21d5b1afc2bfec6dbe00a66
Reviewed-on: https://review.typo3.org/17129
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/SelectViewHelperTest.php

index 496ad57..7dda15d 100644 (file)
@@ -182,7 +182,7 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
                        $options[$key] = $value;
                }
                if ($this->arguments['sortByOptionLabel']) {
-                       asort($options);
+                       asort($options, SORT_LOCALE_STRING);
                }
                return $options;
        }
index de8919a..cf2c764 100644 (file)
@@ -31,6 +31,10 @@ class SelectViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
                $this->viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\SelectViewHelper', array('setErrorClassAttribute', 'registerFieldNameForFormTokenGeneration'));
        }
 
+       public function tearDown() {
+               setlocale(LC_ALL, '');
+       }
+
        /**
         * @test
         */
@@ -121,6 +125,37 @@ class SelectViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
        /**
         * @test
         */
+       public function optionsAreSortedByLabelIfSortByOptionLabelIsSetAndLocaleEqualsUtf8() {
+               $locale = 'de_DE.UTF-8';
+               if (!setlocale(LC_COLLATE, $locale)) {
+                       $this->markTestSkipped('Locale ' . $locale . ' is not available.');
+               }
+
+               setlocale(LC_CTYPE, $locale);
+               setlocale(LC_MONETARY, $locale);
+               setlocale(LC_TIME, $locale);
+               $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
+               $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
+               $this->tagBuilder->expects($this->once())->method('setContent')->with('<option value="value1">Bamberg</option>' . chr(10) . '<option value="value2" selected="selected">Bämm</option>' . chr(10) . '<option value="value3">Bar</option>' . chr(10) . '<option value="value4">Bär</option>' . chr(10) . '<option value="value5">Burg</option>' . chr(10));
+               $this->tagBuilder->expects($this->once())->method('render');
+               $this->arguments['options'] = array(
+                       'value4' => 'Bär',
+                       'value2' => 'Bämm',
+                       'value5' => 'Burg',
+                       'value1' => 'Bamberg',
+                       'value3' => 'Bar'
+               );
+               $this->arguments['value'] = 'value2';
+               $this->arguments['name'] = 'myName';
+               $this->arguments['sortByOptionLabel'] = TRUE;
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initialize();
+               $this->viewHelper->render();
+       }
+
+       /**
+        * @test
+        */
        public function multipleSelectCreatesExpectedOptions() {
                $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
                $this->arguments['options'] = array(