Follow-up to #13418: Added testcase for t3lib_div::_getSET
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 26 Mar 2010 18:00:42 +0000 (18:00 +0000)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 26 Mar 2010 18:00:42 +0000 (18:00 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7194 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/t3lib_div_testcase.php

index b59cad9..a44bd83 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
 
 2010-03-26  Christian Kuhn  <lolli@schwarzbu.ch>
 
+       * Follow-up to #13418: Added testcase for t3lib_div::_getSET (Thanks to Susanne Moog and Oliver Klee)
        * Added Feature #13418: Allow t3lib_div::_GETset() to set specified key (Thanks to Felix Oertel)
        * Fixed bug #13595: loginform has <table> stdWrap, but <div>s inside [css styled content] (Thanks to Susanne Moog)
        * Fixed bug #13792: Double semicolon in css styled content (Thanks to Susanne Moog)
index c7d6109..2a1e654 100644 (file)
  */
 class t3lib_div_testcase extends tx_phpunit_testcase {
        /**
+        * backup of the global variables _GET, _POST, _SERVER
+        *
+        * @var array
+        */
+       private $backupGlobalVariables;
+
+       public function setUp() {
+               $this->backupGlobalVariables = array(
+                       '_GET' => $_GET,
+                       '_POST' => $_POST,
+                       '_SERVER' => $_SERVER,
+               );
+       }
+
+       public function tearDown() {
+               foreach ($this->backupGlobalVariables as $key => $data) {
+                       $GLOBALS[$key] = $data;
+                       $$key = $data;
+               }
+       }
+
+
+       /**
         * @test
         */
        public function checkIntExplodeConvertsStringsToInteger() {
@@ -838,7 +861,7 @@ class t3lib_div_testcase extends tx_phpunit_testcase {
         */
        public function readLLfileLocallangXMLOverride() {
                $unique = uniqid('locallangXMLOverrideTest');
-               
+
                $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
                        <T3locallang>
                                <data type="array">
@@ -866,6 +889,155 @@ class t3lib_div_testcase extends tx_phpunit_testcase {
 
                unlink($file);
        }
-}
 
+
+       ///////////////////////////////
+       // Tests concerning _GETset()
+       ///////////////////////////////
+
+       /**
+        * @test
+        */
+       public function getSetCanSetWholeArray() {
+               $_GET = array();
+               $GLOBALS['HTTP_GET_VARS'] = array();
+               t3lib_div::_GETset(array('oneKey' => 'oneValue'));
+
+               $this->assertEquals(
+                       array('oneKey' => 'oneValue'),
+                       $_GET
+               );
+               $this->assertEquals(
+                       array('oneKey' => 'oneValue'),
+                       $GLOBALS['HTTP_GET_VARS']
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getSetForArrayDropsExistingValues() {
+               $_GET = array();
+               $GLOBALS['HTTP_GET_VARS'] = array();
+
+               t3lib_div::_GETset(array('foo' => 'bar'));
+               t3lib_div::_GETset(array('oneKey' => 'oneValue'));
+
+               $this->assertEquals(
+                       array('oneKey' => 'oneValue'),
+                       $_GET
+               );
+               $this->assertEquals(
+                       array('oneKey' => 'oneValue'),
+                       $GLOBALS['HTTP_GET_VARS']
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getSetCanAssignOneValueToOneKey() {
+               $_GET = array();
+               $GLOBALS['HTTP_GET_VARS'] = array();
+
+               t3lib_div::_GETset('oneValue', 'oneKey');
+
+               $this->assertEquals(
+                       'oneValue',
+                       $_GET['oneKey']
+               );
+               $this->assertEquals(
+                       'oneValue',
+                       $GLOBALS['HTTP_GET_VARS']['oneKey']
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getSetForOneValueNotDropsExistingValues() {
+               $_GET = array();
+               $GLOBALS['HTTP_GET_VARS'] = array();
+
+               t3lib_div::_GETset(array('foo' => 'bar'));
+               t3lib_div::_GETset('oneValue', 'oneKey');
+
+               $this->assertEquals(
+                       array('foo' => 'bar', 'oneKey' => 'oneValue'),
+                       $_GET
+               );
+               $this->assertEquals(
+                       array('foo' => 'bar', 'oneKey' => 'oneValue'),
+                       $GLOBALS['HTTP_GET_VARS']
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getSetCanAssignAnArrayToSpecificArrayElement() {
+               $_GET = array();
+               $GLOBALS['HTTP_GET_VARS'] = array();
+
+               t3lib_div::_GETset(array('childKey' => 'oneValue'), 'parentKey');
+
+               $this->assertEquals(
+                       array('parentKey' => array('childKey' => 'oneValue')),
+                       $_GET
+               );
+               $this->assertEquals(
+                       array('parentKey' => array('childKey' => 'oneValue')),
+                       $GLOBALS['HTTP_GET_VARS']
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getSetCanAssignAValueToSpecificArrayChildElement() {
+               $_GET = array();
+               $GLOBALS['HTTP_GET_VARS'] = array();
+
+               t3lib_div::_GETset('oneValue', 'parentKey|childKey');
+
+               $this->assertEquals(
+                       array('parentKey' => array('childKey' => 'oneValue')),
+                       $_GET
+               );
+               $this->assertEquals(
+                       array('parentKey' => array('childKey' => 'oneValue')),
+                       $GLOBALS['HTTP_GET_VARS']
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getSetCanAssignAnArrayToSpecificArrayChildElement() {
+               $_GET = array();
+               $GLOBALS['HTTP_GET_VARS'] = array();
+
+               t3lib_div::_GETset(
+                       array('key1' => 'value1', 'key2' => 'value2'),
+                       'parentKey|childKey'
+               );
+
+               $this->assertEquals(
+                       array(
+                               'parentKey' => array(
+                                       'childKey' => array('key1' => 'value1', 'key2' => 'value2')
+                               )
+                       ),
+                       $_GET
+               );
+               $this->assertEquals(
+                       array(
+                               'parentKey' => array(
+                                       'childKey' => array('key1' => 'value1', 'key2' => 'value2')
+                               )
+                       ),
+                       $GLOBALS['HTTP_GET_VARS']
+               );
+       }
+}
 ?>
\ No newline at end of file