[TASK] Add unit tests for TemplateService->splitConfArray() 58/43358/2
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Tue, 15 Sep 2015 19:55:26 +0000 (21:55 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 16 Sep 2015 09:57:50 +0000 (11:57 +0200)
splitConfArray is a implementation of TypoScript optionSplit function.
This change adds some unit tests for the basic usage outlined
in the documentation.
see https://docs.typo3.org/typo3cms/TyposcriptReference/ObjectsAndProperties/Index.html#objects-optionsplit

Resolves: #69854
Releases: master
Change-Id: I1312039479b8c685af240224906d897d6c1d00d7
Reviewed-on: http://review.typo3.org/43358
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php

index d0178e6..885979e 100644 (file)
@@ -182,4 +182,120 @@ class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertNull($this->templateService->getFileName('something/../else'));
        }
 
+       public function splitConfDataProvider() {
+               return array(
+                       array(
+                               array('splitConfiguration' => 'a'),
+                               3,
+                               array(
+                                       0 => array('splitConfiguration' => 'a'),
+                                       1 => array('splitConfiguration' => 'a'),
+                                       2 => array('splitConfiguration' => 'a')
+                               )
+                       ),
+                       array(
+                               array('splitConfiguration' => 'a || b || c'),
+                               5,
+                               array(
+                                       0 => array('splitConfiguration' => 'a'),
+                                       1 => array('splitConfiguration' => 'b'),
+                                       2 => array('splitConfiguration' => 'c'),
+                                       3 => array('splitConfiguration' => 'c'),
+                                       4 => array('splitConfiguration' => 'c')
+                               )
+                       ),
+                       array(
+                               array('splitConfiguration' => 'a || b |*| c'),
+                               5,
+                               array(
+                                       0 => array('splitConfiguration' => 'a'),
+                                       1 => array('splitConfiguration' => 'b'),
+                                       2 => array('splitConfiguration' => 'c'),
+                                       3 => array('splitConfiguration' => 'c'),
+                                       4 => array('splitConfiguration' => 'c')
+                               )
+                       ),
+                       array(
+                               array('splitConfiguration' => 'a || b |*| c |*| d || e'),
+                               7,
+                               array(
+                                       0 => array('splitConfiguration' => 'a'),
+                                       1 => array('splitConfiguration' => 'b'),
+                                       2 => array('splitConfiguration' => 'c'),
+                                       3 => array('splitConfiguration' => 'c'),
+                                       4 => array('splitConfiguration' => 'c'),
+                                       5 => array('splitConfiguration' => 'd'),
+                                       6 => array('splitConfiguration' => 'e')
+                               )
+                       ),
+                       array(
+                               array('splitConfiguration' => 'a || b |*| c |*| d || e'),
+                               4,
+                               array(
+                                       0 => array('splitConfiguration' => 'a'),
+                                       1 => array('splitConfiguration' => 'b'),
+                                       2 => array('splitConfiguration' => 'd'),
+                                       3 => array('splitConfiguration' => 'e')
+                               )
+                       ),
+                       array(
+                               array('splitConfiguration' => 'a || b |*| c |*| d || e'),
+                               3,
+                               array(
+                                       0 => array('splitConfiguration' => 'a'),
+                                       1 => array('splitConfiguration' => 'd'),
+                                       2 => array('splitConfiguration' => 'e')
+                               )
+                       ),
+                       array(
+                               array('splitConfiguration' => 'a || b |*||*| c || d'),
+                               7,
+                               array(
+                                       0 => array('splitConfiguration' => 'a'),
+                                       1 => array('splitConfiguration' => 'b'),
+                                       2 => array('splitConfiguration' => 'b'),
+                                       3 => array('splitConfiguration' => 'b'),
+                                       4 => array('splitConfiguration' => 'b'),
+                                       5 => array('splitConfiguration' => 'c'),
+                                       6 => array('splitConfiguration' => 'd')
+                               )
+                       ),
+                       array(
+                               array('splitConfiguration' => '|*||*| a || b'),
+                               7,
+                               array(
+                                       0 => array('splitConfiguration' => 'a'),
+                                       1 => array('splitConfiguration' => 'a'),
+                                       2 => array('splitConfiguration' => 'a'),
+                                       3 => array('splitConfiguration' => 'a'),
+                                       4 => array('splitConfiguration' => 'a'),
+                                       5 => array('splitConfiguration' => 'a'),
+                                       6 => array('splitConfiguration' => 'b')
+                               )
+                       ),
+                       array(
+                               array('splitConfiguration' => 'a |*| b || c |*|'),
+                               7,
+                               array(
+                                       0 => array('splitConfiguration' => 'a'),
+                                       1 => array('splitConfiguration' => 'b'),
+                                       2 => array('splitConfiguration' => 'c'),
+                                       3 => array('splitConfiguration' => 'b'),
+                                       4 => array('splitConfiguration' => 'c'),
+                                       5 => array('splitConfiguration' => 'b'),
+                                       6 => array('splitConfiguration' => 'c')
+                               )
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider splitConfDataProvider
+        * @see https://docs.typo3.org/typo3cms/TyposcriptReference/ObjectsAndProperties/Index.html#objects-optionsplit
+        */
+       public function splitConfArraytest($configuration, $splitCount, $expected) {
+               $actual = $this->templateService->splitConfArray($configuration, $splitCount);
+               $this->assertSame($expected, $actual);
+       }
 }