Follow-up to #11431: Unit test for getPage_preProcess hook
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 30 Aug 2009 14:01:30 +0000 (14:01 +0000)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 30 Aug 2009 14:01:30 +0000 (14:01 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5846 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/t3lib_pageselect_testcase.php [new file with mode: 0644]

index 53e24f8..9b8012a 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2009-08-30  Christian Kuhn  <lolli@schwarzbu.ch>
 
+       * Follow-up to #11431: Unit test for getPage_preProcess hook
        * Added feature #11431: Hook to manipulate the page request in method getPage of class t3lib_pageSelect
 
 2009-08-30  Rupert Germann  <rupi@gmx.li>
diff --git a/tests/t3lib/t3lib_pageselect_testcase.php b/tests/t3lib/t3lib_pageselect_testcase.php
new file mode 100644 (file)
index 0000000..95f894c
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Christian Kuhn <lolli@schwarzbu.ch>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+
+/**
+ * Testcase for class t3lib_page
+ *
+ * @author     Christian Kuhn <lolli@schwarzbu.ch>
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+class t3lib_pageselect_testcase extends tx_phpunit_testcase {
+
+       /**
+        * @var t3lib_DB
+        */
+       protected $typo3DbBackup;
+
+       /**
+        * @var t3lib_pageSelect
+        */
+       protected $pageSelectObject;
+
+       /**
+        * Sets up this testcase
+        */
+       public function setUp() {
+               $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
+               $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
+
+               $this->pageSelectObject = new t3lib_pageSelect();
+       }
+
+       /**
+        * Tears down this testcase
+        */
+       public function tearDown() {
+               $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup;
+       }
+
+       /**
+        * Tests whether the getPage Hook is called correctly.
+        *
+        * @test
+        */
+       public function isGetPageHookCalled() {
+                       // Create a hook mock object
+               $className = uniqid('tx_coretest');
+               $getPageHookMock = $this->getMock(
+                       't3lib_pageSelect_getPageHook',
+                       array('getPage_preProcess'),
+                       array(),
+                       $className
+               );
+
+                       // Register hook mock object
+               $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock;
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
+
+                       // Test if hook is called and register a callback method to check given arguments
+               $getPageHookMock->expects($this->once())->method('getPage_preProcess')
+                       ->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback')));
+
+               $this->pageSelectObject->getPage(42, FALSE);
+       }
+
+       /**
+        * Handles the arguments that have been sent to the getPage_preProcess hook
+        */
+       public function isGetPagePreProcessCalledCallback() {
+               list($uid, $disableGroupAccessCheck, $parent) = func_get_args();
+
+               $this->assertEquals(42, $uid);
+               $this->assertFalse($disableGroupAccessCheck);
+               $this->assertTrue($parent instanceof t3lib_pageSelect);
+       }
+}
+
+?>