[FEATURE] Add stdWrap feature: addPageCacheTags
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / ContentObject / ContentObjectRendererTest.php
index 7e31ff5..4769cb3 100644 (file)
@@ -4,7 +4,7 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2009-2011 Oliver Hader <oliver@typo3.org>
+ *  (c) 2009-2013 Oliver Hader <oliver@typo3.org>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -37,7 +37,7 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        protected $cObj = NULL;
 
        /**
-        * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
+        * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
         */
        protected $tsfe = NULL;
 
@@ -51,7 +51,7 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function setUp() {
                $this->template = $this->getMock('TYPO3\\CMS\\Core\\TypoScript\\TemplateService', array('getFileName', 'linkData'));
-               $this->tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
+               $this->tsfe = $this->getAccessibleMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', FALSE);
                $this->tsfe->tmpl = $this->template;
                $this->tsfe->config = array();
                $this->tsfe->page = array();
@@ -1175,9 +1175,9 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @dataProvider stdWrap_strftimeReturnsFormattedStringDataProvider
         */
        public function stdWrap_strftimeReturnsFormattedString($content, $conf) {
-                       // Set exec_time to a hard timestamp (backed up by $this->backupGlobals = TRUE)
+                       // Set exec_time to a hard timestamp
                $GLOBALS['EXEC_TIME'] = 1346500800;
-                       // Save current timezone and set to UTC to make the system unter test behave
+                       // Save current timezone and set to UTC to make the system under test behave
                        // the same in all server timezone settings
                $timezoneBackup = date_default_timezone_get();
                date_default_timezone_set('UTC');
@@ -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,113 @@ 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 '
+                       ),
+               );
+       }
+
+       /**
+        * @param array $expectedTags
+        * @param array $configuration
+        * @test
+        * @dataProvider stdWrap_addPageCacheTagsAddsPageTagsDataProvider
+        */
+       public function stdWrap_addPageCacheTagsAddsPageTags(array $expectedTags, array $configuration) {
+               $this->cObj->stdWrap_addPageCacheTags('', $configuration);
+               $this->assertEquals($expectedTags, $this->tsfe->_get('pageCacheTags'));
+       }
+
+       /**
+        * @return array
+        */
+       public function stdWrap_addPageCacheTagsAddsPageTagsDataProvider() {
+               return array(
+                       'No Tag' => array(
+                               array(),
+                               array('addPageCacheTags' => ''),
+                       ),
+                       'Two expectedTags' => array(
+                               array('tag1', 'tag2'),
+                               array('addPageCacheTags' => 'tag1,tag2'),
+                       ),
+                       'Two expectedTags plus one with stdWrap' => array(
+                               array('tag1', 'tag2', 'tag3'),
+                               array(
+                                       'addPageCacheTags' => 'tag1,tag2',
+                                       'addPageCacheTags.' => array('wrap' => '|,tag3')
+                               ),
+                       ),
+               );
+       }
 }
 
 ?>