TYPO3 API  SVNRelease
t3lib_tcemainTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 * Copyright notice
00004 *
00005 * (c) 2009-2011 Oliver Klee (typo3-coding@oliverklee.de)
00006 * All rights reserved
00007 *
00008 * This script is part of the TYPO3 project. The TYPO3 project is
00009 * free software; you can redistribute it and/or modify
00010 * it under the terms of the GNU General Public License as published by
00011 * the Free Software Foundation; either version 2 of the License, or
00012 * (at your option) any later version.
00013 *
00014 * The GNU General Public License can be found at
00015 * http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 * This script is distributed in the hope that it will be useful,
00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 * GNU General Public License for more details.
00021 *
00022 * This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 /**
00026  * Testcase for the t3lib_TCEmain class in the TYPO3 core.
00027  *
00028  * @package TYPO3
00029  * @subpackage t3lib
00030  *
00031  * @author Oliver Klee <typo3-coding@oliverklee.de>
00032  */
00033 class t3lib_tcemainTest extends tx_phpunit_testcase {
00034 
00035     /**
00036      * Enable backup of global and system variables
00037      *
00038      * @var boolean
00039      */
00040     protected $backupGlobals = TRUE;
00041 
00042     /**
00043      * Exclude TYPO3_DB from backup/ restore of $GLOBALS
00044      * because resource types cannot be handled during serializing
00045      *
00046      * @var array
00047      */
00048     protected $backupGlobalsBlacklist = array('TYPO3_DB');
00049 
00050     /**
00051      * @var t3lib_TCEmain
00052      */
00053     private $fixture;
00054 
00055     /**
00056      * @var t3lib_beUserAuth a mock logged-in back-end user
00057      */
00058     private $backEndUser;
00059 
00060     public function setUp() {
00061         $this->backEndUser = $this->getMock('t3lib_beUserAuth');
00062 
00063         $this->fixture = new t3lib_TCEmain();
00064         $this->fixture->start(array(), '', $this->backEndUser);
00065     }
00066 
00067     public function tearDown() {
00068         unset(
00069             $this->fixture->BE_USER, $this->fixture, $this->backEndUser
00070         );
00071     }
00072 
00073 
00074     //////////////////////////////////////
00075     // Tests for the basic functionality
00076     //////////////////////////////////////
00077 
00078     /**
00079      * @test
00080      */
00081     public function fixtureCanBeCreated() {
00082         $this->assertTrue(
00083             $this->fixture instanceof t3lib_TCEmain
00084         );
00085     }
00086 
00087 
00088     //////////////////////////////////////////
00089     // Test concerning checkModifyAccessList
00090     //////////////////////////////////////////
00091 
00092     /**
00093      * @test
00094      */
00095     public function adminIsAllowedToModifyNonAdminTable() {
00096         $this->fixture->admin = true;
00097 
00098         $this->assertTrue(
00099             $this->fixture->checkModifyAccessList('tt_content')
00100         );
00101     }
00102 
00103     /**
00104      * @test
00105      */
00106     public function nonAdminIsNorAllowedToModifyNonAdminTable() {
00107         $this->fixture->admin = false;
00108 
00109         $this->assertFalse(
00110             $this->fixture->checkModifyAccessList('tt_content')
00111         );
00112     }
00113 
00114     /**
00115      * @test
00116      */
00117     public function nonAdminWithTableModifyAccessIsAllowedToModifyNonAdminTable() {
00118         $this->fixture->admin = false;
00119         $this->backEndUser->groupData['tables_modify'] = 'tt_content';
00120 
00121         $this->assertTrue(
00122             $this->fixture->checkModifyAccessList('tt_content')
00123         );
00124     }
00125 
00126     /**
00127      * @test
00128      */
00129     public function adminIsAllowedToModifyAdminTable() {
00130         $this->fixture->admin = true;
00131 
00132         $this->assertTrue(
00133             $this->fixture->checkModifyAccessList('be_users')
00134         );
00135     }
00136 
00137     /**
00138      * @test
00139      */
00140     public function nonAdminIsNotAllowedToModifyAdminTable() {
00141         $this->fixture->admin = false;
00142 
00143         $this->assertFalse(
00144             $this->fixture->checkModifyAccessList('be_users')
00145         );
00146     }
00147 
00148     /**
00149      * @test
00150      */
00151     public function nonAdminWithTableModifyAccessIsNotAllowedToModifyAdminTable() {
00152         $this->fixture->admin = false;
00153         $this->backEndUser->groupData['tables_modify'] = 'be_users';
00154 
00155         $this->assertFalse(
00156             $this->fixture->checkModifyAccessList('be_users')
00157         );
00158     }
00159 
00160     /**
00161      * @test
00162      */
00163     public function evalCheckValueDouble2() {
00164         $testData = array (
00165                         '-0,5' => '-0.50',
00166                         '1000' => '1000.00',
00167                         '1000,10' => '1000.10',
00168                         '1000,0' => '1000.00',
00169                         '600.000.000,00' => '600000000.00',
00170                         '60aaa00' => '6000.00',
00171                         );
00172         foreach ($testData as $value => $expectedReturnValue){
00173             $returnValue = $this->fixture->checkValue_input_Eval($value, array('double2'), '');
00174             $this->assertSame(
00175             $returnValue['value'],
00176             $expectedReturnValue
00177             );
00178         }
00179     }
00180 
00181 
00182     ///////////////////////////////////////////
00183     // Tests concerning checkModifyAccessList
00184     ///////////////////////////////////////////
00185 
00186     /**
00187      * Tests whether a wrong interface on the 'checkModifyAccessList' hook throws an exception.
00188      * @test
00189      * @expectedException UnexpectedValueException
00190      * @see t3lib_TCEmain::checkModifyAccessList()
00191      */
00192     public function doesCheckModifyAccessListThrowExceptionOnWrongHookInterface() {
00193         $hookClass = uniqid('tx_coretest');
00194         eval('class ' . $hookClass . ' {}');
00195 
00196         $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
00197 
00198         $this->fixture->checkModifyAccessList('tt_content');
00199     }
00200 
00201     /**
00202      * Tests whether the 'checkModifyAccessList' hook is called correctly.
00203      * @test
00204      * @see t3lib_TCEmain::checkModifyAccessList()
00205      */
00206     public function doesCheckModifyAccessListHookGetsCalled() {
00207         $hookClass = uniqid('tx_coretest');
00208         $hookMock = $this->getMock(
00209             't3lib_TCEmain_checkModifyAccessListHook',
00210             array('checkModifyAccessList'),
00211             array(),
00212             $hookClass
00213         );
00214         $hookMock->expects($this->once())->method('checkModifyAccessList');
00215 
00216         $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
00217         $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock;
00218 
00219         $this->fixture->checkModifyAccessList('tt_content');
00220     }
00221 
00222     /**
00223      * Tests whether the 'checkModifyAccessList' hook modifies the $accessAllowed variable.
00224      * @test
00225      * @see t3lib_TCEmain::checkModifyAccessList()
00226      */
00227     public function doesCheckModifyAccessListHookModifyAccessAllowed() {
00228         $hookClass = uniqid('tx_coretest');
00229         eval('
00230             class ' . $hookClass . ' implements t3lib_TCEmain_checkModifyAccessListHook {
00231                 public function checkModifyAccessList(&$accessAllowed, $table, t3lib_TCEmain $parent) { $accessAllowed = true; }
00232             }
00233         ');
00234 
00235         $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
00236 
00237         $this->assertTrue($this->fixture->checkModifyAccessList('tt_content'));
00238     }
00239 }
00240 ?>