[FEATURE] Add splitChar to noTrimWrap 28/9428/8
authorJigal van Hemert <jigal@xs4all.nl>
Tue, 6 Mar 2012 21:05:05 +0000 (22:05 +0100)
committerBenjamin Mack <benni@typo3.org>
Sun, 24 Mar 2013 10:13:59 +0000 (11:13 +0100)
noTrimWrap constructions with empty parts share syntax with optionSplit.
If this is used in HMENU optionSplit takes precedence. A possibility
to set the splitChar solves the ambiguity.

Change-Id: Ia35603dfca64c5d1c9a0ebdacf316ee373e48560
Resolves: #20793
Releases: 6.1
Reviewed-on: https://review.typo3.org/9428
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Eric Chavaillaz
Tested-by: Eric Chavaillaz
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 48b4fba..39e3dc3 100644 (file)
@@ -3083,7 +3083,17 @@ class ContentObjectRenderer {
         * @return string The processed input value
         */
        public function stdWrap_noTrimWrap($content = '', $conf = array()) {
-               $content = $this->noTrimWrap($content, $conf['noTrimWrap']);
+               $splitChar = isset($conf['noTrimWrap.']['splitChar.'])
+                       ? $this->stdWrap($conf['noTrimWrap.']['splitChar'], $conf['noTrimWrap.']['splitChar.'])
+                       : $conf['noTrimWrap.']['splitChar'];
+               if ($splitChar === NULL || $splitChar === '') {
+                       $splitChar = '|';
+               }
+               $content = $this->noTrimWrap(
+                       $content,
+                       $conf['noTrimWrap'],
+                       $splitChar
+               );
                return $content;
        }
 
@@ -6341,13 +6351,14 @@ class ContentObjectRenderer {
         *
         * @param string $content The content to wrap, eg. "HELLO WORLD
         * @param string $wrap The wrap value, eg. " | <strong> | </strong>
+        * @param string $char The char used to split the wrapping value, default is "|"
         * @return string Wrapped input string, eg. " <strong> HELLO WORD </strong>
         * @see wrap()
         * @todo Define visibility
         */
-       public function noTrimWrap($content, $wrap) {
+       public function noTrimWrap($content, $wrap, $char = '|') {
                if ($wrap) {
-                       $wrapArr = explode('|', $wrap);
+                       $wrapArr = explode($char, $wrap);
                        return $wrapArr[1] . $content . $wrapArr[2];
                } else {
                        return $content;
@@ -7794,4 +7805,4 @@ class ContentObjectRenderer {
 
 }
 
-?>
+?>
\ No newline at end of file
index d298d59..f1ed4d8 100644 (file)
@@ -1203,6 +1203,8 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        /**
+        * Data provider for stdWrap_ifNullDeterminesNullValues test
+        *
         * @return array
         */
        public function stdWrap_ifNullDeterminesNullValuesDataProvider() {
@@ -1223,6 +1225,79 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        ),
                );
        }
+
+       /**
+        * @param $content
+        * @param array $configuration
+        * @param $expected
+        * @dataProvider stdWrap_noTrimWrapAcceptsSplitCharDataProvider
+        * @test
+        */
+       public function stdWrap_noTrimWrapAcceptsSplitChar($content, array $configuration, $expected) {
+               $result = $this->cObj->stdWrap_noTrimWrap($content, $configuration);
+               $this->assertEquals($expected, $result);
+       }
+
+       /**
+        * Data provider for stdWrap_noTrimWrapAcceptsSplitChar test
+        *
+        * @return array
+        */
+       public function stdWrap_noTrimWrapAcceptsSplitCharDataProvider() {
+               return array(
+                       'No char given' => array(
+                               'middle',
+                               array(
+                                       'noTrimWrap' => '| left | right |',
+                               ),
+                               ' left middle right '
+                       ),
+                       'Zero char given' => array(
+                               'middle',
+                               array(
+                                       'noTrimWrap' => '0 left 0 right 0',
+                                       'noTrimWrap.' => array('splitChar' => '0'),
+
+                               ),
+                               ' left middle right '
+                       ),
+                       'Default char given' => array(
+                               'middle',
+                               array(
+                                       'noTrimWrap' => '| left | right |',
+                                       'noTrimWrap.' => array('splitChar' => '|'),
+                               ),
+                               ' left middle right '
+                       ),
+                       'Split char is a' => array(
+                               'middle',
+                               array(
+                                       'noTrimWrap' => 'a left a right a',
+                                       'noTrimWrap.' => array('splitChar' => 'a'),
+                               ),
+                               ' left middle right '
+                       ),
+                       'Split char is multi-char (ab)' => array(
+                               'middle',
+                               array(
+                                       'noTrimWrap' => 'ab left ab right ab',
+                                       'noTrimWrap.' => array('splitChar' => 'ab'),
+                               ),
+                               ' left middle right '
+                       ),
+                       'Split char accepts stdWrap' => array(
+                               'middle',
+                               array(
+                                       'noTrimWrap' => 'abc left abc right abc',
+                                       'noTrimWrap.' => array(
+                                               'splitChar' => 'b',
+                                               'splitChar.' => array('wrap' => 'a|c'),
+                                       ),
+                               ),
+                               ' left middle right '
+                       ),
+               );
+       }
 }
 
 ?>